This is the first time that I have to mess around with systemd. I can't find a solution how to manage, that my service starts after the network is up.
I try to start
knockd.service on startup on my Raspbian system.
After Boot I check if the service is running:
systemctl status knockd
Loaded: loaded (/lib/systemd/system/knockd.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Thu 2019-06-27 14:36:26 CEST; 7min ago Docs: man:knockd(1) Process: 516 ExecStart=/usr/sbin/knockd $KNOCKD_OPTS (code=exited, status=1/FAILURE) Main PID: 516 (code=exited, status=1/FAILURE) Jun 27 14:36:26 pins2 systemd: Started Port-Knock Daemon. Jun 27 14:36:26 pins2 knockd: could not get IP address for eth0 Jun 27 14:36:26 pins2 systemd: knockd.service: Main process exited, code=exited, status=1/FAILURE Jun 27 14:36:26 pins2 systemd: knockd.service: Unit entered failed state. Jun 27 14:36:26 pins2 systemd: knockd.service: Failed with result 'exit-code'.
I think the Problem is this:
could not get IP address for eth0
systemctl cat knockd
# /lib/systemd/system/knockd.service [Unit] Description=Port-Knock Daemon Documentation=man:knockd(1) #Requires=network-online.target #Wants=network-online.target After=network-online.target [Service] EnvironmentFile=-/etc/default/knockd ExecStart=/usr/sbin/knockd $KNOCKD_OPTS ExecReload=/bin/kill -HUP $MAINPID KillMode=mixed SuccessExitStatus=0 2 15 ProtectSystem=full CapabilityBoundingSet=CAP_NET_RAW CAP_NET_ADMIN [Install] WantedBy=multi-user.target Alias=knockd.service
I already use
After=network-online.target in my Unit section. What else do I have to do, I already tried
After Boot my system has an IP Address, and starting the Service manually works without any problems. On another network with some faster network I did not have any Problems even without the
As you can imagine it is quite essential, that knockd starts reliably, because if not, I am locked out.
If this works reliably, will this also work, if the network cable is connected some time after boot?
BTW, I know that I should not edit the
.service file in
/lib/systemd/... I just did that to sort out possible override problems. I will fix that after everything is working. Thank you for your help.