summaryrefslogtreecommitdiffstats
path: root/main/nginx-lua/nginx.initd
blob: bec20dddaaa8561b23ba7451262613518aba39c8 (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
#!/sbin/openrc-run

extra_started_commands="reload"
extra_commands="configtest"

depend() {
	need net
	use dns logger netmount
}

CONFFILE=${CONFFILE:-/etc/nginx/${SVCNAME}.conf}
PIDFILE=${PIDFILE:-/var/run/${SVCNAME}.pid}

configtest() {
	ebegin "Checking ${SVCNAME} configuration"
	mkdir -p /tmp/nginx
	/usr/sbin/nginx -c ${CONFFILE} -t
	eend $? "failed, please correct errors above"
}

start() {
	configtest || return 1
	ebegin "Starting ${SVCNAME}"
	start-stop-daemon --start --pidfile "${PIDFILE}" \
		--exec /usr/sbin/nginx -- -c ${CONFFILE} -g "pid ${PIDFILE};"
	eend $? "Failed to start ${SVCNAME}"
}

stop() {
	configtest || return 1
	ebegin "Stopping ${SVCNAME}"
	start-stop-daemon --stop --pidfile "${PIDFILE}"
	eend $? "Failed to stop ${SVCNAME}"
	rm -f "${PIDFILE}"
}

reload() {
	configtest || return 1
	ebegin "Refreshing ${SVCNAME} configuration"
	kill -HUP $(cat "${PIDFILE}") &>/dev/null
	eend $? "Failed to reload nginx"
}