aboutsummaryrefslogtreecommitdiff
path: root/net/zerotier/files/zerotier.in
blob: 0c2a12a7416d1920e01e40baaf7e78a84c6861eb (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
#!/bin/sh

# $FreeBSD$
#
# PROVIDE: zerotier
# REQUIRE: FILESYSTEMS devfs
# BEFORE:  pf ipfw
# KEYWORD: shutdown
#
# Add these lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# zerotier_enable (bool):	Set to NO by default.
#				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

name=zerotier
rcvar=zerotier_enable
desc="peer-to-peer software-defined networking"

load_rc_config $name

: ${zerotier_enable:=NO}
: ${zerotier_wait_for_net:=NO}

required_modules=%%ZEROTIER_IF_TAP%%

pidfile="/var/run/${name}.pid"
start_precmd="install -o root /dev/null ${pidfile}"

command=/usr/sbin/daemon
command_args=" \
	-c \
	-t ${name} \
	-r \
	-P ${pidfile} \
	%%ZEROTIER_SYSLOG%% \
	%%PREFIX%%/sbin/${name}-one /var/db/${name}-one/"

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"