Shell script applies "four" Nginx service start-stop reload script
Nginx service startup stop reload script known Nginx management commands are: start: / application/nginx/sbin/nginx stop: / application/nginx/sbin/nginx-s stop reload: / application/nginx/sbin/nginx-s reload Please use case script to simulate Nginx startup shutdown / etc/init.d/nginx {start | stop | restart | reload} and can be managed through chkonfig
Script:
#
# nginx startup script
# 2018-11-29
#
#! / bin/bash
# calling system functions and custom variables
[- f / etc/init.d/functions] & &. / etc/init.d/functions
Pidfile=/application/nginx/logs/nginx.pid
# shared functions
Publics () {
RETVAL=$?
If [$RETVAL-eq 0]; then
Action "Nginx is $1" / bin/true
Else
Actio "Nginx is $1" / bin/false
Fi
}
# launch function start
Start () {
If [- f $Pidfile]; then
Echo "Nginx is running"
Else
/ application/nginx/sbin/nginx
Publics Started
Fi
Return $RETVAL
}
# turn off function stop
Stop () {
If [!-f $Pidfile]; then
Echo "Nginx is not runing"
Else
/ application/nginx/sbin/nginx-s stop
Publics Stopped
Fi
Return $RETVAL
}
# reload the function reload
Reload () {
If [!-f $Pidfile]; then
Echo "Can't open $Pidfile, no such file directory"
Else
/ application/nginx/sbin/nginx-s reload
Publics Reload
Fi
Return $RETVAL
}
# case statement using selection
Case "$1" in
Start)
Start
RETVAL=$?
Stop)
Stop
RETVAL=$?
Reload)
Reload
RETVAL=$?
Restart)
Stop
Sleep 2
Start
RETVAL=$?
*)
Echo "USAGE:$0 {satrt | stop | restart | reload}"
Exit 1
Esac