Skip to content

Instantly share code, notes, and snippets.

@AlexRusbridge
Last active April 23, 2026 15:05
Show Gist options
  • Select an option

  • Save AlexRusbridge/d9b589d47bddc71ced8b8221521fb63d to your computer and use it in GitHub Desktop.

Select an option

Save AlexRusbridge/d9b589d47bddc71ced8b8221521fb63d to your computer and use it in GitHub Desktop.
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.

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.

  1. 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"
  1. Make the rc.d script executable:
chmod +x /usr/local/etc/rc.d/tailscaled_set
  1. Enable tailscaled_set to start on boot
echo 'tailscaled_set_enable="YES"' > /etc/rc.conf.d/tailscaled_set

Note

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment