You are not logged in.
Hi,
I need some help, how to start autossh via systemd. Manually started my autossh systemd service is running without problems. But started via systemd while booting, autossh tries to start before dhcp is ready. As result the start of autossh failed, because the network is not ready.
What I did
1. activate autostart for dhcp long time ago: systemctl enable dhcpcd@eth0 (source: https://wiki.archlinux.de/title/DHCP)
2. install autossh: pacman -S autossh
3. create systemd service (source https://blog.philippklaus.de/2013/03/st … rch-linux)
[Unit]
Description=AutoSSH service for a reverse tunnel from some.example.com to localhost
After=network.target
[Service]
ExecStart=/usr/bin/autossh -M 0 -q -N -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" someuser@some.example.com -R 1250:localhost:8080
[Install]
WantedBy=multi-user.target4. test systemd service: systemctl daemon-reload; systemctl restart autossh.service; systemctl status autossh.service
5. reboot system
6. check systemd log: journalctl -b
Jan 30 22:58:40 tux sshd[417]: Server listening on 0.0.0.0 port 22.
Jan 30 22:58:40 tux sshd[417]: Server listening on :: port 22.
Jan 30 22:58:40 tux autossh[419]: port set to 0, monitoring disabled
Jan 30 22:58:40 tux autossh[419]: starting ssh (count 1)
Jan 30 22:58:40 tux autossh[419]: ssh child pid is 422
(...)
Jan 30 22:58:40 tux autossh[419]: ssh exited prematurely with status 255; autossh exiting
(...)
Jan 30 22:58:44 tux dhcpcd[415]: eno1: leased 192.168.0.4 for 3600 seconds
Jan 30 22:58:44 tux dhcpcd[415]: eno1: adding route to 192.168.0.0/24
Jan 30 22:58:44 tux dhcpcd[415]: eno1: adding default route via 192.168.0.1What I allready tried:
- change systemd service line "After=network.target" to "After=network-online.target" without success
- add systemd service line "After=dhcpcd@eno1"
Who can help? How could I manage it, that autossh is starting after dhcp?
Thanks
Martin
Offline
NetworkTarget network-online.target would work if the dhcpcd service supported it.
For the same reason After=dhcpcd@eno1 fails as the service has started successfully so the condition is met but no address has yet been obtained.
Edit:
Oh and welcome to the arch linux forums pichlo.
Last edited by loqs (2018-01-30 23:28:25)
Offline
Hi loqs
I changed the "after" statement as follows:
After=network.target network-online.targetUnfortunately there is no change while booting
Jan 31 08:30:34 tux autossh[399]: port set to 0, monitoring disabled
Jan 31 08:30:34 tux autossh[399]: starting ssh (count 1)
Jan 31 08:30:34 tux autossh[399]: ssh child pid is 403
Jan 31 08:30:34 tux systemd[1]: Started Permit User Sessions.
Jan 31 08:30:34 tux systemd[1]: Started Getty on tty1.
Jan 31 08:30:34 tux sshd[402]: Server listening on 0.0.0.0 port 22.
Jan 31 08:30:34 tux systemd[1]: Reached target Login Prompts.
Jan 31 08:30:34 tux sshd[402]: Server listening on :: port 22.
(...)
Jan 31 08:30:34 tux autossh[399]: ssh exited prematurely with status 255; autossh exiting
(...)
Jan 31 08:30:38 tux dhcpcd[397]: eno1: leased 192.168.0.4 for 3600 seconds
Jan 31 08:30:38 tux dhcpcd[397]: eno1: adding route to 192.168.0.0/24
Jan 31 08:30:38 tux dhcpcd[397]: eno1: adding default route via 192.168.0.1
Jan 31 08:30:45 tux sshd[602]: Accepted publickey for root from 192.168.0.61 port 49429 ssh2: RSA SHA256:DhnDdi++eESNIXmii+Hd0iqA7mj7nuVbihaAmDWSZswDo you have more ideas? How could I find out if dhcpcd supports the mentioned targets? Should I may change the dhcp service?
Thanks
Martin
Offline
network-online.target would work if the dhcpcd service supported it
"subjunctive" - it doesn't.
You'll have to add some network helper, like
while ! ping -c1 some.example.com > /dev/null 2>&1; do sleep 1; doneor some such.
Offline
This would mean that "network-online.target" is not working on my system in general, right?
Is this a known problem with dhcpcd or do I need to check my system setup?
Is there any other service available for starting dhcp at boottime, which support "network-online.target"?
PS Thanks for the workarround. I will try if it works.
Last edited by pichlo (2018-01-31 10:24:24)
Offline
You can also try to make network.target activate only after dhcpcd (NetworkManager and systemd-netword already support this using a service file)
This should give you some information on how that works: https://www.freedesktop.org/wiki/Softwa … orkTarget/
EDIT: such a service is already part of dhcpcd-ui apparently: https://github.com/rsmarples/dhcpcd-ui/ … service.in
You could probably just grab that one.
EDIT2: Or, along the lines of seth's suggestion for a network helper, use ExecStartPre to delay until ping succeeds:
ExecStartPre=/bin/sh -c 'until ping -c1 example.com; do sleep 1; done;'Last edited by Omar007 (2018-01-31 12:06:07)
Offline
I'd not bother with all of the above acrobatics; just add `Restart=on-failure` and `RestartSec=5` to the autossh service file.
Why run ping until ping connects and then run autossh. Just run autossh until autossh connects.
Last edited by Trilby (2018-01-31 12:08:37)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Thanks for all the responses. I will test it as soon as possible.
Meanwhile a DHCP question regarding this article: https://www.freedesktop.org/wiki/Softwa … orkTarget/
If you use NetworkManager you can do this by enabling NetworkManager-wait-online.service:
# systemctl enable NetworkManager-wait-online.service
If you use systemd-networkd you can do this by enabling systemd-networkd-wait-online.service:
# systemctl enable systemd-networkd-wait-online.serviceWhich case I am using, when my dhcp is starting as follows?
systemctl enable dhcpcd@en0Do you have some articles regarding both cases?
Thanks
Martin
Offline
You're using dhcpcd directly, so neither of them. Personally I'd switch to using systemd-networkd, but that's just because it's my preferred solution that I use on all of my machines.
Offline
Thanks for all of your responses. I finally switched the dhcp management to systemd-networkd, now network-online.target works.
Offline
Glad you got it sorted. Please remember to mark this thread [SOLVED].
CoC - How to post
Offline