blob: 300a8c657f15a2473a7a2fa5434e0a27237b7c09 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#!/bin/sh /etc/rc.common
2# Copyright (C) 2015 OpenWrt.org
3
4START=80
5
6USE_PROCD=1
7
8G_OPTS="daemon off;"
9
10NGINX_UTIL="/usr/bin/nginx-util"
11
12eval $("${NGINX_UTIL}" get_env)
13
14CONF=""
15
16
17nginx_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
44start_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
58reload_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
69extra_command "relog" "Reopen log files (without reloading)"
70relog() {
71 [ -d /var/log/nginx ] || mkdir -p /var/log/nginx
72 procd_send_signal nginx '*' USR1
73}