You are not logged in.

#1 2013-01-27 20:15:32

phunni
Member
From: Bristol, UK
Registered: 2003-08-13
Posts: 667

[Solved] systemctl seems to start and stop my service when I run start

I've written a simple .service to enable a script I wrote as a service:

[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

Last edited by phunni (2013-01-28 10:56:14)

Offline

#2 2013-01-27 20:29:12

chris_l
Member
Registered: 2010-12-01
Posts: 387

Re: [Solved] systemctl seems to start and stop my service when I run start

well, from man systemd.service

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> ?


"open source is about choice"
No.
Open source is about opening the source code complying with this conditions, period. The ability to choose among several packages is just a nice side effect.

Offline

#3 2013-01-27 20:35:16

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 13,373
Website

Re: [Solved] systemctl seems to start and stop my service when I run start

Or set type to forking.


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Online

#4 2013-01-27 22:20:20

chris_l
Member
Registered: 2010-12-01
Posts: 387

Re: [Solved] systemctl seems to start and stop my service when I run start

Trilby wrote:

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.


"open source is about choice"
No.
Open source is about opening the source code complying with this conditions, period. The ability to choose among several packages is just a nice side effect.

Offline

#5 2013-01-28 10:51:59

phunni
Member
From: Bristol, UK
Registered: 2003-08-13
Posts: 667

Re: [Solved] systemctl seems to start and stop my service when I run start

chris_l wrote:

...and why you are doing this instead of systemctl enable netcfg@<profile> ?

Because this is different smile

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.

Offline

#6 2013-01-28 10:56:00

phunni
Member
From: Bristol, UK
Registered: 2003-08-13
Posts: 667

Re: [Solved] systemctl seems to start and stop my service when I run start

BTW using RemainAfterExit=yes appears to have worked.  Thanks.

Offline

Board footer

Powered by FluxBB