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

description="Nginx http and reverse proxy server"
description_checkconfig="Verify configuration"
description_upgrade="Upgrade running binary"
description_reload="Reload configuration"
description_reopen="Reopen log files"

extra_commands="checkconfig"
extra_started_commands="reload reopen upgrade"

cfgfile=${NGINX_CONFIG:-/etc/nginx/nginx.conf}
pidfile=/run/nginx/nginx.pid
command=/usr/sbin/nginx
command_args="-c $cfgfile"
required_files="$cfgfile"

depend() {
	need net
	use dns logger netmount
}

checkconfig() {
	ebegin "Checking $RC_SVCNAME config"
	$command $command_args -t
	eend $?
}

start_pre() {
	ebegin
	checkpath -d -o ${NGINX_OWNER:-nginx:nginx} ${pidfile%/*}
	checkconfig >/dev/null 2>&1
	eend $?
}

reload() {
	ebegin "Reloading $RC_SVCNAME configuration"
	checkconfig >/dev/null 2>&1 && start-stop-daemon --signal HUP --pidfile $pidfile
	eend $?
}

reopen() {
	ebegin "Reopening $RC_SVCNAME log files"
	start-stop-daemon --signal USR1 --pidfile $pidfile
	eend $?
}

upgrade() {
	checkconfig || return $?

	ebegin "Upgrading $RC_SVCNAME binary"

	einfo "Sending USR2 to old binary"
	start-stop-daemon --signal USR2 --pidfile $pidfile

	einfo "Sleeping 3 seconds before pid-files checking"
	sleep 3

	if [ ! -f $pidfile.oldbin ]; then
		eerror "File with old pid ($pidfile.oldbin) not found"
		return 1
	fi

	if [ ! -f $pidfile ]; then
		eerror "New binary failed to start"
		return 1
	fi

	einfo "Sleeping 3 seconds before WINCH"
	sleep 3 ; start-stop-daemon --signal 28 --pidfile $pidfile.oldbin

	einfo "Sending QUIT to old binary"
	start-stop-daemon --signal QUIT --pidfile $pidfile.oldbin

	einfo "Upgrade completed"

	eend $? "Upgrade failed"
}