Changeset View
Changeset View
Standalone View
Standalone View
head/net/zerotier/files/zerotier.in
#!/bin/sh | #!/bin/sh | ||||
# $FreeBSD$ | # $FreeBSD$ | ||||
# | # | ||||
# PROVIDE: zerotier | # PROVIDE: zerotier | ||||
# REQUIRE: FILESYSTEMS devfs | # REQUIRE: FILESYSTEMS devfs | ||||
# BEFORE: pf ipfw | # BEFORE: pf ipfw | ||||
# KEYWORD: shutdown | # KEYWORD: shutdown | ||||
# | # | ||||
# Add these lines to /etc/rc.conf.local or /etc/rc.conf | # Add these lines to /etc/rc.conf.local or /etc/rc.conf | ||||
# to enable this service: | # to enable this service: | ||||
# | # | ||||
# zerotier_enable (bool): Set to NO by default. | # zerotier_enable (bool): Set to NO by default. | ||||
# Set it to YES to enable zerotier. | # Set it to YES to enable zerotier. | ||||
# zerotier_wait_for_net (bool): Set to NO by default. Use for DHCP interfaces only | |||||
# Set it to YES to require zerotier to wait until online | |||||
. /etc/rc.subr | . /etc/rc.subr | ||||
name=zerotier | name=zerotier | ||||
rcvar=zerotier_enable | rcvar=zerotier_enable | ||||
desc="peer-to-peer software-defined networking" | |||||
load_rc_config $name | load_rc_config $name | ||||
: ${zerotier_enable:="NO"} | : ${zerotier_enable:=NO} | ||||
: ${zerotier_wait_for_net:=NO} | |||||
required_modules="if_tap" | required_modules=%%ZEROTIER_IF_TAP%% | ||||
pidfile="/var/run/${name}.pid" | pidfile="/var/run/${name}.pid" | ||||
start_precmd="install -o root /dev/null ${pidfile}" | start_precmd="install -o root /dev/null ${pidfile}" | ||||
command="/usr/sbin/daemon" | command=/usr/sbin/daemon | ||||
command_args=" \ | command_args=" \ | ||||
-c \ | -c \ | ||||
-t ${name} \ | -t ${name} \ | ||||
-r \ | -r \ | ||||
-P ${pidfile} \ | -P ${pidfile} \ | ||||
%%ZEROTIER_SYSLOG%% \ | %%ZEROTIER_SYSLOG%% \ | ||||
/usr/local/sbin/${name}-one" | %%PREFIX%%/sbin/${name}-one /var/db/${name}-one/" | ||||
run_rc_command "$1" | start_postcmd=start_postcmd | ||||
start_postcmd() | |||||
{ if checkyesno zerotier_wait_for_net; then | |||||
zerotier_count=5 | |||||
until %%PREFIX%%/bin/zerotier-cli status |egrep -o ONLINE\$; do | |||||
warn ${name} is waiting for ONLINE status | |||||
sleep 2 | |||||
zerotier_count=$((zerotier_count-1)) | |||||
test $zerotier_count -le 0 && break | |||||
done | |||||
if test $zerotier_count -le 0; then | |||||
warn ${name} still not ONLINE, stopped blocking | |||||
else | |||||
warn ${name} is ONLINE | |||||
fi | |||||
fi | |||||
} | |||||
run_rc_command "$1" |