Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
systemd service that runs a script which reboots at the end
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
DaggyStyle
Watchman
Watchman


Joined: 22 Mar 2006
Posts: 5910

PostPosted: Thu May 26, 2022 5:34 pm    Post subject: systemd service that runs a script which reboots at the end Reply with quote

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
View user's profile Send private message
alamahant
Advocate
Advocate


Joined: 23 Mar 2019
Posts: 3879

PostPosted: Thu May 26, 2022 5:52 pm    Post subject: Reply with quote

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
View user's profile Send private message
DaggyStyle
Watchman
Watchman


Joined: 22 Mar 2006
Posts: 5910

PostPosted: Thu May 26, 2022 6:39 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum