0

I fail to configure my systemd service properly (systemd 249.11-0ubuntu3.12). It should start a tail process which outputs to the console. Ubuntu running as Proxmox VM.

When booting, the service is started but exits without helpful output:

× watchbackup.service - Startup Applications
     Loaded: loaded (/etc/systemd/system/watchbackup.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Fri 2024-03-01 21:47:01 CET; 27s ago
    Process: 939 ExecStart=/opt/backup-proxmox/tools/watchbackup.sh (code=exited, status=1/FAILURE)
   Main PID: 939 (code=exited, status=1/FAILURE)

If I restart the service manually, it works as intended. The execed shell script (I failed miserably to put the tail directly to the service unit file's ExecStart command):

#!/bin/sh
sleep 5
ls -la  /net/var/archiv-1/log/ > /tmp/foo
echo tty1 > /dev/tty1
echo tty0 > /dev/tty0
echo console > /dev/console
tail -f /net/var/archiv-1/log/backup.log 

The sleep succeeds to delay, the file exists as expected (although /net/var/archiv-1 is an NFS mount), all three echoes are visible on the console. However, tail terminates immediately.

My last attempt service unit file looks like this:

[Unit]
Description=Startup Applications
After=network.target
After=net-var-archiv\x2d1.mount
After=net-var-archiv\x2d1.service

[Service]
WorkingDirectory=/opt/backup-proxmox
ExecStart=/opt/backup-proxmox/tools/watchbackup.sh
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Type=simple
StandardOutput=tty
StandardError=tty
TTYPath=/dev/tty1

[Install]
WantedBy=multi-user.target

Any suggestions to identify the reason why I cannot tail the file if the service is started at boot time but I can when restarting the service manually?

2
  • Does the tail work manually? I.e. what happens when you issue tail -f /net/var/archiv-1/log/backup.log in a terminal?
    – eyoung100
    Mar 1 at 22:40
  • @eyoung100: Yes, it works manually. From ssh session or tty1 console, both work as expected and follow the file. When the service is manually restarted right after booting (ssh archiv-1 systemctl restart watchbackup.service), it works as well, the file content is shown on tty1.
    – Twonky
    Mar 1 at 23:00

1 Answer 1

1

Use the Native SystemD Journal

Replace tail with journalctl -f -u watchbackup.service

I can't find out why tail isn't allowed, only the fix. I'll add a more fleshed out answer when I can find why, but I suspect it has something to do with the fact that tail cannot monitor a real time write, and systemd being the init system is running in real-time.

4
  • That's weird. This doesn't work as well, the service terminates as well when using journalctl.
    – Twonky
    Mar 2 at 21:28
  • does journalctl contain any info related to the failure?
    – eyoung100
    Mar 4 at 21:58
  • unfortunately, not anything.
    – Twonky
    Apr 17 at 13:12
  • This may be a stupid question but id the script marked +x
    – eyoung100
    Apr 17 at 16:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .