Created
September 20, 2013 14:40
-
-
Save vshank77/6638579 to your computer and use it in GitHub Desktop.
nginx Linux Service Wrapper Script (RHEL / Redhat based)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # nginx Start up the Nginx HTTP Reverse Proxy | |
| # | |
| # chkconfig: 2345 55 25 | |
| ### BEGIN INIT INFO | |
| # Provides: nginx | |
| # Required-Start: $remote_fs $network $syslog | |
| # Required-Stop: $remote_fs $syslog | |
| # Should-Start: $syslog | |
| # Should-Stop: $network $syslog | |
| # Default-Start: 2 3 4 5 | |
| # Default-Stop: 0 1 6 | |
| # Short-Description: Start up the Nginx HTTP Reverse Proxy server daemon | |
| # Description: Nginx is a free, open-source, high-performance HTTP server and reverse proxy | |
| # This service starts up the Nginx HTTP Reverse Proxy. | |
| ### END INIT INFO | |
| # source function library | |
| . /etc/rc.d/init.d/functions | |
| # pull in sysconfig settings | |
| [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx | |
| RETVAL=0 | |
| prog="nginx" | |
| lockfile=/var/lock/subsys/$prog | |
| # Some functions to make the below more readable | |
| APPRUN=/usr/local/nginx/sbin/nginx | |
| CONFIG=/usr/local/nginx/conf/nginx.conf | |
| PIDFILE=/usr/local/nginx/logs/nginx.pid | |
| runlevel=$(set -- $(runlevel); eval "echo \$$#" ) | |
| start() | |
| { | |
| [ -x $APPRUN ] || exit 5 | |
| [ -f $CONFIG ] || exit 6 | |
| echo -n $"Starting $prog: " | |
| $APPRUN && success || failure | |
| RETVAL=$? | |
| [ $RETVAL -eq 0 ] && touch $lockfile | |
| echo | |
| return $RETVAL | |
| } | |
| stop() | |
| { | |
| echo -n $"Stopping $prog: " | |
| killproc -p $PIDFILE $APPRUN | |
| RETVAL=$? | |
| # if we are in halt or reboot runlevel kill all running sessions | |
| # so the TCP connections are closed cleanly | |
| if [ "x$runlevel" = x0 -o "x$runlevel" = x6 ] ; then | |
| trap '' TERM | |
| killall $prog 2>/dev/null | |
| trap TERM | |
| fi | |
| [ $RETVAL -eq 0 ] && rm -f $lockfile | |
| echo | |
| } | |
| reload() | |
| { | |
| echo -n $"Reloading $prog: " | |
| killproc -p $PIDFILE $APPRUN -HUP | |
| RETVAL=$? | |
| echo | |
| } | |
| restart() { | |
| stop | |
| start | |
| } | |
| rh_status() { | |
| status -p $PIDFILE $prog | |
| } | |
| rh_status_q() { | |
| rh_status >/dev/null 2>&1 | |
| } | |
| case "$1" in | |
| start) | |
| rh_status_q && exit 0 | |
| start | |
| ;; | |
| stop) | |
| if ! rh_status_q; then | |
| rm -f $lockfile | |
| exit 0 | |
| fi | |
| stop | |
| ;; | |
| restart) | |
| restart | |
| ;; | |
| reload) | |
| rh_status_q || exit 7 | |
| reload | |
| ;; | |
| force-reload) | |
| restart | |
| ;; | |
| status) | |
| rh_status | |
| RETVAL=$? | |
| if [ $RETVAL -eq 3 -a -f $lockfile ] ; then | |
| RETVAL=2 | |
| fi | |
| ;; | |
| *) | |
| echo $"Usage: $0 {start|stop|restart|reload|force-reload|status}" | |
| RETVAL=2 | |
| esac | |
| exit $RETVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment