Skip to content

jwillikers/tailscale-online-target

Repository files navigation

Tailscale Online Target

The Tailscale Online Target is a systemd network-online.target for Tailscale. This makes it possible to add systemd dependencies on the Tailscale network. This is based off of the post Mount share only if connected to Tailscale from the Tailscale Forum. I’ve ported over the script to use Nushell and made it possible to add dependencies on specific devices being available on the Tailscale network.

Install

These are the steps to install Tailscale, Nushell, and the Tailscale Online Target. These instructions are intended for Debian and Fedora Atomic systems.

  1. Install just by following the instructions in the installation section.

  2. Clone the repository.

    git clone https://github.com/jwillikers/tailscale-online-target.git
  3. Change to the repository’s directory.

    cd tailscale-online-target
  4. Install everything by running just install.

    just install
  5. Bring Tailscale online. I use an exit node to route all traffic through Tailscale. Modify or omit the --exit-node flag as necessary.

    sudo tailscale up --exit-node=fd7a:115c:a1e0:ab12:4843:cd96:625f:e80c
  6. Start the desired system timers. Here I start the global timer as well as a timer for a specific instance.

    System
    sudo systemctl enable --now tailscale-dispatcher.timer tailscale-dispatcher@meerkat.timer
    User
    systemctl --user enable --now tailscale-dispatcher.timer tailscale-dispatcher@meerkat.timer
  7. Add a dependency on the specific tailscale-online.target as necessary for any systemd units.

Dependent Filesystems

Adding a dependency for filesystems is a bit more complicated than a regular systemd unit. The instructions here describe how to do add a dependency on the Tailscale Online Target for a filesystem, such as an NFS mount.

fstab

In /etc/fstab, use the x-systemd.requires mount option to specify the dependency as in the following example.

/etc/fstab
nfs.jwillikers.io:/container-volumes /var/home/core/container-volumes nfs defaults,_netdev,context="system_u:object_r:container_file_t:s0",noatime,nodev,noexec,nofail,nosuid,soft,user,x-systemd.automount,x-systemd.idle-timeout=5min,x-systemd.mount-timeout=30s,x-systemd.requires=tailscale-online@rockpro64.target 0 0
mount units

Add the dependency manually to systemd mount and automount units.

sudo systemctl edit var-home-core-Media.mount
/etc/systemd/system/var-home-core-Media.mount.d/override.conf
[Unit]
After=tailscale-online@rockpro64.target
Requires=tailscale-online@rockpro64.target
sudo systemctl edit var-home-core-Media.automount
/etc/systemd/system/var-home-core-Media.automount.d/override.conf
[Unit]
After=tailscale-online@rockpro64.target
Requires=tailscale-online@rockpro64.target

Code of Conduct

The project’s Code of Conduct is available in the Code of Conduct file.

License

This repository is licensed under the GPLv3. Please refer to the bundled license.

© 2024 Jordan Williams

Authors

About

A systemd network-online.target for Tailscale

Topics

Resources

License

Stars

Watchers

Forks