1 #!/bin/bash 2 # chkconfig: 2345 40 98 3 # description: Start/Stop Nginx server 4 5 path=/application/nginx/sbin 6 pid=/application/nginx/logs/nginx.pid 7 RETVAL=0 8 9 . /etc/init.d/functions 10 11 start(){ 12 if [ ! -f $pid ];then 13 $path/nginx 14 RETVAL=$? 15 if [ $RETVAL -eq 0 ];then 16 action "nginx is started" /bin/true 17 return $RETVAL 18 else 19 action "nginx is started" /bin/false 20 return $RETVAL 21 fi 22 else 23 echo "nginx is running" 24 return 0 25 fi 26 } 27 stop(){ 28 if [ -f $pid ];then 29 $path/nginx -s stop 30 RETVAL=$? 31 if [ $RETVAL -eq 0 ];then 32 action "nginx is stopped" /bin/true 33 return $RETVAL 34 else 35 action "nginx is stopped" /bin/false 36 return $RETVAL 37 fi 38 else 39 echo "nginx is no running" 40 return $RETVAL 41 fi 42 } 43 44 case "$1" in 45 start) 46 start 47 RETVAL=$? 48 ;; 49 stop) 50 stop 51 RETVAL=$? 52 ;; 53 restart) 54 stop 55 sleep 1 56 start 57 RETVAL=$? 58 ;; 59 *) 60 echo $"Usage: $0 {start|stop|restart|reload}" 61 exit 1 62 esac 63 exit $RETVAL