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

: ${REDSOCKS_BINARY:=/usr/sbin/redsocks}
: ${REDSOCKS_CONFIG:=/etc/redsocks.conf}
: ${REDSOCKS_PIDFILE:=/run/redsocks/redsocks.pid}

extra_commands="checkconfig"
extra_started_commands="reload"

depend() {
	need localmount
	use dns
}

checkconfig() {
	if [ ! -f "${REDSOCKS_CONFIG}" ] ; then
		eerror "No ${REDSOCKS_CONFIG} file exists!"
		return 1
	fi

        "${REDSOCKS_BINARY}" -t -c ${REDSOCKS_CONFIG} || return 1
}

start() {
        checkconfig || return 1

        ebegin "Starting ${SVCNAME}"
        start-stop-daemon --start --exec "${REDSOCKS_BINARY}" \
            -p "${REDSOCKS_PIDFILE}" -c ${REDSOCKS_CONFIG}
        eend $?
}

stop() {
        if [ "${RC_CMD}" = "restart" ] ; then
                checkconfig || return 1
        fi

        ebegin "Stopping ${SVCNAME}"
        start-stop-daemon --stop --exec "${REDSOCKS_BINARY}" \
            -p "${REDSOCKS_PIDFILE}" -c "${REDSOCKS_CONFIG}"
        eend $?
}

reload() {
        checkconfig || return 1

        ebegin "Reloading ${SVCNAME}"
        start-stop-daemon --signal HUP --exec "${REDSOCKS_BINARY}" \
	    -p "${REDSOCKS_PIDFILE}" -c "${REDSOCKS_CONFIG}"
        eend $?
}