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

# Default pidfile location
DEFAULT_PIDFILE="/var/run/stunnel/stunnel.pid"
FILES="/etc/stunnel/*.conf"
DAEMON="/usr/sbin/stunnel"

depend() {
	need net
    before logger
}

get_pids() {
    local file=${1}
    if test -f ${file} ; then
        CHROOT=$(grep "^chroot" ${file} | sed "s;.*= *;;")
        PIDFILE=$(grep "^pid" ${file} | sed "s;.*= *;;")
        if [ "${PIDFILE}" == "" ] ; then
            PIDFILE="${DEFAULT_PIDFILE}"
        fi
        if test -f ${CHROOT}/${PIDFILE} ; then
            cat ${CHROOT}/${PIDFILE}
        fi
    fi
}

start() {
    rm -rf /var/run/stunnel/*.pid
	ebegin "Starting stunnel"
    for file in ${FILES} ; do
        if test -f "${file}" ; then
            ARGS="${file} ${STUNNEL_OPTIONS}"
            PROCLIST="$(get_pids ${file})"
            CHROOT=$(grep "^chroot" ${file} | sed "s;.*= *;;")
            PIDFILE=$(grep "^pid" ${file} | sed "s;.*= *;;")
            if [ "${PROCLIST}" ] && kill -0 ${PROCLIST} 2> /dev/null ; then
                ewarn "  already running: ${file} "
            elif ${DAEMON} ${ARGS} ; then
                if ! test -f ${CHROOT}/${PIDFILE} ; then
                    # give the daemon time to create the pid file
                    # See bug #308931 for more details
                    sleep 0.5s
                fi
                if test -f ${CHROOT}/${PIDFILE} ; then
                    einfo "   ${file}"
                else
                    eerror "   error starting: ${file}"
                fi
            fi
        fi
    done
    eend $?
}

stop() {
	ebegin "Stopping stunnel"
    for file in ${FILES} ; do
        PROCLIST=$(get_pids ${file})
        if [ "${PROCLIST}" ] && kill -0 ${PROCLIST} 2> /dev/null ; then
            kill ${PROCLIST}
            einfo "  ${file} "
        fi
    done
    eend $?
}

restart() {
    svc_stop
    sleep 1
    svc_start
}