Slackware style init script for nginx web server

Slackware style init script for start/stop/restart nginx web server:


#!/bin/sh
#
# /etc/rc.d/rc.nginx
#
# Start/stop/restart nginx web server.

test_config() {
  set +e
  RES=`nginx -t 2>&1`
  if [ $? -ne 0 ] ; then
     echo "Error in nginx configuration found, restart aborted!"
     echo $RES
     exit 10
  fi
  set -e
}

nginx_start() {
 ulimit -n 65535
 /usr/sbin/nginx -c /etc/nginx/nginx.conf
}

nginx_stop() {
 killall nginx
 rm -f /var/run/nginx/nginx.pid
}

nginx_restart() {
 test_config
 nginx_stop
 nginx_start
}

case "$1" in
  'start')
    nginx_start
  ;;
  'stop')
    nginx_stop
  ;;
  'restart')
    nginx_restart
  ;;
  *)
    echo "Usage: $0 {start|stop|restart}"
  ;;
esac

Comments

Comments are closed.