This is a script file that controls Nginx services, including the control of Nginx startup, restart, stop, smooth restart, and the amount of configuration file checks.
[email protected] ~]# cat nginx.sh
#!/bin/env Bash
# Description:nginx Server # # #必须加描述
# Nginx-this script is used to control Nginx service
# processname Nginx
# Chkconfig:-85 15
# Edit by Sun
# date 2014-07-03
# email address [email protected]
nginx= "/usr/local/nginx/sbin/nginx"
Prog= "Nginx"
Conf_file= "/usr/local/nginx/conf/nginx.conf"
Start () {
If [' Pgrep $prog | wc-l '-eq 0];then
If [-X $nginx] && [-F $conf _file];then
$nginx-C $conf _file
Ret=$?
If [$ret-eq 0];then
echo "$prog start successed"
Else
echo "$prog start Failed"
Fi
Else
echo "$prog config file not exist"
Fi
Else
echo "$prog is already started ... "
Fi
}
Stop () {
If [' Pgrep $prog | wc-l '-ne 0];then
Killall-9 $prog
Ret=$?
If [$ret-eq 0];then
echo "$prog Stop successed"
Else
echo "$prog stop failed"
Fi
Else
echo "$prog is already stopped ..."
Fi
}
Restart () {
Stop
Sleep 2
Start
}
Reload () {
If [' Pgrep $prog | wc-l '-ne 0];then
Pid= ' Ps-ef | grep $prog | grep Master | awk ' {print $} '
If [-X $nginx] && [-F $conf _file];then
Kill-hup $pid
Ret=$?
If [$ret-eq 0];then
echo "$prog Reload successed"
Else
echo "$prog Reload Failed"
Fi
Else
echo "$prog config file is not exist"
Fi
Else
echo "$prog is stopped, please start $prog first ..."
Fi
}
Check () {
If [-X $nginx] && [-F $conf _file];then
$nginx-T-C $conf _file
Ret=$?
If [$ret-eq 0];then
echo "$prog Check successed"
Else
echo "$prog check Failed"
Fi
Fi
}
Case $ in
Start
Start
;;
Stop
Stop
;;
Restart
Restart
;;
Reload
Reload
;;
Check
Check
;;
*)
echo "Usage: $ {Start|stop|restart|reload|check}"
Esac
Run bash nginx.sh start, and so on.
This article from "Personal Feelings" blog, declined reprint!