FreeNAS & Zerotier: Persist or Die

++++++++++++++++++++++++++++++++

MISSION: Making Zerotier persist across reboots in FreeNAS

Step 1: Run Zerotier & Join a Network
Either run zerotier-cli & get the system ID to add to your zerotier network, manually; OR, use a script (EXAMPLE: Use PTS stand-up zt script) to automate joining your network.

Better than chocolate & peanut butter!

Let’s go ahead and enable the ZeroTier service in the rc.conf file that FreeNAS uses at boot-time.

sysrc -f /conf/base/etc/rc.conf zerotier_enable=”YES”

(OR, the real down and dirty, need it right now:

[root@freenas ~]# echo ‘zerotier_enable=”YES”‘ | tee -a /etc/rc.conf

rysnc -avhP /conf/base/etc/rc.conf /etc/

And Then

Then we start zt …

service zerotier start

OR

/usr/local/etc/rc.d/zerotier start

And THEN?

… ummm…and then join our ZT network

zerotier-cli join YOUR_NETWORK_ID

OR

Go approve it in the webUI, or conversely, you can grab the node_ID either manually or via a script and add the system to the network

zerotier-cli info | awk ‘{ print $3 }’

which will output something like:

c301b2efc

NOTE TO SELF: Reference script for zt auto-assignment

Ah, yes…I’ve got some automation scripts that I’ve already done awhile back to assign a zerotier network/IP to a newly minted system upon vm/sytem installation/creation. Ironically, my home FreeNAS is down atm, so I’ll have to pull it from a backup for Part II 😉

ANND THENNNN…..

NO AND THEN!!

However you got’r dun, now that we’ve SUCCESSFULLY JOINED A ZT NETWORK,
we can

Step 2: Copy the Zerotier Data to the FreeNAS boot-device/dataset
If you’ve got zerotier running, you’re halfway there. The only challenge now would be on a reboot, it all goes away, as the configuration is dynamically generated at runtime/reboot. because it’s an appliance, isn’t that so?

That’s why we’ll go ahead and proceed to the next step …

Step 3: Configure the Zerotier Setup to Persist Across Reboots
Go ahead and copy the zerotier info in /var/db BACK OVER TO the FreeNAS boot-device, where we’ll reference it in a post-init boot script from the FreeNAS UI.

rsync -avhP /var/db/zerotier-one /conf/base/var/db/

AND THEN AND THEN AND THEN AND THEN?

We can add our post-init command in the FreeNAS UI.
Just click Tasks->Init/Shutown Scripts & Add
For the command, we’ll select post-init for the WHEN and put the following in the “command to run” field.

service zerotier start

Some postinit commands that are entered via the FreeNAS UI

Test with a REBOOT, if possible, to make sure everything works as expected!

TODO:
While this wil work in a pinch, and get you through a reboot, it’s not robust and will not survive and upgrade. No worries, I’ve already got it done.

But really, it seems that it’s time to make Zerotier a First Class FreeNAS Citizen, don’t you think?