Idea: After Nginx starts, there will be a nginx.pid file in the specified location, by judging whether the file exists. Determine if Nginx has been started.
#!/bin/bash
#this is my first try to test write a shell to control nginx Daemon
#History 2015-08-04 Masterliu
Path=/usr/bin/:/usr/local/bin:/bin:/usr/sbin:/usr/local/sbin:/sbin:~/bin
Export PATH
#this file could is configured in nginx.conf
Pidfile=/usr/local/nginx/logs/nginx.pid
Nginxd=/usr/local/nginx/sbin/nginx
function Start () {
If [-e $PIDfile];then
Echo-e "Nginx has already Started\t\t[ok]" && exit 0
Fi
$Nginxd &>/dev/null
If [$? = 0];then
Echo-e "Nginx has Started\t\t[ok]"
Else
Echo-e "Nginx start failed\t\t[failed]"
Fi
}
function Stop () {
if [!-e $PIDfile];then
Echo-e "Nginx has already Stopped\t\t[ok]" && exit 0
Fi
#killall Nginx
$Nginxd-S Stop &>/dev/null
Sleep 2
if [!-e $PIDfile];then
Echo-e "Nginx has Stopped\t\t[ok]";
Fi
}
function Reload () {
if [!-e $PIDfile];then
Echo-e "Nginx hasn ' t Start\t\t[ok]" && exit 0
Fi
$Nginxd-S reload && echo-e "Nginx has Reload\t\t[ok]" && exit 0
}
function status () {
if [!-e $PIDfile];then
Echo-e "Nginx hasn ' t Run\t\t[ok]"
Else
Echo-e "Nginx is Running\t\t[ok]"
Fi
}
Case "$" in
Start
Start
;;
Stop
Stop
;;
Restart
Stop
Start
;;
Status
Status
;;
Reload
Reload
;;
*)
Echo-e "\ t start|stop|restart|status|reload\t"
;;
Esac
The
has written an nginx startup script, Shell