标准 init.d 模版

最后更新于:2022-04-02 03:49:33

[TOC] ## 模版 > [参考](https://gist.github.com/vittee/7262943)
/etc/init.d/php-fpm ``` #!/bin/bash # # # chkconfig: - 85 15 # description: your description # # processname: php-fpm . /etc/rc.d/init.d/functions if [ -f /etc/sysconfig/php-fpm ]; then . /etc/sysconfig/php-fpm fi # 程序自带的守护进程,没有可以不写 BINCTL="" BIN=/home/im_user/im_server/im_webserver/php/sbin/php-fpm PID=$BIN/logs/httpd.pid OPTIONS="" PROG=$(basename ${BIN}) # 存放结果的变量 RETVAL=0 USER="im_user" start() { echo -n $"Starting $PROG: " daemon --user="${USER}" $BIN $OPTIONS RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/${PROG} return $RETVAL } stop() { echo -n $"Stopping $PROG: " killproc $BIN RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/${PROG} $PID } reload() { echo -n $"Reloading $PROG: " killproc $BIN -HUP RETVAL=$? echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status $BIN RETVAL=$? ;; restart) stop start ;; condrestart) if [ -f $PID ] ; then stop start fi ;; reload) reload ;; ## 扩展,可能有些服务自带守护进程或其他参数 graceful|help|configtest|fullstatus) $BINCTL $@ RETVAL=$? ;; *) echo $"Usage: $PROG {start|stop|restart|condrestart|reload|status" echo $"|fullstatus|graceful|help|configtest}" exit 1 esac exit $RETVAL ```

';