I have bind sshd to the zerotier-one ip address.
That works.
After reboot, sshd dies because it cannot bind to zerotier-one interface.
Tried adding zerotie-one.service to After, Wants and Requires in systemd
But still does not work.
How to make sshd to startup only after zerotier-one has started up and got an ip address?
hmm… How about from the other side? Add in sshd.service: RequiredBy=, or Before=/After=. Or, create a .target unit to manipulate service launch at your will.
Off the top of my head, maybe a launch a .timer unit as part of ZeroTier’s (so you know ZT has started) that waits just a little bit after (OnActiveSec=##) starting to restart sshd…or maybe reset the failed unit, depending on the error given when it died.
Did the following and it seems to work. May not be perfect so please continue to advice.
Here is the systemd startup for zerotier.
[Unit]
Description=ZeroTier One
After=network-online.target network.target
Wants=network-online.target
[Service]
ExecStart=/usr/sbin/zerotier-one
Restart=always
KillMode=process
ExecStartPost=/usr/bin/sleep 30 #<-- added this to make 30sec delay
ExecStartPost=-/root/scripts/zerotier/restart_ssh #<-- this is the script that does the work.
# Please note the "-" at the start
# so the systemctl will continue even with a fail
[Install]
WantedBy=multi-user.target
Here is the script.
#!/usr/bin/bash
#script to restart ssh if ssh is failed
/usr/bin/systemctl is-failed --quiet ssh.service && /usr/bin/systemctl restart ssh.service
/usr/bin/systemctl is-failed --quiet dovecot.service && /usr/bin/systemctl restart dovecot.service
/usr/bin/systemctl restart postfix.service
# strange for me. Even the dovecot and postfix needs to be restarted
# might be because of the zerotier affects the network.