FAQ

Page Discussion History

Standalone daemon

Revision as of 22:14, 19 May 2010 by Jjuarez (Talk)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

A very simple bash script than let you operate with the nginx daemon. Basically is a platform agnostic ctl script.

#!/bin/sh
 
NGINX_BASE_DIR="/opt/nginx"
NGINX_DAEMON="${NGINX_BASE_DIR}/sbin/nginx"
NGINX_CONF="${NGINX_BASE_DIR}/conf/nginx.conf"
 
__launch_signal( ) {
 
  ${NGINX_DAEMON} -s ${1} &>/dev/null
}
 
__checkconfig( ) {
 
  ${NGINX_DAEMON} -c ${NGINX_CONF} -t &>/dev/null
}
 
__start( ) {
 
  [ -r ${NGINX_CONF} ] || exit 1 
 
  __checkconfig && ${NGINX_DAEMON} -c ${NGINX_CONF} &>/dev/null || return ${?}
}
 
__stop( ) {
 
  __launch_signal stop
}
 
__reload( ) {
 
  __checkconfig && __launch_signar reload || return ${?}  
}
 
__restart( ) {
 
  __stop && __start
}
 
__show_usage( ) {
 
  echo "Usage: ${0} {start|stop|restart|reload}"
  exit 3
}
 
##
# :: main ::
case "${1}" in
  start|stop|restart|reload)
    [ -x ${NGINX_DAEMON} ] || exit 2
    __${1}
    ;;
  *)
    __show_usage
    ;;
esac