Centos7下配置Nginx启动服务脚本
1:Nginx配置文件,Nginx路径根据自己安装的位置而修改 vim /etc/init.d/Nginx@H_502_8@
#! /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:设置执行权限@H_502_8@
chmod a+x /etc/init.d/Nginx
chkconfig --add Nginx
4:设置开机启动@H_502_8@
chkconfig Nginx on
5:重启, 查看Nginx服务是否自动启动@H_502_8@
shutdown -h 0 -r
ps -ef | grep Nginx
6:对Nginx服务执行停止/启动/重新读取配置文件操作@H_502_8@
启动@H_502_8@
systemctl start Nginx.service
重载@H_502_8@
systemctl reload Nginx.service
停止@H_502_8@
systemctl top Nginx.service
重启@H_502_8@
systemctl restart Nginx.service
查看状态@H_502_8@
systemctl status Nginx.service
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。