User-level systemd services

Goal: Launching mbsync as a user using systemd and in a cron-like manner.

For this a systemd timer will launch a systemd service.

1
2
mkdir -p ~/.config/systemd/user
vim ~/.config/systemd/user/mbsync.service
1
2
3
4
5
6
7
8
9
10
11
# mbsync.service
[Unit]
Description=Mailbox synchronization service
After=network.target network-online.target dbus.socket
[Service]
Type=oneshot
ExecStart=/usr/bin/mbsync -Va
ExecStartPost=/usr/bin/notmuch new
StandardOutput=syslog
StandardError=syslog

vim ~/.config/systemd/user/mbsync.timer

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# mbsync.timer
[Unit]
Description=MBSync Quicksync timer
[Timer]
# Check systemd.time(7)
# Time to wait after booting before offlineimap.service is run for the first time
OnBootSec=15min
# Every 30 seconds
# OnCalendar=*:*:0/30
#OnCalendar=*-*-* *:0/2:00
#OnCalendar=hourly
#OnCalendar=minutely
# run 1 minutes after each deactivation of the unit
OnUnitInactiveSec=60s
Unit=mbsync.service
[Install]
WantedBy=default.target
1
2
3
4
5
6
7
# Take new service into account
systemctl --user daemon-reload
# Enable and start service
systemctl --user enable --now mbsync.timer
# Check service status
systemctl --user status -l mbsync.timer
systemctl --user status -l mbsync.service