Difference between revisions of "Nginx/Init script"

From ArchWiki
Jump to: navigation, search
(Created.)
 
(categorize, add link back to parent article)
Line 1: Line 1:
/etc/rc.d/nginx snippet. It must be owned by root with permissions 755.
+
[[Category:Web Server (English)]]
 +
Go back to [[Nginx]].
  
<pre>
+
{{ic|/etc/rc.d/nginx}} snippet. It must be owned by root with permissions 755.
 +
 
 +
{{bc|<nowiki>
 
#!/bin/bash
 
#!/bin/bash
  
Line 69: Line 72:
 
     echo "usage: $0 {start|stop|restart|reload|check|careless_start}"
 
     echo "usage: $0 {start|stop|restart|reload|check|careless_start}"
 
esac
 
esac
</pre>
+
</nowiki>}}

Revision as of 14:26, 27 November 2011

Go back to Nginx.

/etc/rc.d/nginx snippet. It must be owned by root with permissions 755.

#!/bin/bash

# general config

. /etc/conf.d/nginx
. /etc/rc.conf
. /etc/rc.d/functions

function check_config {
  stat_busy "Checking configuration"
  /usr/sbin/nginx -t -q -c "$NGINX_CONFIG"
  if [ $? -ne 0 ]; then
    stat_die
  else
    stat_done
  fi
}

case "$1" in
  start)
    check_config
    $0 careless_start
    ;;
  careless_start)
    stat_busy "Starting Nginx"
    if [ -s $NGINX_PID ]; then
      stat_fail
      # probably ;)
      stat_busy "Nginx is already running"
      stat_die
     fi
    /usr/sbin/nginx -c "$NGINX_CONFIG" &>/dev/null
    if [ $? -ne 0 ]; then
      stat_fail
    else
      add_daemon nginx
      stat_done
    fi
    ;;
  stop)
    stat_busy "Stopping Nginx"
    kill -QUIT `cat $NGINX_PID` &>/dev/null
    if [ $? -ne 0 ]; then
      stat_fail
    else
      rm_daemon nginx
      stat_done
    fi
    ;;
  restart)
    check_config
    $0 stop
    sleep 1
    $0 careless_start
    ;;
  reload)
    check_config
    if [ -s /var/run/nginx.pid ]; then
      status "Reloading Nginx Configuration" kill -HUP `cat $NGINX_PID`
    fi
    ;;
  check)
    check_config
    ;;
  *)
    echo "usage: $0 {start|stop|restart|reload|check|careless_start}"
esac