View previous topic :: View next topic |
Author |
Message |
DaggyStyle Watchman
Joined: 22 Mar 2006 Posts: 5925
|
Posted: Thu May 26, 2022 5:34 pm Post subject: systemd service that runs a script which reboots at the end |
|
|
Greetings,
I need run a script on boot before network is executed which will block the boot where the last cmd in it is reboot.
the init system is systemd
can it be done? if yes, how?
Thanks _________________ Only two things are infinite, the universe and human stupidity and I'm not sure about the former - Albert Einstein |
|
Back to top |
|
|
alamahant Advocate
Joined: 23 Mar 2019 Posts: 3914
|
Posted: Thu May 26, 2022 5:52 pm Post subject: |
|
|
Hi
Maybe
Code: |
/etc/systemd/system/myservice.service
[Unit]
Description=<>
Before=network.target
After=local-fs.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/myservice
[Install]
WantedBy=multi-user.target
|
and
Code: |
/usr/local/bin/myservice
#!/bin/bash
.
.
.
systemctl isolate reboot.target
|
Then
Code: |
chmod +x /usr/local/bin/myservice
sysyemctl daemon-reload
systemctl enable myservice
|
You have to state some conditions in your script otherwise you might fall in a reboot-loop.Plz first test it with something less dramatic than a reboot. _________________
|
|
Back to top |
|
|
DaggyStyle Watchman
Joined: 22 Mar 2006 Posts: 5925
|
Posted: Thu May 26, 2022 6:39 pm Post subject: |
|
|
thanks, will try _________________ Only two things are infinite, the universe and human stupidity and I'm not sure about the former - Albert Einstein |
|
Back to top |
|
|
|