0

I have unison running under systemd to keep my local and remote NASs in sync.
The systemd config is thus:

[Unit]
Description=NAS Unision service
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=1
User=nas
ExecStart=/usr/bin/unison borg

[Install]
WantedBy=multi-user.target

And in ~nas/.unison/borg.prf I have configure unison to run with:

# Keep repeating every 15 mins.
repeat=900

# Log to the file which will be rotated by logrotate.
log=true
logfile=/var/log/unison-borg.log

logrotate is configure to rotate the log once per day:

# Rotation of the Unision logs
/var/log/unison-borg.log {
    dayly
    rotate 7
    compress
    delaycompress
    missingok
    notifempty
    create 644 nas nas
}

My issue is that unison doesn't appear to open the log file with each repeat and thus when logrotate rotates the log file unsion-borg.log.1 gets the updates.

The man file for unison states that "Sending SIGUSR1 will close the logfile; the logfile will be re-opened (and created, if needed) automatically, to allow for log rotation."

How should I do this in systemd?

1
  • Why is it important to do it in systemd? Why not in logrotate? Oct 26, 2023 at 4:15

1 Answer 1

0

Create the script /etc/logrotate.post.daily:

#!/bin.sh
systemctl status nas-borg | awk '/Main PID/{ print "kill -10 " $3 }' | sh

And modify the logroate.conf task to add the postrotate option:

/var/log/unison-borg.log {
    ...
    postrotate /etc/logrotate.post.daily
}
1
  • That seems like a long-winded way of doing systemctl kill nas-borg
    – muru
    Oct 27, 2023 at 1:42

You must log in to answer this question.

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