...and why you are doing this instead of systemctl enable netcfg@<profile> ?
Because this is different
I want netcfg to try profiles in a given order and then stop when one succeeds. As far as I can tell (and from conversations about it on this very board) netcfg doesn't have this functionality. So, I've written a script to extend it.
]]>Or set type to forking.
hmm.
As a forking service, the parent is expected to end, and the cgroup will contain the children (not sure about what would happen with the children using oneshot+RemainAfterExit )
However, the official netcfg.service and netcfg@.service files are set as oneshot+RemainAfterExit instead of forking.
Since there are not children process from netcfg (none that I have seen, maybe Im wrong), I think that maybe, the right thing™ is oneshot+RemainAfterExit instead of forking.
Type=
Behavior of oneshot is similar to simple, however it is expected that the process has to exit before systemd starts follow-up units. RemainAfterExit= is particularly useful for this type of service.
RemainAfterExit=
Takes a boolean value that specifies whether the service shall be considered active even when all its processes exited. Defaults to no.
Not sure 100%, but probably if you set RemainAfterExit to yes
...and why you are doing this instead of systemctl enable netcfg@<profile> ?
]]>[Unit]
Description=run through a list of netcfg profiles starting them in order and stopping when one connects succesfully.
Before=network.target
Wants=network.target
Conflicts=netcfg.service
[Service]
Type=oneshot
ExecStart=/usr/bin/netcfg-manager
ExecStop=/usr/bin/netcfg -a
[Install]
WantedBy=multi-user.target
when I run
systemctl start netcfg-manager.service
and the request the status I get the following output from the status request:
netcfg-manager.service - run through a list of netcfg profiles starting them in order and stopping when one connects succesfully.
Loaded: loaded (/usr/lib/systemd/system/netcfg-manager.service; disabled)
Active: inactive (dead) since Sun 2013-01-27 20:12:28 UTC; 3s ago
Process: 1834 ExecStop=/usr/bin/netcfg -a (code=exited, status=0/SUCCESS)
Process: 1821 ExecStart=/usr/bin/netcfg-manager (code=exited, status=0/SUCCESS)
Jan 27 20:12:28 kirstine netcfg-manager[1821]: ethernet-static already connected
Jan 27 20:12:28 kirstine netcfg[1834]: :: ethernet-static down [done]
Which suggests to me that it is running both ExecStart and ExecStop when I simply ask it to start.
Obviously this is a problem.
Can anyone shed any light on what it going on here?
I don't think it's a factor, but, just in case, here is the script that gets called:
#!/bin/bash
i=0
while read line; do
# ignore comment lines
echo "$line" | grep "^#" >/dev/null 2>&1 && continue
profiles[i]=$line
((i++))
done < /etc/netcfg-manager.conf
for p in ${profiles[@]}
do
netcfg -u $p
if [ $? -eq 0 ]
then
echo "Started profile $p succesfully";
break;
fi
done