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

# default arguments
: "${EXABGP_ARGS:=--env=/etc/${RC_SVCNAME}/exabgp.env /etc/${RC_SVCNAME}/exabgp.conf}"

command="capsh"
command_args="
	--uid=${EXABGP_USER:-exabgp}
	--gid=${EXABGP_GROUP:-exabgp}
	--caps='cap_net_admin+epi cap_setuid+ep-i cap_setgid+ep-i'
	-- -c \"/usr/bin/exabgp ${EXABGP_ARGS}\""
command_background="yes"
pidfile="/run/exabgp/${RC_SVCNAME}.pid"
start_stop_daemon_args="
	--stdout /var/log/${RC_SVCNAME}/exabgp.log
	--stderr /var/log/${RC_SVCNAME}/exabgp.log"
extra_started_commands="routes sessions"
extra_commands="checkconfig"

depend() {
	need net
}

start_pre() {
	checkpath -q -d -m 0755 -o "${EXABGP_USER}:${EXABGP_GROUP}" \
		/run/exabgp || return

	checkpath -q -p -m 0600 -o "${EXABGP_USER}:${EXABGP_GROUP}" \
		/run/exabgp/${RC_SVCNAME}.{in,out} || return

	checkconfig || return
}

stop_pre() {
	# don't restart if the configuration is bad
	if [ "${RC_CMD}" = restart ]; then
		checkconfig || return
	fi
}

checkconfig() {
	ebegin "Checking configuration for ${RC_SVCNAME}"
	exabgp -t ${EXABGP_ARGS}
	eend ${?} "Invalid configuration"
}

sessions() {
	ebegin "Querying sessions"
	exabgpcli --env /etc/${RC_SVCNAME}/exabgp.env show neighbor summary
	eend ${?} "exabgpcli failed"
}

routes() {
	ebegin "Querying routes"
	exabgpcli --env /etc/${RC_SVCNAME}/exabgp.env show adj-rib out
	eend ${?} "exabgpcli failed"
}