Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 139919 - Defining RC-services that schedule other services to start later should be more flexible
Summary: Defining RC-services that schedule other services to start later should be mo...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] baselayout (show other bugs)
Hardware: All Linux
: High enhancement
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-10 13:44 UTC by Antti Mäkelä
Modified: 2006-08-25 03:26 UTC (History)
1 user (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 Antti Mäkelä 2006-07-10 13:44:23 UTC
With multiple network interfaces, the rc-scripts system takes into account only the ones defined in runlevels when scheduling services to start. 

The wireless LAN stuff described below apply to me personally, but I would think that at least the PPP link would be a bigger problem and be of interest to others as well..

My computer has wired and wireless interfaces. I start up the LAN interface at boot and have set it to runlevel default. I do not start my wireless LAN interface at boot, because I don't want to have my laptop shouting for network, for example in situations where I know that there is no wireless network around.  I therefore load my ipw2200 module with rf_kill parameter. 

This issue also applies to a ppp0 interface that comes up when I connect my mobile phone via bluetooth. The interface does not even exist at boot time, however, it will come up as soon as I dial up to my ISP.

I have defined a hotkey (actually an ACPI action based on ibm_acpi) to start up the wireless LAN interface by pressing a key (fn-f5):

Upon boot, I get the following notices.

* WARNING: ntp is scheduled to start when net.lan has started.
* WARNING: sshd is scheduled to start when net.lan has started.

The rc-scripts are blissfully unaware of my wlan and ppp interfaces that will potentially be activated later. 

Even if I could activate the interfaces at boot time there is still the issue that I would like the system to activate ntpd if lan,wlan or ppp is up, but sshd would only be up when connected to wired lan (and even there, only when docked - I'm using the dock detection from http://forums.gentoo.org/viewtopic-t-433637.html). Other services that could probably be interface-specific could be NFS, Samba, xinetd and so on.

One solution I thought about - For wireless LAN I have defined a script for ACPI hotkey action (pressing an fn-button) that toggles the WLAN interface state.

#!/bin/sh
if iwconfig wlan | grep "radio off" > /dev/null ; then
  echo 0 > /sys/class/net/wlan/device/rf_kill
  /etc/init.d/net.wlan start > /dev/null &
else
  /etc/init.d/net.wlan stop > /dev/null &
  echo 1 > /sys/class/net/wlan/device/rf_kill
fi

I suppose I could add a logic in there, basically inserting /etc/init.d/ntpd start after /etc/net.wlan start. However, when bringing wlan down I would have to include a test to bring ntpd down only if no other interface is up. And where to get the states of the other interfaces "the standard way"?

(Incidentally, does resolvconf-gentoo handle NTP besides DNS?).

Anyway, my suggestion is

  add a POTENTIAL_NETWORK_INTERFACES parameter to /etc/conf.d/rc that allows the user to specify the network interfaces that could potentially be activated by user at some point, even though they are not listed in a runlevel

  AND/OR 

  add a SERVICE_BINDING parameter where user can specify what services are bound to what interfaces, for example
SERVICE_BINDING_WLAN=("ntpd")
SERVICE_BINDING_LAN=("ntpd" "sshd")
  
  OR 

  besides the "included"/"not included" in runlevels, allow user to add services to runlevels that start up in "paused"-state (or some similar "ready" state).

  OR

  Use some ifplugd like tool to not *bring* the interface up as necessary, but monitor the *state* of the interface. This would also allow for the possibility to bring up an interface with other tools than Gentoo initscripts and still allow the services to start
  - for example, bringing up PPP interface by the kpppd dialup tool in KDE

I can patch this for my purposes (for most of the time) by doing a "sudo /etc/init.d/ntpd start" whenever I connect (and changing my wlan ACPI action script), but I would prefer the system would handle it automatically.
Comment 1 Roy Marples (RETIRED) gentoo-dev 2006-07-17 02:42:38 UTC
If you need to bind specific services to specific interfaces then remove them from the default runlevel and do this in /etc/conf.d/net

postup() {
   if [[ ${IFACE} == "lan" ]] ; then
      start_service sshd
   fi
}

predown() {
   if [[ ${IFACE} == "lan" ]] ; then
      stop_service sshd
   fi
}

> (Incidentally, does resolvconf-gentoo handle NTP besides DNS?)

Nope, it's just DNS
Comment 2 Antti Mäkelä 2006-07-17 11:38:27 UTC
(In reply to comment #1)
> If you need to bind specific services to specific interfaces then remove them
> from the default runlevel and do this in /etc/conf.d/net

  Ok. I'll add some if service_started() logic to the predown() for those services that should not be taken down if other interfaces are still valid (such as NTP) - however, they should probably be sent SIGHUP so that they take in new configuration (I use my local ntp server when in local lan, and pool.ntp.org with wlan since the hotspot could be anywhere).

  Also, I'm going to check if I could modify /etc/ifplugd/ifplugd.action to only start/stop services (and not call rc-script) if interface comes up in the case of ppp. I've never tested ifplugd's monitor mode with ppp - but theoretically this could allow for one to bring dialup interfaces up via other programs than directly calling initscript. Kind of similar fashion to wpa_supplicant where you the daemon can run in the background and you can reconfigure it on the fly with wpa_gui.

  Unfortunately, this means effectively duplicating the postup/predown functionality already written in conf.d/net. Is there a way to call rc-scripts so that only the post/pre-part is executed?
Comment 3 Roy Marples (RETIRED) gentoo-dev 2006-07-17 16:01:42 UTC
(In reply to comment #2)
>   Unfortunately, this means effectively duplicating the postup/predown
> functionality already written in conf.d/net. Is there a way to call rc-scripts
> so that only the post/pre-part is executed?

Yes and no - it depends on the interface. You could do this

config_ppp0=( "noop" )

Which means "Do nothing on ppp0 if we are UP and have a working IPv4 address". However, that's just the config - the module pre/post and your user defined pre/post functions still get run. So if any modules cause a problem, exlude them

modules_ppp0=( "!ifplugd" )
Comment 4 Roy Marples (RETIRED) gentoo-dev 2006-08-17 08:57:42 UTC
With baselayout-1.12.4 you can do this in each /etc/conf.d/ file except for rc

RC_NEED="foo"
RC_USE="bar"

So in /etc/conf.d/ntp
RC_NEED="net.wlan net.lan"

in /etc/conf.d/sshd
RC_NEED="net.lan"
Comment 5 Antti Mäkelä 2006-08-25 03:26:25 UTC
I now have

RC_USE="net.lan" in my /etc/conf.d/sshd 

AND

RC_USE="net.lan net.wlan" in my /etc/conf.d/ntpd

Results, with both interfaces down at the boot:

I get reports like

WARNING: ntpd is scheduled to start when net.lan or net.lan has started
WARNING: sshd is scheduled to start when net.lan or net.lan has started.

The services only start when I bring LAN up (ie. plug in the cable). If I say /etc/init.d/net.wlan start, ntpd is not brought up..

Baselayout is 1.12.4-r7.

I have net.lan in my runlevel default, along with sshd and ntpd. net.wlan is not in any runlevel (or net.ppp0, for that matter).