#!/bin/sh # # nginx Nginx Web Server (@flavor@ version) # # chkconfig: 345 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx-@flavor@ # pidfile: /var/run/nginx-@flavor@.pid # config: /etc/nginx/nginx-@flavor@.conf # Source function library . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network nginx="/usr/sbin/nginx-@flavor@" svname="nginx (@flavor@)" prog=${nginx##*/} sysconfig="/etc/sysconfig/$prog" lockfile="/var/lock/subsys/$prog" pidfile="/var/run/$prog.pid" NGINX_CONF_FILE="/etc/nginx/$prog.conf" # Get service config [ -f $sysconfig ] && . $sysconfig # Check that networking is up. if is_yes "${NETWORKING}"; then if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then msg_network_down "$svname" exit 1 fi else exit 0 fi # configtest itself # must return non-zero if check failed # output is discarded if checkconfig is ran without details configtest() { $nginx -t -c $NGINX_CONF_FILE } # wrapper for configtest checkconfig() { local details=${1:-0} if [ $details = 1 ]; then # run config test and display report (status action) show "Checking %s configuration" "$svname"; busy local out out=$(configtest 2>&1) RETVAL=$? if [ $RETVAL = 0 ]; then ok else fail fi [ "$out" ] && echo >&2 "$out" else # run config test and abort with nice message if failed # (for actions checking status before action). configtest >/dev/null 2>&1 RETVAL=$? if [ $RETVAL != 0 ]; then show "Checking %s configuration" "$svname"; fail nls 'Configuration test failed. See details with %s "checkconfig"' $0 exit $RETVAL fi fi } start() { # Check if the service is already running? if [ ! -f $lockfile ]; then checkconfig msg_starting "$svname" daemon $nginx -c $NGINX_CONF_FILE RETVAL=$? [ $RETVAL -eq 0 ] && touch $lockfile else msg_already_running "$svname" fi } stop() { # Stop daemons. if [ -f $lockfile ]; then msg_stopping "$svname" killproc $prog rm -f $lockfile $pidfile >/dev/null 2>&1 else msg_not_running "$svname" fi } reload() { if [ -f $lockfile ]; then checkconfig msg_reloading "$svname" killproc $prog -HUP RETVAL=$? else msg_not_running "$svname" RETVAL=7 fi } condrestart() { if [ ! -f $lockfile ]; then msg_not_running "$svname" RETVAL=$1 return fi checkconfig stop start } RETVAL=0 # See how we were called. case "$1" in start) start ;; stop) stop ;; restart) checkconfig stop start ;; try-restart) condrestart 0 ;; reload|force-reload|graceful) reload ;; checkconfig|configtest) checkconfig 1 ;; status) status $prog RETVAL=$? ;; *) msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|graceful|checkconfig|status}" exit 3 ;; esac exit $RETVAL