Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 200331 - [Feature request] "toggle" option for init.d scripts
Summary: [Feature request] "toggle" option for init.d scripts
Status: RESOLVED WONTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] baselayout (show other bugs)
Hardware: All Linux
: High enhancement (vote)
Assignee: OpenRC Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-25 22:04 UTC by Vlastimil Babka (Caster) (RETIRED)
Modified: 2010-08-05 16:17 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vlastimil Babka (Caster) (RETIRED) gentoo-dev 2007-11-25 22:04:13 UTC
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.
Comment 1 Roy Marples (RETIRED) gentoo-dev 2007-12-03 17:11:13 UTC
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?
Comment 2 Vlastimil Babka (Caster) (RETIRED) gentoo-dev 2007-12-28 20:15:02 UTC
(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...)
Comment 3 Roy Marples 2008-03-18 11:47:16 UTC
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 :)
Comment 4 Doug Goldstein (RETIRED) gentoo-dev 2008-03-31 16:35:47 UTC
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.
Comment 5 Vlastimil Babka (Caster) (RETIRED) gentoo-dev 2008-04-01 05:50:42 UTC
How bout making the /etc/init.d/foo status return a different code for "inactive" than for running/off?
Comment 6 Roy Marples 2008-04-01 06:29:42 UTC
(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.
Comment 7 Vlastimil Babka (Caster) (RETIRED) gentoo-dev 2008-04-01 07:28:18 UTC
Great, I didn't test openrc yet, old baselayout didn't have this :)
Comment 8 William Hubbs gentoo-dev 2010-08-05 16:16:48 UTC
(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