I have a laptop with soft wifi button which sends events captured by acpid and I use it to toggle the net.wlan0 service. Currently I have to make script like this: if /etc/init.d/net.wlan0 status --quiet; then /etc/init.d/net.wlan0 stop else /etc/init.d/net.wlan0 start fi I thought that it would be neat if the init scripts supported some "toggle" option which would do exactly this, without the need to hack extra scripts.
What behaviour would you expect if you did "/etc/init.d/foo toggle" and the service was in a non start/stopped state such as starting, stopping or inactive? Error or just try it anyway?
(In reply to comment #1) > What behaviour would you expect if you did "/etc/init.d/foo toggle" and the > service was in a non start/stopped state such as starting, stopping or > inactive? Error or just try it anyway? starting -> stop stopping -> restart (if possible, otherwise just let it finish stopping) inactive -> stop (assuming from the network scripts, inactive is like started but for example cable not plugged...)
I've been thinking about this on and off, and I just don't like it. Say you have a switch - on and off. You flip the switch to off, so the service stops. Something else then starts the service and you flip your switch again. Now it's off due to the toggle, but you would expect it to be on. So no, I won't do it :)
I agree with Roy on this one. I won't be patching OpenRC to support this. Mike I'll leave this one up to you.
How bout making the /etc/init.d/foo status return a different code for "inactive" than for running/off?
(In reply to comment #5) > How bout making the /etc/init.d/foo status return a different code for > "inactive" than for running/off? It does :) Look at /usr/include/rc.h for a list of all the state codes. The return code for status is the same as these, with the exception of started being 0.
Great, I didn't test openrc yet, old baselayout didn't have this :)
(In reply to comment #3) > I've been thinking about this on and off, and I just don't like it. > Say you have a switch - on and off. You flip the switch to off, so the service > stops. Something else then starts the service and you flip your switch again. > Now it's off due to the toggle, but you would expect it to be on. > So no, I won't do it :) (In reply to comment #4) > I agree with Roy on this one. I won't be patching OpenRC to support this. Mike > I'll leave this one up to you. I am also in agreement with the two above comments, so I am closing this as wontfix. Mike, feel free to re-open if you disagree. William