aboutsummaryrefslogtreecommitdiffstats
path: root/community/py-waitress/waitress.initd
blob: 79e3aa5d3d10a7454428e343c88216d7be4e1e1b (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
#!/sbin/openrc-run

: ${user:="nobody"}
: ${python:="/usr/bin/python3"}
: ${python_opts:="-u"}  # this is needed for stdout/stderr redirect to work
: ${wsgi_module:=}
: ${wsgi_object:="application"}
: ${wsgi_call:="no"}

command="$python"
command_args="$python_opts /usr/bin/waitress-serve"
command_background="yes"

pidfile="/run/$RC_SVCNAME.pid"
start_stop_daemon_args="
	--interpreted
	--user $user
	${group:+--group $group}
	${basedir:+--chdir $basedir}
	${start_stop_daemon_args:-}"

depends() {
	need net
	after postgresql
}

start_pre() {
	local waitress_args=""

	if [ "$RC_SVCNAME" = "waitress" ]; then
		ewarn "You are not supposed to run this runscript directly. Instead, you should"
		ewarn "create a symlink for the application you want to run as well as a copy of"
		ewarn "the configuration file and modify it appropriately, like so:"
		ewarn ""
		ewarn "    ln -s waitress /etc/init.d/myapp"
		ewarn "    cp /etc/conf.d/waitress /etc/conf.d/myapp"
		ewarn ""
	fi

	if [ -z "$wsgi_module" ]; then
		eerror '$wsgi_module must be set!'; return 1
	fi

	if [ -n "${logfile:-}" ]; then
		start_stop_daemon_args="$start_stop_daemon_args
			--stdout $logfile --stderr $logfile"
		checkpath -f -m 0644 -o $user "$logfile"
	fi

	if [ -n "$unix_socket_path" ]; then
		checkpath -d -m 0755 -o $user "${unix_socket_path%/*}"
	fi

	if yesno "$wsgi_call"; then
		waitress_args="$waitress_args --call"
	fi

	local item; for item in ${listen_on:-}; do
		waitress_args="$waitress_args --listen='$item'"
	done

	waitress_args="$waitress_args
		$(optif --unix-socket "$unix_socket_path")
		$(optif --unix-socket-perms "$unix_socket_perms")
		$(optif --url-scheme "$url_scheme")
		$(optif --url-prefix "$url_prefix")
		$(optif --ident "$server_ident")
		${waitress_opts:-}
		$wsgi_module:$wsgi_object"

	command_args="$command_args $waitress_args"
}

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