summaryrefslogtreecommitdiff
blob: 3b759df883d8d28314b723c12780ead05241d30d (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
#!/sbin/openrc-run
# Copyright 1999-2021 Gentoo Authors
# Copyright 2019 Alarig Le Lay <alarig@grifon.fr>
# Distributed under the terms of the GNU General Public License v2

extra_started_commands="reload"

pidfile="/run/${RC_SVCNAME}.pid"
command="/usr/sbin/${RC_SVCNAME}"
retry=15
start_stop_daemon_args="--make-pidfile"

CONF_FILE="/etc/${RC_SVCNAME}.conf"
SOCK="/run/${RC_SVCNAME}.ctl"

if [ ${BIRD_GROUP} ]; then
	BIRD_OPTS="${BIRD_OPTS} -g ${BIRD_GROUP}"
fi
if [ ${BIRD_USER} ]; then
	BIRD_OPTS="${BIRD_OPTS} -u ${BIRD_USER}"
fi

client_args="-s ${SOCK}"
command_args="${client_args} -c ${CONF_FILE} -P ${pidfile} ${BIRD_OPTS}"
client_args="${client_args} -r"

depend() {
	need net
	use logger
}

check_run() {
	BIRD_CHECK_CONF="birdc ${client_args} configure check \"${CONF_FILE}\""
	# Check if the bird parser returns what we want
	# We can’t use $? because it’s always 0 if the sock works
	STATE=$(${BIRD_CHECK_CONF} | grep 'Configuration OK')

	if [ -n "${STATE}" ]; then
		return 0
	else
		# We remove the first three lines (garbage informations), the
		# errors begin after that
		eerror "$(${BIRD_CHECK_CONF} | sed '1,3d')"
		return 1
	fi
}

reload() {
	check_run || return 1
	ebegin "Reloading BIRD"
	start-stop-daemon --signal HUP --pidfile "${pidfile}"
	eend $?
}

start_post() {
	checkpath -f -m 0655 -o bird:bird "${pidfile}"
}

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