php8-pecl-xdebug: update to 3.2.1
[feed/packages.git] / net / nginx / files / nginx.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2015 OpenWrt.org
3
4 START=80
5
6 USE_PROCD=1
7
8 G_OPTS="daemon off;"
9
10 NGINX_UTIL="/usr/bin/nginx-util"
11
12 eval $("${NGINX_UTIL}" get_env)
13
14 CONF=""
15
16
17 nginx_init() {
18 [ -z "${CONF}" ] || return # already called.
19
20 [ -d /var/log/nginx ] || mkdir -p /var/log/nginx
21 [ -d /var/lib/nginx ] || mkdir -p /var/lib/nginx
22
23 rm -f "$(readlink "${UCI_CONF}")"
24 ${NGINX_UTIL} init_lan
25
26 if [ -e "${UCI_CONF}" ]
27 then CONF="${UCI_CONF}"
28 else CONF="${NGINX_CONF}"
29 fi
30
31 local message
32 message="$(/usr/sbin/nginx -t -c "${CONF}" -g "${G_OPTS}" 2>&1)" ||
33 {
34 echo -e "${message}" | logger -t "nginx_init" -p "daemon.err"
35 logger -s -t "nginx_init" -p "daemon.err" "NOT using conf file!"
36 echo "show config to be used by: nginx -T -c '${CONF}'" >&2
37 exit 1
38 }
39
40 logger -t "nginx_init" -p "daemon.info" "using ${CONF} (the test is ok)"
41 }
42
43
44 start_service() {
45 nginx_init
46
47 procd_open_instance
48 procd_set_param command /usr/sbin/nginx -c "${CONF}" -g "${G_OPTS}"
49 procd_set_param stdout 1
50 procd_set_param stderr 1
51 procd_set_param file "${CONF}" "${CONF_DIR}*.crt" "${CONF_DIR}*.key" \
52 "${CONF_DIR}*.conf" "${CONF_DIR}*.locations"
53 procd_set_param respawn
54 procd_close_instance
55 }
56
57
58 reload_service() {
59 nginx_init
60
61 if [ "$(cat "/proc/$(cat "/var/run/nginx.pid")/cmdline")" = \
62 "nginx: master process /usr/sbin/nginx -c ${CONF} -g ${G_OPTS}" ]
63 then procd_send_signal nginx
64 else restart
65 fi
66 }
67
68
69 service_triggers() {
70 procd_add_raw_trigger acme.renew 5000 /etc/init.d/nginx reload
71 }
72
73
74 extra_command "relog" "Reopen log files (without reloading)"
75 relog() {
76 [ -d /var/log/nginx ] || mkdir -p /var/log/nginx
77 procd_send_signal nginx '*' USR1
78 }