Advertisement
kevin25

nginx startup script

Mar 11th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.95 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # nginx - this script starts and stops the nginx daemin
  4. #
  5. # chkconfig:   - 85 15
  6. # description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
  7. #               proxy and IMAP/POP3 proxy server
  8. # processname: nginx
  9. # config:      /etc/nginx/nginx.conf
  10. # pidfile:     /var/run/nginx.pid
  11.  
  12. # Source function library.
  13. . /etc/rc.d/init.d/functions
  14.  
  15. # Source networking configuration.
  16. . /etc/sysconfig/network
  17.  
  18. # Check that networking is up.
  19. [ "$NETWORKING" = "no" ] && exit 0
  20.  
  21. nginx="/opt/nginx/sbin/nginx"
  22. prog=$(basename $nginx)
  23.  
  24. NGINX_CONF_FILE="/etc/nginx/nginx.conf"
  25.  
  26. lockfile=/var/lock/nginx.lock
  27.  
  28. start() {
  29.     [ -x $nginx ] || exit 5
  30.     [ -f $NGINX_CONF_FILE ] || exit 6
  31.     echo -n $"Starting $prog: "
  32.     daemon $nginx -c $NGINX_CONF_FILE
  33.     retval=$?
  34.     echo
  35.     [ $retval -eq 0 ] && touch $lockfile
  36.     return $retval
  37. }
  38.  
  39. stop() {
  40.     echo -n $"Stopping $prog: "
  41.     killproc $prog -QUIT
  42.     retval=$?
  43.     echo
  44.     [ $retval -eq 0 ] && rm -f $lockfile
  45.     return $retval
  46. }
  47.  
  48. restart() {
  49.     configtest || return $?
  50.     stop
  51.     start
  52. }
  53.  
  54. reload() {
  55.     configtest || return $?
  56.     echo -n $"Reloading $prog: "
  57.     killproc $nginx -HUP
  58.     RETVAL=$?
  59.     echo
  60. }
  61.  
  62. force_reload() {
  63.     restart
  64. }
  65.  
  66. configtest() {
  67.   $nginx -t -c $NGINX_CONF_FILE
  68. }
  69.  
  70. rh_status() {
  71.     status $prog
  72. }
  73.  
  74. rh_status_q() {
  75.     rh_status >/dev/null 2>&1
  76. }
  77.  
  78. case "$1" in
  79.     start)
  80.         rh_status_q && exit 0
  81.         $1
  82.         ;;
  83.     stop)
  84.         rh_status_q || exit 0
  85.         $1
  86.         ;;
  87.     restart|configtest)
  88.         $1
  89.         ;;
  90.     reload)
  91.         rh_status_q || exit 7
  92.         $1
  93.         ;;
  94.     force-reload)
  95.         force_reload
  96.         ;;
  97.     status)
  98.         rh_status
  99.         ;;
  100.     condrestart|try-restart)
  101.         rh_status_q || exit 0
  102.             ;;
  103.     *)
  104.         echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
  105.         exit 2
  106. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement