Skip to content

Instantly share code, notes, and snippets.

@oprypin
Last active April 5, 2025 16:35
Show Gist options
  • Save oprypin/0f0c3479ab53e00988b52919e5d7c144 to your computer and use it in GitHub Desktop.
Save oprypin/0f0c3479ab53e00988b52919e5d7c144 to your computer and use it in GitHub Desktop.
systemd user unit + timer example

Save these files as ~/.config/systemd/user/some-service-name.*

Run this now and after any modifications: systemctl --user daemon-reload

Try out the service (oneshot): systemctl --user start some-service-name

Check logs if something is wrong: journalctl -u --user-unit some-service-name

Start the timer after this user logs in: systemctl --user enable --now some-service-name.timer

[Unit]
Description=Do some thing
After=network.target
[Service]
Type=oneshot
ExecStart=/home/my-user-name/my-service/script.py --some-arg=some-value
[Install]
WantedBy=default.target
[Unit]
Description=Run "Do some thing" every 30 minutes
[Timer]
OnBootSec=3min
OnUnitActiveSec=30min
[Install]
WantedBy=timers.target
@gene1wood
Copy link

Should

  • systemctl --user daemon-reload
  • systemctl --user start some-service-name
  • systemctl --user enable --now some-service-name.timer

be run as root or as the user?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment