Hello, I’m having trouble with automating my osync-batch via systemd.service.
I have configured osync for bidirectional synchronization of local folders on my harddisk and my NAS. Both source and target are mounted on boot - the local folder is a veracrypt partition and the NAS is connected via cifs. Manually I can synchronize each folder or all in one batch (although I have to sudo it). So I expect I configured osync correctly and my problem is systemd. This is the command I’m executing:
sudo bash osync-batch.sh --path=/home/USERNAME/osync --max-exec-time=300
Now I’m trying to automate this: It should synchronize the folders after login and then every X minutes (5 - 30 min, I’m not sure yet), maybe later I want to implement the monitoring. I created a systemd.service and timer as --user. This is executed but fails if there are files to synchronize - therefor fails the task.
This is my systemd.service: /etc/systemd/user/osync-login.service
[Unit]
Description=Sync files between NAS and local disk after login
[Service]
Type=oneshot
ExecStart=/home/USERNAME/osync/osync-batch.sh --path=/home/USERNAME/osync --max-exec-time=600
EDIT: Running in bash does not solve the problem:
ExecStart=/bin/bash -c '/home/carsten/osync/osync-batch.sh --path=/home/carsten/osync --max-exec-time=600'
This is the systemd.timer: /etc/systemd/user/osync-login.timer
[Unit]
Description=Sync files between NAS and local disk three minutes after boot and every 5 minutes
[Timer]
OnBootSec=3min
OnCalendar=*:0/5
Persistent=true
[Install]
WantedBy=timers.target
This is the error message generated by systemctl status:
Instance sync_verwaltung_USERNAME.conf failed with exit code [1].
systemd[1677]: osync-login.service: Main process exited, code=exited, status=1/FAILURE
systemd[1677]: osync-login.service: Failed with result 'exit-code'.
systemd[1677]: Failed to start Sync files between NAS and local disk after login.
systemd[1677]: osync-login.service: Consumed 28.341s CPU time, 47.3M memory peak, 0B memory swap peak.
What did I do wrong? How can I get information about the error? I thought the manual execution with sudo is no problem because the systemd.service runs automatically as root. But when I tried to write this in the service-file (User=root, Group=root), there was also an error (changing group policies failed).