aboutsummaryrefslogtreecommitdiffstats
path: root/community/tinc-pre/tinc-pre.initd
blob: 55728bec2c78b26038dc088c4a783f3a0f01373d (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
77
78
#!/sbin/openrc-run
# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

extra_started_commands="reload"

NETS="/etc/conf.d/tinc.networks"
DAEMON="/usr/sbin/tincd"

depend() {
	use logger dns
	need net
}

checkconfig() {
	if [ "${RC_SVCNAME}" = "tincd" ] ; then
		ALL_NETNAME="$(awk '/^ *NETWORK:/ { print $2 }' "${NETS}")"
	else
		ALL_NETNAME="${RC_SVCNAME#*.}"
	fi
	# warn this if still not found
	if [ -z "${ALL_NETNAME}" ] ; then
		eerror "No VPN networks configured in ${NETS}"
		return 1
	fi
	return 0
}

start() {
	ebegin "Starting tinc VPN networks"
	checkconfig || return 1
	for NETNAME in ${ALL_NETNAME}
	do
		CONFIG="/etc/tinc/${NETNAME}/tinc.conf"
		PIDFILE="/run/tinc.${NETNAME}.pid"
		if [ ! -f "${CONFIG}" ]; then
			eerror "Cannot start network ${NETNAME}."
			eerror "Please set up ${CONFIG} !"
		else
			ebegin "Starting tinc network ${NETNAME}"
			if [ "${SYSLOG}" = "yes" ]; then
				LOG=""
			else
				LOG="--logfile=/var/log/tinc.${NETNAME}.log"
			fi
			start-stop-daemon --start --exec "${DAEMON}" --pidfile "${PIDFILE}" -- --net="${NETNAME}" ${LOG} --pidfile "${PIDFILE}" --debug="${DEBUG_LEVEL}" ${EXTRA_OPTS}
			eend $?
		fi
	done
}

stop() {
	ebegin "Stopping tinc VPN networks"
	checkconfig || return 1
	for NETNAME in ${ALL_NETNAME}
	do
		PIDFILE="/run/tinc.${NETNAME}.pid"
		if [ -f "${PIDFILE}" ]; then
			ebegin "Stopping tinc network ${NETNAME}"
			start-stop-daemon --stop --pidfile "${PIDFILE}"
			eend $?
		fi
	done
}

reload() {
	ebegin "Reloading configuration for tinc VPN networks"
	checkconfig || return 1
	for NETNAME in ${ALL_NETNAME}
	do
		PIDFILE="/run/tinc.${NETNAME}.pid"
		if [ -f "${PIDFILE}" ]; then
			ebegin "Reloading tinc network ${NETNAME}"
			start-stop-daemon --signal HUP --pidfile ${PIDFILE}
			eend $?
		fi
	done
}