FS#30348 - [netcfg] net-auto-wired.service doesn't work

Attached to Project: Arch Linux
Opened by Iskren Ivov Chernev (ichernev) - Monday, 18 June 2012, 21:48 GMT
Last edited by Jouke Witteveen (jouke) - Sunday, 24 June 2012, 22:20 GMT
Task Type Bug Report
Category Packages: Core
Status Closed
Assigned To Jouke Witteveen (jouke)
Tom Gundersen (tomegun)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 1
Private No

Details

Description:
systemctl start net-auto-wired.service fails, because ifplugd exists with nonzero status (which is fine) but systemd thinks this is an issue.

Additional info:
* netcfg 2.8.3-1
* systemctl status header

% systemctl status net-auto-wired.service
net-auto-wired.service - Provides automatic netcfg wired connection
Loaded: loaded (/usr/lib/systemd/system/net-auto-wired.service; enabled)
Active: failed (Result: exit-code) since Tue, 19 Jun 2012 00:43:27 +0300; 5s ago
Process: 23270 ExecStop=/usr/sbin/ifplugd -i $WIRED_INTERFACE -r /etc/ifplugd/netcfg.action -k (code=exited, status=0/SUCCESS)
Process: 23279 ExecStart=/usr/sbin/ifplugd -i $WIRED_INTERFACE -r /etc/ifplugd/netcfg.action -fIw -d10 (code=exited, status=2)
Main PID: 23228 (code=exited, status=0/SUCCESS)
CGroup: name=systemd:/system/net-auto-wired.service

Steps to reproduce:
1. Configure a wired netcfg profile
2. systemctl start net-auto-wired.service

Solution:
Just add a minus sign before /usr/bin/ifplugd in ExecStart in ExecStop, like

ExecStart=-/usr/sbin/ifplugd -i $WIRED_INTERFACE -r /etc/ifplugd/netcfg.action -fIw -d10
ExecStop=-/usr/sbin/ifplugd -k -i $WIRED_INTERFACE -r /etc/ifplugd/netcfg.action

and it would work.
This task depends upon

Closed by  Jouke Witteveen (jouke)
Sunday, 24 June 2012, 22:20 GMT
Reason for closing:  Fixed
Additional comments about closing:  90939
Comment by Jouke Witteveen (jouke) - Tuesday, 19 June 2012, 10:18 GMT
What are the exit values of ifplugd? Is there a switch to make them sane?
Comment by Iskren Ivov Chernev (ichernev) - Tuesday, 19 June 2012, 19:10 GMT
-w | --wait-on-fork
When daemonizing, wait until the background process finished with the initial link beat detection. When this
is enabled, the parent process will return the link status on exit. 1 means link beat detected, 2 stands for
link beat not detected, everything else is an error.

We are using this flag, but I tried without and it seems to work.
Comment by Jouke Witteveen (jouke) - Tuesday, 19 June 2012, 21:16 GMT
So if I understand it correctly, removing the w switch from the start command makes starting work. I don't think we need the minus sign after ExecStop, do we? If that command succeeds it'd be broken to not return 0.

Now the hard part. I'm no systemd target expert, but I think entering network.target is supposed to mean there is a working connection. Of course, this is not necessarily the case for this service. Can we do something about this?
Comment by Iskren Ivov Chernev (ichernev) - Tuesday, 19 June 2012, 22:04 GMT
Yes, removing the w switch seems reasonable. [*]
Yes, I also think we don't need the minus sign, both at ExecStart and ExecStop.

I just tried systemd yesterday, so I'm no expert either :) I think we don't need to reference network in Before/Wants, but [*] I don't know how systemd is going to know when the network is ready (as other services depend on it).
Comment by Iskren Ivov Chernev (ichernev) - Tuesday, 19 June 2012, 22:37 GMT
I noticed another issue -- when you restart the daemon the network goes down, but not up again. The reason is that on shutdown ifplugd disables the interface, but not the profile, and then on startup it reenables the already enabled profile, which does nothing.

The correct behavior would be to down the profiles on exit. I think both scripts in /etc/ifplugd should be carefully examined by somebody who knows ifplugd and netcfg a little better.
Comment by Jouke Witteveen (jouke) - Thursday, 21 June 2012, 10:07 GMT
What about the attached service file? It is non-forking and doesn't claim the network is usable after it is loaded. I think the real solution would be to switch to something that has proper dbus integration so that systemd can be informed of status changes.
Comment by Iskren Ivov Chernev (ichernev) - Thursday, 21 June 2012, 22:57 GMT
I just tested the attached file and it doesn't have the problem with restarting I stated above.
About 'Before: network.target' -- what is the idea behind this?
About dbus integration -- I think network-manager is the proper (only?) answer to that, but I'm not sure if it should be used in this particular place.

Overall I think the attached file is much better than what currently is used, so it may be used until something better comes up :)
Comment by Tom Gundersen (tomegun) - Thursday, 21 June 2012, 23:33 GMT
Before=network.target means that the network is not considered to be up before this service has finished starting. In order for network.target to be useful for other services to order against we also need: that the service is not considered considered to be started until we have a network connection (which seems to be what the "-w" switch does, but I'm not an expert); and to add Wants=network.target to actually activate the target once we are ready (and not only block it).

As to the wrong error code: I think the ideal situtaion would be to return '0' when a link beat was detected and something else otherwise. However, that is not the case, so either we wrap the thing in a shell-script that translates the return code, or we do "ExecStart=-" which just ignores the return code (the problem is then that the we won't detect if there is a real error).
Comment by Dave Reisner (falconindy) - Thursday, 21 June 2012, 23:53 GMT
This bug report amuses me, since no other than Lennart wrote ifplugd. I have nothing constructive to add.
Comment by Jouke Witteveen (jouke) - Friday, 22 June 2012, 00:04 GMT
What baffles me is that he never introduced ifplugd to systemd. I feel that I am missing something terribly.

Does anyone know what the clean way would be to monitor a NIC for cable (un)plug events and act upon them?
@Tom: It is not an error when ifplugd doesn't find a beat on start-up, is it? It just means no cable is attached, right?
What I tried to write was a service file that starts ifplugd the way we want it to run and be easy on systemd (no forking etc.). The Before= is just meant as an order preference but has no real effect since starting the service is instantaneous the way I wrote it (at least, this is what I make of it). Can you give a structured overview of your objections? The ExecStop is called before the process is killed and deals with the off-topic concern of Iskren.
Comment by Jouke Witteveen (jouke) - Sunday, 24 June 2012, 22:19 GMT
Please reopen this bug if you have insights from which a better service file could be crafted.

Loading...