Nginx系列(三.nginx註冊為linux系統服務)

WBOY
發布: 2016-08-08 09:24:56
原創
1293 人瀏覽過

一、创建服务脚本

<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
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板