Skip to main content
Topic: [SOLVED] Put runit service down after it executes once (Read 437 times) previous topic - next topic
0 Members and 2 Guests are viewing this topic.

[SOLVED] Put runit service down after it executes once

I made runit service:
unblock_wifi
Quote
#!/bin/sh
exec rfkill unblock wifi
exec sv down unblock_wifi

It works. But last line seems not right.
Isn't unblock_wifi/once suppose to do the same?

The main goal is to link airplane button to
Quote
rfkill toggle wifi
But without previously putting service down rfkill toggle wifi doesn't work.
unblock_wifi service unblocks wifi again. Despite its status is down.


Re: Put runit service down after it executes once

Reply #2
Thanks, it works.

Would be better if you  can set airplane button to restore previous state. Now the only option is enable everything.

Re: [SOLVED] Put runit service down after it executes once

Reply #3
If you run help exec on a shell, you'll find out what's the problem:

Code: [Select]
exec: exec [-cl] [-a name] [command [argument ...]] [redirection ...]
    Replace the shell with the given command.

So the script stops as soon as rfkill unblock wifi is spawned. Rfkill then exits after unblocking wifi, but the shell isn't there anymore to read sv down unblock_wifi. Since runit always restarts the service after the process it's monitoring exits, the script is spawned again, and the cycle repeats.

You'd want to write it like this:

Code: [Select]
#!/bin/sh
rfkill unblock wifi
# pause literally does nothing, it doesn't even exit.
# It's there so runit doesn't start the service again.
exec pause