- update
yourServiceName
in file name &Description
in unit file with proper information. - add your script to
ExecStart
. for example:ExecStart=/usr/bin/bash -c 'echo "hello world" > /tmp/hello.txt'
- move unit files to
/etc/systemd/system
directory. - apply proper permissions to each file:
chown root:root /etc/systemd/system/yourServiceName-boot.service
chmod 644 /etc/systemd/system/yourServiceName-boot.service
- run:
systemctl daemon-reload
- enable each service:
systemctl enable yourServiceName-boot.service
- start each service:
systemctl start yourServiceName-boot.service
- ready for action 🚀
Last active
November 20, 2021 18:30
-
-
Save matinrco/7142695d01f7854843f8a509c40e744e to your computer and use it in GitHub Desktop.
systemd unit template for oneshot execution after boot/sleep/hibernate/hybridsleep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=your service which do something after boot | |
After=multi-user.target | |
StartLimitBurst=0 | |
[Service] | |
Type=oneshot | |
Restart=on-failure | |
ExecStart=your command or script here | |
[Install] | |
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=your service which do something after hibernation | |
After=hibernate.target | |
StartLimitBurst=0 | |
[Service] | |
Type=oneshot | |
Restart=on-failure | |
ExecStart=your command or script here | |
[Install] | |
WantedBy=hibernate.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=your service which do something after hybridsleep | |
After=hybrid-sleep.target | |
StartLimitBurst=0 | |
[Service] | |
Type=oneshot | |
Restart=on-failure | |
ExecStart=your command or script here | |
[Install] | |
WantedBy=hybrid-sleep.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=your service which do something after sleep | |
After=suspend.target | |
StartLimitBurst=0 | |
[Service] | |
Type=oneshot | |
Restart=on-failure | |
ExecStart=your command or script here | |
[Install] | |
WantedBy=suspend.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=your service which do something after suspendthenhibernate | |
After=suspend-then-hibernate.target | |
StartLimitBurst=0 | |
[Service] | |
Type=oneshot | |
Restart=on-failure | |
ExecStart=your command or script here | |
[Install] | |
WantedBy=suspend-then-hibernate.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment