Mail from systemd-timers

If you want to mail the output of a systemd-timer unit by redirecting STDOUT to /usr/bin/mail or something: forget it. For a long time SysAdmin used to good old crond it definitely doesn’t work as expected. As long as you redirect STDOUT in your script or program, you won’t get any output, because systemd redirects STDOUT to the journal by default. It’s documented behavior, you just have to read the fine print in man systemd.exec (StandardOutput=).

It’s rather counter-intuitive and has been discussed on systemd-devel, but in the end it’s “the right thing” ® to do. Systemd PID 1 should not care nor can it know where STDOUT is currently connected to.

So, how to work around it? Most likely your timer-thingy is a script wrapped in a service unit with Type=oneshot and ExecStart=/my/script. If so, just create a helper script that mails the output of journalctl -u <unit> –since today or something. Just don’t read the output of journalctl via a pipe!

My solution is a little perl script: mail-unit.pl

Just add StartExec=mail-unit.pl <my unit name> after your actual script.

Restore files from obnam

Well, well, well… Seems I just fucked up:

  1.  I should have remembered that tc can only control outoging traffic. So changing /etc/network-scripts/tc.sh for incoming rates was just stupid.
  2. I wrote the file to disk without keeping the original, working lines commented out.
  3. I didn’t remember the proper bandwidth values.

Fortunately, I keep an obnam-backup. To recover files from e.g. /etc, do the following:

# mount /dev/mapper/obnam-c /mnt/backup-obnam/
# obnam restore --to=/tmp/restore\
 --config=/home/am/.config/obnam/etc.conf

That restores all of /etc to /tmp/restore. Add a file or directory the end to only restore that file or directory, or leave out –to to restore in place.

Do not forget to umount /mnt/backup-obnam afterwards!

Another thing: If obnam complains about locking errors, do the following:

# mount /dev/mapper/obnam-c /mnt/backup-obnam/
# cd .config/obnam
# for i in *.conf ; do obnam force-lock --config $i ; echo $i ; done

Shit gebeurt 🙁