Difference between revisions of "Nginx/Init script"

From ArchWiki
Jump to: navigation, search
(categorize, add link back to parent article)
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Web Server (English)]]
+
[[Category:Web Server]]
 
Go back to [[Nginx]].
 
Go back to [[Nginx]].
  
Line 8: Line 8:
  
 
# general config
 
# general config
 +
 +
NGINX_CONFIG="/etc/nginx/conf/nginx.conf"
  
 
. /etc/conf.d/nginx
 
. /etc/conf.d/nginx
Line 30: Line 32:
 
   careless_start)
 
   careless_start)
 
     stat_busy "Starting Nginx"
 
     stat_busy "Starting Nginx"
     if [ -s $NGINX_PID ]; then
+
     if [ -s /var/run/nginx.pid ]; then
 
       stat_fail
 
       stat_fail
 
       # probably ;)
 
       # probably ;)
Line 46: Line 48:
 
   stop)
 
   stop)
 
     stat_busy "Stopping Nginx"
 
     stat_busy "Stopping Nginx"
     kill -QUIT `cat $NGINX_PID` &>/dev/null
+
     kill -QUIT `cat /var/run/nginx.pid` &>/dev/null
 
     if [ $? -ne 0 ]; then
 
     if [ $? -ne 0 ]; then
 
       stat_fail
 
       stat_fail
Line 63: Line 65:
 
     check_config
 
     check_config
 
     if [ -s /var/run/nginx.pid ]; then
 
     if [ -s /var/run/nginx.pid ]; then
       status "Reloading Nginx Configuration" kill -HUP `cat $NGINX_PID`
+
       status "Reloading Nginx Configuration" kill -HUP `cat /var/run/nginx.pid`
 
     fi
 
     fi
 
     ;;
 
     ;;
Line 72: Line 74:
 
     echo "usage: $0 {start|stop|restart|reload|check|careless_start}"
 
     echo "usage: $0 {start|stop|restart|reload|check|careless_start}"
 
esac
 
esac
 +
</nowiki>}}
 +
 +
{{ic|/etc/conf.d/nginx}} snippet. It must be owned by root with permissions 755.
 +
 +
{{bc|<nowiki>
 +
NGINX_CONFIG=/etc/nginx/conf/nginx.conf
 
</nowiki>}}
 
</nowiki>}}

Revision as of 15:17, 23 April 2012

Go back to Nginx.

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

#!/bin/bash

# general config

NGINX_CONFIG="/etc/nginx/conf/nginx.conf"

. /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 /var/run/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 /var/run/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 /var/run/nginx.pid`
    fi
    ;;
  check)
    check_config
    ;;
  *)
    echo "usage: $0 {start|stop|restart|reload|check|careless_start}"
esac

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

NGINX_CONFIG=/etc/nginx/conf/nginx.conf