Bug 809823

Summary: systemd "service start" immediately followed by "service stop" if no process running
Product: [openSUSE] openSUSE 12.3 Reporter: Ralf Friedl <Ralf.Friedl>
Component: BasesystemAssignee: E-mail List <bnc-team-screening>
Status: RESOLVED INVALID QA Contact: E-mail List <qa-bugs>
Severity: Normal    
Priority: P5 - None CC: fcrozat, Ralf.Friedl
Version: Final   
Target Milestone: ---   
Hardware: x86-64   
OS: openSUSE 12.2   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Ralf Friedl 2013-03-16 21:47:33 UTC
User-Agent:       Mozilla/5.0 (Windows; U; Win98; de-AT; rv:1.8.1.24) Gecko/20100228 SeaMonkey/1.1.19

Actually, system is openSUSE 12.3, but that is not (yet) available from the
Operating System selection box.

I have created an init script that executes some commands, but doesn't leave a process running. When it is started, whether by "systemctl start local.service" or "/etc/init.d/local start" (which calls systemctl), systemd executes "/etc/init.d/local start" with SYSTEMD_NO_WRAP set. The script is executed and return status 0 for success. So far everything is well.
The problem is that now systemd immediately executed "/etc/init.d/local stop". But the stop action undoes the effects of the start action and is only meant to be called at shutdown.

This used to work with the original openSUSE 12.2, but no longer after some updates to systemd.

Reproducible: Always

Steps to Reproduce:
1. Create startup script /etc/init.d/local that doesn't leave process running.
2. Call systemctl to have systemd execute the script.
Actual Results:  
systemd calls "/etc/init.d/local start". The script exits with status 0.
systemd calls "/etc/init.d/local stop".


Expected Results:  
systemd calls "/etc/init.d/local start". The script exits with status 0.
systemd doesn't call "/etc/init.d/local stop" until system shutdown.


I verified that it is really not leaving a running progress by adding this line:
    ( sleep 999999 & )
Now everything works as expected, except when I kill the sleep process (or it dies for other reasons), systemd will execute the stop action of the script.
Comment 1 Frederic Crozat 2013-03-18 11:08:40 UTC
systemd has to use some heuristic to detect if an initscript is a "remainafterexit" service (ie not having any process left is OK" or not.

If an initscript is taking a long time to start, the heuristic will disable the "RemainAfterExit" flag. 

If you want to enforce one behaviour, add to your initscript LSB header the following line:
# X-Systemd-RemainAfterExit: true (or false)

(of course, I would suggest to use a systemd .service file if you can, but that's another story).
Comment 2 Ralf Friedl 2013-03-18 17:15:32 UTC
Thank you, works as expected.
Comment 3 Frederic Crozat 2013-03-18 17:46:18 UTC
closing bug as invalid then.