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

# If you want to run multiple separate processes, then create symlinks to
# this runscript (e.g. uwsgi.myapp or myapp) and configure options in
# the corresponding conf.d files. uWSGI options can be specified using
# variable uwsgi_opts or config file specified by variable uwsgi_conf.

: ${pidfile:="/run/$RC_SVCNAME/uwsgi.pid"}

extra_started_commands='reload stats'
description_reload='Gracefully reload all the workers and the master process'
description_stats='Dump uWSGI statistics to log file'

command='/usr/sbin/uwsgi'
command_args="--die-on-term ${uwsgi_opts:-}"
command_background='yes'
start_stop_daemon_args='--quiet'
retry='INT/30/KILL/5'

if [ "$RC_SVCNAME" = 'uwsgi' ]; then
	: ${name:="uWSGI emperor"}
	emperor='yes'
else
	: ${name:="uWSGI application ${RC_SVCNAME#uwsgi.}"}
	emperor='no'
fi

depend() {
	need net
	use apache2 lighttpd nginx
	after postgresql
}

start_pre() {
	if [ "$emperor" = 'yes' ]; then
		: ${logfile:="/var/log/uwsgi/uwsgi.log"}
		: ${user:="root"}
	else
		: ${user:="nobody"}
		command_args="--master $command_args"
	fi
	start_stop_daemon_args="$start_stop_daemon_args
		--user $user
		$(optif --group "$group")
		$(optif --stdout "$logfile")
		$(optif --stderr "$logfile")"

	if [ -z "$uwsgi_conf" ]; then
		case "$RC_SVCNAME" in
			uwsgi) uwsgi_conf='/etc/uwsgi/uwsgi.ini';;
			uwsgi.*) uwsgi_conf="/etc/uwsgi/conf.d/${RC_SVCNAME#uwsgi.}";;
			*) uwsgi_conf="/etc/$RC_SVCNAME/uwsgi";;
		esac
	fi

	if [ -f "${uwsgi_conf%.ini}.ini" ]; then
		command_args="$command_args --ini ${uwsgi_conf%.ini}.ini"
	elif [ -f "${uwsgi_conf%.yml}.yml" ]; then
		command_args="$command_args --yaml ${uwsgi_conf%.yml}.yml"
	fi

	checkpath -d -m 775 -o $user:$group \
		"$(dirname "$pidfile")"

	if yesno "$EINFO_VERBOSE"; then
		einfo "Command: $command $(printf '%s ' $command_args)"
	fi
}

reload() {
	ebegin "Reloading $name"
	start-stop-daemon --signal HUP --pidfile "$pidfile"
	eend $?
}

stats() {
	ebegin "Dumping statistics for $name to the log file"
	start-stop-daemon --signal USR1 --pidfile "$pidfile"
	eend $?
}

optif() {
	test -n "$2" && printf "%s %s\n" "$1" "$2"
}