实战-nginx服务启动脚本
nginx服务启动脚本
此nginx脚本中使用了函数功能,让脚本具有更强的可读性
[root@xuegod63 ~]# vim /etc/init.d/nginx
#!/bin/bash #chkconfig: 2345 80 90 #description:nginx run # nginx启动脚本 # @authorDevil # @version0.0.1 # @date2018-05-29 PATH=/data/soft/nginx DESC="nginx daemon" NAME=nginx DAEMON=$PATH/sbin/$NAME #/data/soft/nginx/sbin/nginx CONFIGFILE=$PATH/$NAME.conf PIDFILE=$PATH/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME [ -x "$DAEMON" ] || exit 0 do_start() { $DAEMON -c $CONFIGFILE || echo -n "nginx already running" } do_stop() { $DAEMON -s stop || echo -n "nginx not running" } do_reload() { $DAEMON -s reload || echo -n "nginx can't reload" } case "$1" in start) echo -n "Starting $DESC: $NAME" do_start echo "." ;; stop) echo -n "Stopping $DESC: $NAME" do_stop echo "." ;; reload|graceful) echo -n "Reloading $DESC configuration..." do_reload echo "." ;; restart) echo -n "Restarting $DESC: $NAME" do_stop do_start echo "." ;; *) echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2 exit 3 ;; esac exit 0