summaryrefslogtreecommitdiff
path: root/net/gobgp/files/gobgpd.in
blob: 1030b00e2c465c51dd8194e9c00688bb4712115c (plain) (blame)
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
#!/bin/sh

# PROVIDE: gobgpd
# REQUIRE: netif routing
# BEFORE:  LOGIN
# KEYWORD: shutdown
#
# Define these gobgpd* variables in one of these files:
#	/etc/rc.conf
#	/etc/rc.conf.local
#	/etc/rc.conf.d/gobgpd
#
# DO NOT CHANGE THESE DEFAULT VALUES HERE
#
# Add the following lines to /etc/rc.conf to enable gobgpd:
#
# gobgpd_enable="YES"
# gobgpd_config="<default unset>"
# gobgpd_config_type="<default unset>"
# gobgpd_flags="<set as needed>"
# gobgpd_log_level="<set as needed like 'debug'>"
# gobgpd_stdlog_enable="<default 'NO'>"
# gobgpd_syslog_host="<set as needed like 'yes'(same as ':') or 'udp:otherhost:514'>"
# gobgpd_syslog_facility="<set as needed like 'daemon'>"
# gobgpd_foreground_enable="<default 'NO'>"
#

. /etc/rc.subr

name="gobgpd"
rcvar="gobgpd_enable"

load_rc_config $name

: ${gobgpd_enable:=NO}
: ${gobgpd_stdlog_enable:=NO}
: ${gobgpd_foreground_enable:=NO}

pidfile="/var/run/${name}.pid"
procname="%%PREFIX%%/libexec/gobgpd"
command_args="${gobgpd_flags}${gobgpd_ctype:+ -t ${gobgpd_config_type}}${gobgpd_config:+ -f ${gobgpd_config}}${gobgpd_log_level:+ --log-level=${gobgpd_log_level}}"

start_cmd="gobgpd_start"
start_precmd="gobgpd_prestart"
reload_cmd="gobgpd_reload"
sig_stop="KILL"

gobgpd_prestart () {
	case "${gobgpd_flags}" in
	-f*|*-f*|--config-file*|*--config-file*)
		err 1 "gobgpd_flags includes the --config-file option, use gobgpd_config instead."
		;;
	-t*|*-t*|--config-type*|*--config-type*)
		err 1 "gobgpd_flags includes the --config-type option, use gobgpd_config_type instead."
		;;
	-s*|*-s*|--syslog*)
		err 1 "gobgpd_flags includes the --syslog option, use gobgpd_syslog_host instead."
		;;
	--syslog-facility*|*--syslog-facility*)
		err 1 "gobgpd_flags includes the --syslog-facility option, use gobgpd_syslog_host instead."
		;;
	--disable-stdlog*|*--disable-stdlog*)
		err 1 "gobgpd_flags includes the --disable-stdlog option, use gobgpd_stdlog_enable instead."
		;;
	--log-level*|*--log-level*)
		err 1 "gobgpd_flags includes the --log-level option, use gobgp_log_level instead."
		;;
	-d*|*-d*|--dry-run*|*--dry-run*)
		err 1 "gobgpd_flags doesn't require --dry-run option."
		;;
	-h*|*-h*|--help*|*--help*)
		err 1 "gobgpd_flags doesn't require --help option."
		;;
	esac

	case "x${gobgpd_config_type}" in
	x|xtoml|xyaml|xjson)
		;;
	*)
		err 1 "gobgpd_config_type requires one of 'toml', 'yaml' or 'json'."
	esac

	if [ -f ${gobgpd_config} ]; then
		${procname} --dry-run ${command_args} > /dev/null
		if [ $? -ne 0 ]; then
			err 1 $(${procname} --dry-run --log-plain ${command_args})
		fi
	fi
}

gobgpd_start () {
	if checkyesno gobgpd_foreground_enable; then
		${procname} ${command_args} $(checkyesno gobgpd_stdlog_enable || echo --disable-stdlog) ${gobgpd_syslog_host:+ --syslog=${gobgpd_syslog_host}}${gobgpd_syslog_facility:+ --syslog-facility=${gobgpd_syslog_facility}}
	else
		echo "Starting ${name}."
		/usr/sbin/daemon -c -p ${pidfile} ${procname} ${command_args} $(checkyesno gobgpd_stdlog_enable || echo --disable-stdlog) ${gobgpd_syslog_host:+ --syslog=${gobgpd_syslog_host}}${gobgpd_syslog_facility:+ --syslog-facility=${gobgpd_syslog_facility}}
	fi
}

gobgpd_reload () {
	echo "Graceful Restarting ${name}."
	${procname} --graceful-restart ${command_args}
}

run_rc_command "$1"