龚哥哥 爱生活、做自己!
Centos7下配置nginx启动服务脚本
发表于 2017-5-29 | 服务器

1:nginx配置文件,nginx路径根据自己安装的位置而修改  vim /etc/init.d/nginx

#! /bin/bash
#chkconfig: 2345 80 90
#description:nginx run

# nginx启动脚本
# @author	Devil
# @version	0.0.1
# @date		2017-05-29

PATH=/data/soft/nginx
DESC="nginx daemon"
NAME=nginx
DAEMON=$PATH/$NAME
CONFIGFILE=$PATH/$NAME.conf
PIDFILE=$PATH/$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

2:设置执行权限

chmod a+x /etc/init.d/nginx

3:注册成服务

chkconfig --add nginx

4:设置开机启动

chkconfig nginx on

5:重启, 查看nginx服务是否自动启动

shutdown -h 0 -r

ps -ef | grep nginx

6:对nginx服务执行停止/启动/重新读取配置文件操作

启动
systemctl start nginx.service

重载
systemctl reload nginx.service

停止
systemctl top nginx.service

重启
systemctl restart nginx.service

发表评论:

TOP