Nginx系列(三.nginx注册为linux系统服务)

WBOY
发布: 2016-08-08 09:24:56
原创
1294 人浏览过

一、创建服务脚本

<code>vim /etc/init<span>.d</span>/nginx</code>
登录后复制

脚本内容如下

<code><span>#! /bin/sh</span><span># chkconfig: - 85 15</span>PATH=/web/server/nginx/sbin

DESC=<span>"nginx daemon"</span>
NAME=nginx
DAEMON=/web/server/nginx/sbin/<span>$NAME</span>
CONFIGFILE=/web/server/nginx/conf/<span>$NAME</span>.conf
PIDFILE=/web/server/nginx/logs/<span>$NAME</span>.pid
SCRIPTNAME=/etc/init.d/<span>$NAME</span><span>set</span><span>-e</span>
[ -x <span>"<span>$DAEMON</span>"</span> ] || <span>exit</span><span>0</span><span><span>do_start</span></span>() {
<span>$DAEMON</span> -c <span>$CONFIGFILE</span> || <span>echo</span> -n <span>"nginx already running"</span>
}

<span><span>do_stop</span></span>() {
<span>$DAEMON</span><span>-s</span> stop || <span>echo</span> -n <span>"nginx not running"</span>
}

<span><span>do_reload</span></span>() {
<span>$DAEMON</span><span>-s</span> reload || <span>echo</span> -n <span>"nginx can't reload"</span>
}

<span>case</span><span>"<span>$1</span>"</span><span>in</span>
start)
<span>echo</span> -n <span>"Starting <span>$DESC</span>: <span>$NAME</span>"</span><span>do</span>_start
<span>echo</span><span>"."</span>
;;
stop)
<span>echo</span> -n <span>"Stopping <span>$DESC</span>: <span>$NAME</span>"</span><span>do</span>_stop
<span>echo</span><span>"."</span>
;;
reload|graceful)
<span>echo</span> -n <span>"Reloading <span>$DESC</span> configuration..."</span><span>do</span>_reload
<span>echo</span><span>"."</span>
;;
restart)
<span>echo</span> -n <span>"Restarting <span>$DESC</span>: <span>$NAME</span>"</span><span>do</span>_stop
<span>do</span>_start
<span>echo</span><span>"."</span>
;;
*)
<span>echo</span><span>"Usage: <span>$SCRIPTNAME</span> {start|stop|reload|restart}"</span> >&<span>2</span><span>exit</span><span>3</span>
;;
<span>esac</span><span>exit</span><span>0</span></code>
登录后复制

二、添加服务

<code><span>chkconfig</span><span>-</span><span>-</span><span>add</span><span>nginx</span></code>
登录后复制

三、测试

<code>service nginx <span><span>start</span></span></code>
登录后复制
<code>service nginx <span>stop</span></code>
登录后复制
<code>service nginx restart</code>
登录后复制
<code>service nginx reload</code>
登录后复制

以上就介绍了Nginx系列(三.nginx注册为linux系统服务),包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板