image.png

    1. #!/bin/bash
    2. #nginx service manage script
    3. #variables
    4. nginx_install_doc=/usr/local/nginx
    5. proc=nginx
    6. nginxd=$nginx_install_doc/sbin/nginx
    7. pid_file=$nginx_install_doc/logs/nginx.pid
    8. # Source function library.
    9. if [ -f /etc/init.d/functions ];then
    10. . /etc/init.d/functions
    11. else
    12. echo "not found file /etc/init.d/funtions"
    13. exit
    14. fi
    15. if [ -f $pid_file ];then
    16. nginx_process_id=`cat $pid_file`
    17. nginx_process_num=`ps aux |grep $nginx_process_id|grep -v "grep"|wc -l`
    18. fi

    image.png

    1. #function
    2. start () {
    3. if [ -f $pid_file ] && [ $nginx_process_num -ge 1 ];then
    4. echo "nginx running......"
    5. else
    6. if [ -f $pid_file ] && [ $nginx_process_num -lt 1 ];then
    7. rm -f $pid_file
    8. #echo "nginx start `daemon $nginxd`"
    9. action "nginx start" $nginxd
    10. fi
    11. #echo "nginx start `daemon $nginxd`"
    12. action "nginx start" $nginxd
    13. fi
    14. }

    image.png

    1. stop () {
    2. if [ -f $pid_file ] && [ $nginx_process_num -ge 1 ];then
    3. action "nginx stop" killall -s QUIT $proc
    4. rm -f $pid_file
    5. else
    6. action "nginx stop" killall -s QUIT $proc 2>/dev/null
    7. fi
    8. }

    image.png

    1. restart() {
    2. stop
    3. sleep 1
    4. start
    5. }

    image.png

    1. reload () {
    2. if [ -f $pid_file ] && [ $nginx_process_num -ge 1 ];then
    3. action "nginx reload" killall -s HUP $proc
    4. else
    5. action "nginx reload" killall -s HUP $proc 2>/dev/null
    6. fi
    7. }

    image.png

    1. status () {
    2. if [ -f $pid_file ] && [ $nginx_process_num -ge 1 ];then
    3. echo "nginx running......"
    4. else
    5. echo "nginx stop"
    6. fi
    7. }

    image.png

    1. #callable
    2. case $1 in
    3. start) start
    4. ;;
    5. stop) stop
    6. ;;
    7. restart) restart
    8. ;;
    9. reload) reload
    10. ;;
    11. status) status
    12. ;;
    13. *) echo "USAGE: $0 start|stop|restart|reload|status "
    14. ;;
    15. esac