summaryrefslogtreecommitdiff
blob: a73527ed57e7fecb2cec6da22de6136529005156 (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
#!/sbin/openrc-run
# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

extra_started_commands="reload"
SERVICENAME=${SVCNAME#*.}
SERVICENAME=${SERVICENAME:-stunnel}
STUNNEL_CONFIGFILE=${STUNNEL_CONFIGFILE:-/etc/stunnel/${SERVICENAME}.conf}

depend() {
    need net
    before logger
}

get_config() {
	if [ ! -e ${STUNNEL_CONFIGFILE} ] ; then
		eerror "You need to create ${STUNNEL_CONFIGFILE} first."
		return 1
	fi
	CHROOT=$(grep "^chroot" ${STUNNEL_CONFIGFILE} | sed "s;.*= *;;")
	[ -n "${CHROOT}" ] && CHROOT="--chroot ${CHROOT}"
	PIDFILE=$(grep "^pid" ${STUNNEL_CONFIGFILE} | sed "s;.*= *;;")
	PIDFILE=${PIDFILE:-/run/stunnel/${SERVICENAME}.pid}
}

start() {
	get_config || return 1
	checkpath -d -m 0775 -o root:stunnel /run/stunnel
	if [ "$(dirname ${PIDFILE})" != "/run" ]; then
		checkpath -d -m 0755 -o stunnel:stunnel -q $(dirname ${PIDFILE})
	fi
	ebegin "Starting ${SVCNAME}"
	start-stop-daemon --start --pidfile "${PIDFILE}" ${CHROOT} \
	                  --exec /usr/bin/stunnel -- ${STUNNEL_CONFIGFILE} ${STUNNEL_OPTIONS}
	eend $? "Failed to start ${SVCNAME}"
}

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

reload() {
	get_config || return 1
	ebegin "Reloading ${SVCNAME}"
	start-stop-daemon --signal HUP --pidfile ${PIDFILE} --name stunnel
	eend $?
}