summaryrefslogtreecommitdiff
path: root/community/nginx/rc.d
blob: eb9031e81fae8b8957f1619e1a0c1fdec7c1916a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash

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

function check_config {
  stat_busy "Checking nginx configuration"
  /usr/sbin/nginx -t -q -c /etc/nginx/nginx.conf
  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 /etc/nginx/nginx.conf &>/dev/null
    if [ $? -ne 0 ]; then
      stat_fail
    else
      add_daemon nginx
      stat_done
    fi
    ;;
  stop)
    stat_busy "Stopping nginx"
    PID=$(cat /var/run/nginx.pid)
    kill -QUIT $PID &>/dev/null
    if [ $? -ne 0 ]; then
      stat_fail
    else
      for i in {1..10}; do
        [ -d /proc/$PID ] || { stat_done; rm_daemon nginx; exit 0; }
        sleep 1
      done
      stat_fail
    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