CentOS6.3添加nginx系统服务的实例详解
CentOS6.3添加nginx系统服务的实例详解
前言:
今天虚拟机上配了下服务器整理了个这个nginx服务
要注意-短横杠这个符号看看复制进去后有没有乱码,我之前就遇到这个问题,郁闷了好久才发现
提示:顶部的注释不要去除否则无法注册为系统服务,
关于:chkconfig:23456537
网上搜索总结了下意思是:
- 2345为启动该服务的系统环境
- 65 为加载的优先级别
- 37 为关闭的优先级别
65,37这两个位置的数值不能相同,也不能和其它服务的数值冲突,这个我也没遇到过此类问题,如果有发现问题请对应自己的配置修改下好了
新建文件:
#vi/etc/init.d/nginx
输入内容:
#!/bin/sh
#CommentstosupportchkconfigonRedHatLinux
#chkconfig:23456537
#description:Anginxdaemon.
set-e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginxdaemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
SCRIPTNAME=/etc/init.d/$NAME
#Ifthedaemonfileisnotfound,terminatethescript.
test-x$DAEMON||exit0
d_test(){
$DAEMON-t
}
d_start(){
$DAEMON||echo-n"alreadyrunning"
}
d_stop(){
$DAEMON-squit||echo-n"notrunning"
}
d_reload(){
$DAEMON-sreload||echo-n"couldnotreload"
}
case"$1"in
test)
d_test
echo"."
;;
start)
echo-n"Starting$DESC:$NAME"
d_start
echo"."
;;
stop)
echo-n"Stopping$DESC:$NAME"
d_stop
echo"."
;;
reload)
echo-n"Reloading$DESCconfiguration..."
d_reload
echo"reloaded."
;;
restart)
echo-n"Restarting$DESC:$NAME"
d_stop
#Sleepfortwosecondsbeforestartingagain,thisshouldgivethe
#Nginxdaemonsometimetoperformagracefulstop.
sleep2
d_start
echo"."
;;
*)
echo"Usage:$SCRIPTNAME{test|start|stop|restart|reload}">&2
exit3
;;
esac
exit$?
注册nginx服务:
chmod+x/etc/init.d/nginx chkconfig--addnginx chkconfig--level2345nginxon chkconfig--listnginx
相关nginx命令:
检测nginx配置
#servicenginxtest
启动
#servicenginxstart
关闭
#servicenginxstop
重启
#servicenginxrestart
重载配置
#servicenginxreload
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!