A FreeBSD rc.d script for OPNsense that runs tailscale set after tailscaled has started. Polls until the Tailscale daemon is ready (up to 30 seconds) before applying configuration, ensuring the command doesn't fail due to a race condition on boot.
- Create a new file
/usr/local/etc/rc.d/tailscaled_set
#!/bin/sh
# PROVIDE: tailscaled_set
# REQUIRE: tailscaled
. /etc/rc.subr
name="tailscaled_set"
rcvar="${name}_enable"
start_cmd="${name}_start"
stop_cmd=":"
tailscaled_set_start()
{
local i=0
while ! /usr/local/bin/tailscale status > /dev/null 2>&1; do
sleep 1
i=$((i + 1))
[ $i -ge 30 ] && echo "tailscaled never became ready" && return 1
done
/usr/local/bin/tailscale set --relay-server-port=40000
}
load_rc_config $name
: ${tailscaled_set_enable:=yes}
run_rc_command "$1"- Make the rc.d script executable:
chmod +x /usr/local/etc/rc.d/tailscaled_set- Enable
tailscaled_setto start on boot
echo 'tailscaled_set_enable="YES"' > /etc/rc.conf.d/tailscaled_setNote
Running service tailscaled_set enable will also enable the service, but it will write the config to /etc/rc.conf by default.
Creating the file manually in /etc/rc.conf.d/ keeps it alongside the tailscaled config, which is cleaner and more consistent with how OPNsense organises its rc configuration.