Skip to content

Instantly share code, notes, and snippets.

@blisabda
Forked from oprypin/instructions.md
Created January 20, 2022 13:10
Show Gist options
  • Save blisabda/ab42ebbd001e63732cafa319dce608e2 to your computer and use it in GitHub Desktop.
Save blisabda/ab42ebbd001e63732cafa319dce608e2 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment