diff options
Diffstat (limited to 'security/netbird/files/netbird.in')
-rw-r--r-- | security/netbird/files/netbird.in | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/security/netbird/files/netbird.in b/security/netbird/files/netbird.in index 191491ea3604..ddd19f27cd52 100644 --- a/security/netbird/files/netbird.in +++ b/security/netbird/files/netbird.in @@ -4,15 +4,61 @@ # REQUIRE: SERVERS # KEYWORD: shutdown # +# Add the following lines to /etc/rc.conf to enable this service: +# +# netbird_enable (bool): Set it to YES to run netbird on startup. +# Default: NO +# netbird_config (path): Path to the netbird configuration file. +# Default: /var/db/netbird/config.json +# netbird_socket (path): Path to the Unix-domain socket for daemon communication. +# Default: /var/run/netbird.sock +# netbird_loglevel (str): Set to 'panic', 'fatal', 'error', 'warn', 'info', 'debug' or 'trace'. +# Default: 'info' +# netbird_logfile (path): Path to the client log file. +# Default: /var/log/netbird/client.log +# netbird_tun_dev (str): Name of the TUN device used by Netbird for its VPN tunnel. +# Default: wt0 +# . /etc/rc.subr name="netbird" -netbird_env="IS_DAEMON=1" +rcvar="${name}_enable" + +load_rc_config "$name" + +: ${netbird_enable:="NO"} +: ${netbird_config:="/var/db/netbird/config.json"} +: ${netbird_socket:="/var/run/netbird.sock"} +: ${netbird_loglevel:="info"} +: ${netbird_logfile:="/var/log/netbird/client.log"} +: ${netbird_tun_dev:="wt0"} + pidfile="/var/run/${name}.pid" command="/usr/sbin/daemon" daemon_args="-P ${pidfile} -r -t \"${name}: daemon\"" -command_args="${daemon_args} /usr/local/bin/netbird service run --config /var/db/netbird/config.json --log-level info --daemon-addr unix:///var/run/netbird.sock --log-file /var/log/netbird/client.log" +command_args="${daemon_args} %%PREFIX%%/bin/netbird service run --config ${netbird_config} --log-level ${netbird_loglevel} --daemon-addr unix://${netbird_socket} --log-file ${netbird_logfile}" +start_precmd="${name}_start_precmd" +stop_postcmd="${name}_stop_postcmd" -run_rc_command "$1" +netbird_start_precmd() { + logger -s -t netbird "Starting ${name}." + # Check for orphaned netbird tunnel interface + # And if it exists, then destroy it + if /sbin/ifconfig ${netbird_tun_dev} >/dev/null 2>&1; then + if ! /sbin/ifconfig ${netbird_tun_dev} | fgrep -qw PID; then + logger -s -t netbird "Found orphaned tunnel interface ${netbird_tun_dev}, destroying" + /sbin/ifconfig ${netbird_tun_dev} destroy + fi + fi +} +netbird_stop_postcmd() { + if /sbin/ifconfig ${netbird_tun_dev} >/dev/null 2>&1; then + logger -s -t netbird "Destroying tunnel interface ${netbird_tun_dev}" + /sbin/ifconfig ${netbird_tun_dev} destroy || \ + logger -s -t netbird "Failed to destroy interface ${netbird_tun_dev}" + fi +} + +run_rc_command "$1" |