#! /bin/sh
# Default-Start:
2
3
4
5
# Default-Stop:
0
1
6
# Short-Description: starts the nginx web server
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC=
"nginx daemon"
NAME=nginx
<span style=
"color: #ff0000;"
><strong>DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid</strong></span>
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x
"$DAEMON"
] || exit
0
do_start() {
$DAEMON -c $CONFIGFILE || echo -n
"nginx already running"
}
do_stop() {
kill -INT `cat $PIDFILE` || echo -n
"nginx not running"
}
do_reload() {
kill -HUP `cat $PIDFILE` || 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
|
將上述腳本命名為nginx,保存到/etc/init.d目錄下。嘗試/etc/init.d/nginx start 命令,會報“權限不足”的錯誤,執行chmod +x /etc/init.d/nginx 給其賦執行權限。
可以用一下方式來執行此腳本:
/etc/init.d/nginx start
/etc/init.d/nginx sttop
/etc/init.d/nginx reload
/etc/init.d/nginx restart
如果想讓此腳本開機自啟動 還需在腳本頭部家 chkconfig xx xx等注釋(具體需要參考chkconfig命令用法),讓它支持chckconfig 然后執行/sbin/chkconfig nginx on 命令。同時,可以sudo /sbin/chkconfig --list nginx 來查看效果。