View previous topic :: View next topic |
Author |
Message |
th_in_gs n00b
Joined: 04 Nov 2023 Posts: 7
|
Posted: Fri Nov 10, 2023 8:32 pm Post subject: Running script, not service, with openrc? |
|
|
I’d like to run a script after mount-ro is completed on shutdown (I’m working on an SBC that has no visible output, so I want to toggle an LED to show when it’s safe to switch off).
If I just put a ‘stop’ script in /etc/local.d I think it’s run too early - before mount-ro is completed.
I feel like to do this properly, I should make a new service in /etc/init.d/ that depends on mount-ro, and then rc-update add led_off shutdown. But I’m confused about how openrc deals with ’services’ that are run-once rather than ongoing daemons. All the docs I can find suggest that /etc/init.d/ items are for starting daemon-like services that are running or not, and openrc should be able to manage start up and shut down independently. But for a script like this, there is no ‘running’ or ‘shutting down’.
Is there a way to tell openrc that my ’service’ is ‘run-once’? Am I overthinking this and it will ‘just work’? I want to ensure I’m doing things the right way... |
|
Back to top |
|
|
NeddySeagoon Administrator
Joined: 05 Jul 2003 Posts: 54327 Location: 56N 3W
|
Posted: Fri Nov 10, 2023 8:54 pm Post subject: |
|
|
th_in_gs,
Why do you care?
After your scrips runs, you will power the SBC off. It's not like you could even cancel the pending shutdown at that stage.
As you say, the local service is first to be shut down, so its too early _________________ Regards,
NeddySeagoon
Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail. |
|
Back to top |
|
|
hdcg Tux's lil' helper
Joined: 07 Apr 2013 Posts: 120
|
Posted: Fri Nov 10, 2023 8:59 pm Post subject: |
|
|
Hi th_in_gs,
simply have a look at the already mentioned
Code: | /etc/init.d/mount-ro |
This is also a run-once service.
Best Regards,
Holger |
|
Back to top |
|
|
th_in_gs n00b
Joined: 04 Nov 2023 Posts: 7
|
Posted: Fri Nov 10, 2023 9:03 pm Post subject: |
|
|
Thanks. Overall point taken (I’ll just write the service script and see how it goes!)
I guess I asked for two reasons:
1) I’m wary of doing something I don’t understand. Like, if I get this wrong is openrc going to do something like loop switching the LED off over and over again because it thinks my service never starts up?
...but you’re right, that wouldn’t be the end of the world. The LED would turn off and I’d still know mount-ro had passed, so in practical terms it’d be serving its purpose fine.
2) I’d just like to understand the general way of doing things like this ‘right’. For example, what would be the right thing to do if I e.g. wanted to run a script (e.g. perhaps to turn on an LED) on after a certain service had started during boot? Things would presumably need to be left in a consistent state then for the system to continue to work properly. |
|
Back to top |
|
|
|
|
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
|
|