Niginx 做成脚本服务并开机启动
1、创建配置
vi /etc/init.d/nginx
2、插入
#! /bin/bash
# chkconfig: - 85 15
PATH=/usr/local/nginx
DESC="nginx daemon"
NAME=nginx
DAEMON=$PATH/sbin/$NAME
CONFIGFILE=$PATH/conf/$NAME.conf
PIDFILE=$PATH/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -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
3、设置执行权限
chmod a+x /etc/init.d/nginx
4、注册成服务
chkconfig --add nginx
5、设置开机启动
chkconfig nginx on
6、以后对nginx服务执行停止/启动/重新读取配置文件操作
1、启动nginx服务
service nginx start
2、停止nginx服务
service nginx stop
3、重启nginx服务
service nginx restart
4、重新读取nginx配置(这个最常用,不用停止nginx服务就能使修改的配置生效)
service nginx reload