summaryrefslogtreecommitdiff
path: root/net-misc/radvd/files/radvd-2.19.init
blob: 069801e841abbbafdfc041e20a6fa8eded1f60aa (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
#!/sbin/openrc-run
# Copyright 1999-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

CONFIGFILE=/etc/radvd.conf
PIDFILE=/run/radvd/radvd.pid
SYSCTL_FORWARD=net.ipv6.conf.all.forwarding

description="IPv6 Router Advertisement Daemon"

extra_commands="configtest"
extra_started_commands="reload"
description_configtest="Test the configuration and run startup tests"
description_reload="Reload the radvd configuration file"

depend() {
	need net
}

checkconfig() {
	if [ ! -f "${CONFIGFILE}" ]; then
		eerror "Configuration file ${CONFIGFILE} not found"
		return 1
	fi

	if ! /usr/sbin/radvd -c -C "${CONFIGFILE}" ; then
		eerror "Configuration file ${CONFIGFILE} failed test"
		return 1
	fi
}

configtest() {
	ebegin "Checking ${RC_SVCNAME} configuration"
	checkconfig
	eend $?
}

start() {
	if [ "${FORWARD}" != "no" ]; then
		ebegin "Enabling IPv6 forwarding"
		sysctl -w "${SYSCTL_FORWARD}=1" >/dev/null
		eend $?
	fi

	checkconfig || return 1

	checkpath -d -o radvd:radvd "${PIDFILE%/*}"

	ebegin "Starting IPv6 Router Advertisement Daemon"
	start-stop-daemon --start --exec /usr/sbin/radvd \
		--pidfile "${PIDFILE}" \
		-- -C "${CONFIGFILE}" -p "${PIDFILE}" -u radvd ${OPTIONS}
	eend $?
}

stop() {
	ebegin "Stopping IPv6 Router Advertisement Daemon"
	start-stop-daemon --stop --exec /usr/sbin/radvd --pidfile "${PIDFILE}"
	eend $?

	if [ "${FORWARD}" != "no" ]; then
		ebegin "Disabling IPv6 forwarding"
		sysctl -w "${SYSCTL_FORWARD}=0" > /dev/null
		eend $?
	fi
}

reload() {
	if [ "${FORWARD}" != "no" ]; then
		ebegin "Enabling IPv6 forwarding"
		sysctl -w "${SYSCTL_FORWARD}=1" >/dev/null
		eend $?
	fi

	checkconfig || return 1

	checkpath -d -o radvd:radvd "${PIDFILE%/*}"

	ebegin "Reloading IPv6 Router Advertisement Daemon"
	start-stop-daemon --signal HUP \
		--exec /usr/sbin/radvd --pidfile "${PIDFILE}"
	eend $?
}