summaryrefslogtreecommitdiff
path: root/network/nginx/rc.nginx
blob: 0c82902992377456c34920dafd67403d499ed65e (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh
#
# Nginx daemon control script.
# Written for Slackware Linux by Cherife Li <cherife-#-dotimes.com>.

BIN=/usr/sbin/nginx
CONF=/etc/nginx/nginx.conf
PID=/var/run/nginx.pid

nginx_start() {
  # Sanity checks.
  if [ ! -r $CONF ]; then # no config file, exit:
    echo "$CONF does not appear to exist. Abort."
    exit 1
  fi

  if [ -s $PID ]; then
    echo "Nginx appears to already be running?"
    exit 1
  fi

  echo "Starting Nginx server daemon..."
  if [ -x $BIN ]; then
    $BIN -c $CONF
  fi
}

nginx_test_conf() {
  echo "Checking configuration for correct syntax and"
  echo "then trying to open files referenced in configuration..."
  $BIN -t -c $CONF
}

nginx_term() {
  echo "Shutdown Nginx quickly..."
  kill -TERM $(cat $PID)
}

nginx_stop() {
  echo "Shutdown Nginx gracefully..."
  kill -QUIT $(cat $PID)
}

nginx_reload() {
  echo "Reloading Nginx configuration..."
  kill -HUP $(cat $PID)
}

nginx_upgrade() {
  echo "Upgrading to the new Nginx binary."
  echo "Make sure the Nginx binary has been replaced with new one"
  echo "or Nginx server modules were added/removed."
  kill -USR2 $(cat $PID)
  sleep 3
  kill -QUIT $(cat $PID.oldbin)
}

nginx_restart() {
  nginx_quit
  sleep 3
  nginx_start
}

case "$1" in
  check)
    nginx_test_conf
    ;;
  start)
    nginx_start
    ;;
  term)
    nginx_term
    ;;
  stop)
    nginx_stop
    ;;
  reload)
    nginx_reload
    ;;
  restart)
    nginx_restart
    ;;
  upgrade)
    nginx_upgrade
    ;;
  *)
  echo "usage: `basename $0` {check|start|term|stop|reload|restart|upgrade}"
esac