User-level systemd services

Recovered 2026-07-13 from the generated HTML preserved in the blog-old repository (master branch) — the markdown source of the short-lived October 2017 blog incarnation was never committed. Original publication: 2017-10-10.

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

For this a systemd timer will launch a systemd service.

mkdir -p ~/.config/systemd/user
vim ~/.config/systemd/user/mbsync.service
# 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

# 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
# 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