How to implement restart script by Nginx
This article mainly shows you "how to implement the restart script in Nginx", which is easy to understand and well-organized. I hope it can help you solve your doubts. Let the editor lead you to study and learn the article "how to implement the restart script in Nginx".
Vi / etc/init.d/nginx
Then enter the following, and you will be able to use the
Service nginx start
Service nginx stop
Service nginx restart
Service nginx reload
The explanation here needs to be explained.
# chkconfig:
# description:
These two comments in the script are required, indicating that they are in a format supported by chkconfig. Otherwise, there will be a prompt similar to the following:
Service nginx does not support chkconfig
Remember to give permission to the script after you add it.
Chmod 755 nginx
Chmod + x nginx
[@ more@]
#! / bin/sh
#
# nginx-this script starts and stops the nginx daemin
#
# chkconfig:-85 15
# description: Nginx is an HTTP (S) server, HTTP (S) reverse
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: / usr/local/nginx/conf/nginx.conf
# pidfile: / usr/local/nginx/logs/nginx.pid
# Source function library.
. / etc/rc.d/init.d/functions
# Source networking configuration.
. / etc/sysconfig/network
# Check that networking is up.
["$NETWORKING" = "no"] & & exit 0
Nginx= "/ usr/local/nginx/sbin/nginx"
Prog=$ (basename $nginx)
NGINX_CONF_FILE= "/ usr/local/nginx/conf/nginx.conf"
Lockfile=/var/lock/subsys/nginx
Start () {
[- x $nginx] | | exit 5
[- f $NGINX_CONF_FILE] | | exit 6
Echo-n $"Starting $prog:"
Daemon $nginx-c $NGINX_CONF_FILE
Retval=$?
Echo
[$retval-eq 0] & & touch $lockfile
Return $retval
}
Stop () {
Echo-n $"Stopping $prog:"
Killproc $prog-QUIT
Retval=$?
Echo
[$retval-eq 0] & & rm-f $lockfile
Return $retval
}
Restart () {
Configtest | | return $?
Stop
Start
}
Reload () {
Configtest | | return $?
Echo-n $"Reloading $prog:"
Killproc $nginx-HUP
RETVAL=$?
Echo
}
Force_reload () {
Restart
}
Configtest () {
$nginx-t-c $NGINX_CONF_FILE
}
Rh_status () {
Status $prog
}
Rh_status_q () {
Rh_status > / dev/null 2 > & 1
}
Case "$1" in
Start)
Rh_status_q & & exit 0
, 1
Stop)
Rh_status_q | | exit 0
, 1
Restart | configtest)
, 1
Reload)
Rh_status_q | | exit 7
, 1
Force-reload)
Force_reload
Status)
Rh_status
Condrestart | try-restart)
Rh_status_q | | exit 0
*)
Echo $"Usage: $0 {start | stop | status | restart | condrestart | try-restart | reload | force-reload | configtest}"
Exit 2
Esac
The above is all the contents of the article "how to implement the restart script in Nginx". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!