You are not logged in.
I'd like to have systemd run a scp command when the headless system boots and again when it reboots or is shutdown.
The user service I created errors out but I am unclear why. Thoughts are appreciated.
~/.config/systemd/user/foo.service
[Unit]
Description=foo
After=network-online.target
Wants=network-online.target
Before=shutdown.target reboot.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/scp -q /var/log/my.log me@server:/home/me/remote.log
ExecStop=/usr/bin/scp -q /var/log/my.log me@server:/home/me/remote.log
[Install]
WantedBy=default.targetOn a fresh boot:
% systemctl --user status foo
● foo.service - foo
Loaded: loaded (/home/facade/.config/systemd/user/foo.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2019-09-17 10:11:21 EDT; 21s ago
Process: 325 ExecStart=/usr/bin/scp -q /var/log/my.log me@server:/home/me/remote.log (code=exited, status=1/FAILURE)
Main PID: 325 (code=exited, status=1/FAILURE)
Sep 17 10:11:20 aroom systemd[318]: Starting foo...
Sep 17 10:11:21 aroom scp[325]: lost connection
Sep 17 10:11:21 aroom systemd[318]: foo.service: Main process exited, code=exited, status=1/FAILURE
Sep 17 10:11:21 aroom systemd[318]: foo.service: Failed with result 'exit-code'.
Sep 17 10:11:21 aroom systemd[318]: Failed to start foo.I am wondering if the network is not up when it tries to execute despite the network-online.target.
EDIT: See https://www.freedesktop.org/wiki/Softwa … orkTarget/
The problem was that systemd-networkd-wait-online.service was not enabled. Re-enabling systemd-networkd did it for me and now foo works as expected.
sudo systemctl enable systemd-networkd
Created symlink /etc/systemd/system/dbus-org.freedesktop.network1.service → /usr/lib/systemd/system/systemd-networkd.service.
Created symlink /etc/systemd/system/network-online.target.wants/systemd-networkd-wait-online.service → /usr/lib/systemd/system/systemd-networkd-wait-online.service<frustrated comment>
Systemd can be a quirky thing... why wasn't the wait-online service enabled the first time systemd-networkd was enabled originally years ago when this box was built (bug maybe or version differences)
</frustrated comment>
Last edited by graysky (2019-09-17 14:25:04)
Offline