aboutsummaryrefslogtreecommitdiffstats
path: root/community/stunnel/stunnel.initd
blob: 6b8ab0335b1eceb2d90e5ecf4ef6f8c54ad0d0c3 (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
#!/sbin/openrc-run

instance_name="${SVCNAME#*.}"
instance_name="${instance_name:-stunnel}"
config_file="${STUNNEL_CONFIGFILE:-/etc/stunnel/$instance_name.conf}"

extra_started_commands="reload"

command="/usr/bin/stunnel"
command_args="$config_file $STUNNEL_OPTIONS"
pidfile="/run/stunnel/$instance_name.pid"  # default value

required_files="$config_file"


depend() {
	need net
	before logger
}

start_pre() {
	pidfile=$(config_get "pid" "$pidfile")

	local chroot_dir=$(config_get "chroot")
	[ -z "$chroot_dir" ] || start_stop_daemon_args="--chroot $chroot_dir"

	local user=$(config_get "setuid" "stunnel")
	local group=$(config_get "setgid" "stunnel")

	checkpath -d -m 0775 -o root:$group /run/stunnel

	if [ ! "$(dirname "$pidfile")" -ef "/run" ]; then
		checkpath -d -m 0755 -o $user:$group "$(dirname "$pidfile")"
	fi
}

stop_pre() {
	pidfile=$(config_get "pid" "$pidfile")
}

reload() {
	pidfile=$(config_get "pid" "$pidfile")

	ebegin "Reloading $SVCNAME"
	start-stop-daemon --signal HUP --pidfile "$pidfile" --name stunnel
	eend $?
}

config_get() {
	local key="$1"
	local default="${2:-}"

	local val="$(sed -En "s|^$key\s*=\s*(.*)\s*$|\1|p" "$config_file")"
	echo "${val:-$default}"
}