Nginx series (three.nginx is registered as a Linux system service)

WBOY
Release: 2016-08-08 09:24:56
Original
1294 people have browsed it

一、创建服务脚本

<code>vim /etc/init<span>.d</span>/nginx</code>
Copy after login

脚本内容如下

<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>
Copy after login

二、添加服务

<code><span>chkconfig</span><span>-</span><span>-</span><span>add</span><span>nginx</span></code>
Copy after login

三、测试

<code>service nginx <span><span>start</span></span></code>
Copy after login
<code>service nginx <span>stop</span></code>
Copy after login
<code>service nginx restart</code>
Copy after login
<code>service nginx reload</code>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template