Unprivileged systemd timers
Unprivileged systemd timers can be used to create periodic tasks, which are active during a user login session.
First, here’s a shell script representing an example task carried out:
#!/usr/bin/env bash
# ~/.local/bin/gio-automount-smb
gio mount smb://haaparousku/home || true
gio mount smb://haaparousku/music || true
It creates GIO (abbreviation for GNOME Input/Output) mounts for couple of SMB shares.
Next the task is wrapped by a service unit in order to make it visible for systemd:
# ~/.config/systemd/user/gio-automount-smb.service
[Unit]
Description=Automount Samba shares with GIO
Wants=gio-automount-smb.timer
[Service]
Type=oneshot
ExecStart=%h/.local/bin/gio-automount-smb
[Install]
WantedBy=default.target
Finally a timer unit is needed, which will start the service periodically:
# ~/.config/systemd/user/gio-automount-smb.timer
[Unit]
Description=Automount Samba shares with GIO
Requires=gio-automount-smb.service
[Timer]
Unit=gio-automount-smb.service
OnCalendar=*-*-* *:0/15:0
[Install]
WantedBy=timers.target
Now that all pieces are together the timer can enabled:
systemctl enable --user gio-automount-smb.timer
systemctl start --user gio-automount-smb.timer # or logout the session
And GIO mounts will get (re-)created every 15 minutes while the user has the login session active.