summaryrefslogtreecommitdiff
path: root/security/tinc/files/tincd.in
blob: 1463aa0b2801d0a298fc2dd90afc253d076f5d25 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/sh

# PROVIDE: tincd
# REQUIRE: ipfilter FILESYSTEMS sysctl netif
# BEFORE:  SERVERS routing
# KEYWORD: shutdown
#
# Define these tincd_* variables in one of these files:
#	/etc/rc.conf
#	/etc/rc.conf.local
#	/etc/rc.conf.d/tincd
#
# tincd_enable (bool):	Set to "NO" by default.
#			Set it to "YES" to enable tincd.
# tincd_cfg (str):	Set to "" by default.
#			Set it to NETNAMEs to use (ex.: "vpn1 vpn2").
# tincd_flags (str):	Set to "" by default.
#			Set it to flags to use (ex.: "-d 1 --logfile").
#
# DO NOT CHANGE THESE DEFAULT VALUES HERE

. /etc/rc.subr

name="tincd"
desc="Tinc VPN Daemon"
rcvar="tincd_enable"

load_rc_config $name

: ${tincd_enable:="NO"}
command="%%PREFIX%%/sbin/tincd"
start_cmd="tincd_start"
stop_cmd="tincd_stop"
reload_cmd="tincd_reload"
status_cmd="tincd_status"
extra_commands="reload"
procname=${command:-tincd}
ldconfig_command="/sbin/ldconfig"

tincd_start()
{
	${ldconfig_command} -elf -m %%LOCALBASE%%/lib
	if test -z "${tincd_cfg}"
	then
		echo "Starting tincd"
		$command
	else
		for cfg in ${tincd_cfg}
		do
			echo "Starting tincd for: ${cfg}"
			$command -n $cfg $tincd_flags
		done
	fi
	# code deliberately borrowed from /etc/rc.d/netif
	if [ -f /etc/rc.d/ipfilter ] ; then
		# Resync ipfilter
		/etc/rc.d/ipfilter quietresync
	fi
}

tincd_stop()
{
	if test -z "${tincd_cfg}"
	then
		echo "Stopping tincd"
		$command -k
	else
		for cfg in $tincd_cfg
		do
			echo "Stopping tincd for: ${cfg}"
			$command -n $cfg -k
		done
	fi
	wait_for_pids $rc_pid
}

tincd_reload()
{
	if test -z "${tincd_cfg}"
	then
		echo "Sending HUP to tincd"
		$command --kill=HUP
	else
		for cfg in $tincd_cfg
		do
			echo "Sending HUP to tincd for: ${cfg}"
			$command -n $cfg --kill=HUP
		done
	fi
}

tincd_status_network()
{
	rc_pid=$(check_pidfile "$pidfile" "$_procname" "$command_interpreter")
	if [ -n "$rc_pid" ]; then
		echo "${name} for ${cfg} is running as pid $rc_pid."
	else
		echo "${name} for ${cfg} is not running."
		return 1
	fi
}

tincd_status()
{
	if test -z "${tincd_cfg}"
	then
		cfg="."
		pidfile="/var/run/tinc.pid"
		tincd_status_network
	else
		for cfg in $tincd_cfg
		do
			pidfile="/var/run/tinc.${cfg}.pid"
			tincd_status_network
		done
	fi
}

run_rc_command "$1"