[systemd-devel] FC16 - how to get ExecStop= to be executed at shutdown?

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Thu Dec 8 14:45:49 PST 2011

On 12/04/2011 06:50 PM, Josh Geisser wrote:
> Hi Zbigniew
> I added the "| logger"  b/c i wanted additional proove that the scripts are actually executed, and it seems to work, the start-output is logged into syslog.

as I said before, the output goes _by default_ to syslog (or more 
precisely, to DefaultStandardOutput, which default to syslog) so your 
test doesn't really work.

Look at the following file (/etc/systemd/system/hello.service):

   ExecStart=/bin/echo hello world | /usr/bin/logger
   ExecStop=/bin/echo stopping service

When I load and start this service, I get the following line in syslog:

   Dec  8 23:36:11 localhost echo[5286]: hello world | /usr/bin/logger
   Dec  8 23:36:11 localhost echo[5288]: stopping service

So ExecStop does get called, and there's no shell syntax.


> But not the ExecStop. I added some more logging and the stop command seems never to be executed.
> Also, the VMs take time to shutdown, but Xfce just terminate upon shutdown, definitely does not wait until the VBox service is stopped.
> It might be that systemd terminates the PIDs of the VMs directly, but it's currently not executing the ExecStop ... bet I'm missing something.
> Cheers
> Josh
> -----Ursprüngliche Nachricht-----
> Von: systemd-devel-bounces+josh=gebaschtel.ch at lists.freedesktop.org [mailto:systemd-devel-bounces+josh=gebaschtel.ch at lists.freedesktop.org] Im Auftrag von Zbigniew Jedrzejewski-Szmek
> Gesendet: Sonntag, 4. Dezember 2011 18:28
> An: systemd-devel at lists.freedesktop.org
> Betreff: Re: [systemd-devel] FC16 - how to get ExecStop= to be executed at shutdown?
> On 12/04/2011 03:53 PM, Josh Geisser wrote:
> Hi,
>> I succeeded with auto login and auto start of my Virtual Boxes, but could not get them to do a proper shutdown.
>> Because of the nature of the VM processes I want to send them a proper ACPI shutdown button instead of terminating the process, which is done through my old rc-script.
>> The VirtualBoxes process are started AFTER X11 is up, but must also be shutdown BEFORE the display-manager is exited.
>> How do I configure this in the service file?
> You already have this property, because After is reversed during shutdown.
>   From systemd.unit(5):
> Note that when two units with an ordering dependency between them are
> shut down, the inverse of the start-up order is applied. i.e. if a unit
> is configured with After= on another unit, the former is stopped before
> the latter if both are shut down.
>> My /lib/systemd/system/vbox.service:
>> [Unit]
>> Description=Virtual Box Machines
>> After=vboxdrv.service network.target display-manager.service
>> [Service]
>> Type=forking
>> ExecStart=/home/vmuser/./rc.virtualboxes start | /usr/bin/logger
>> ExecStop=/home/vmuser/./rc.virtualboxes stop | /usr/bin/logger
> Those two lines are wrong. ExecStart is justed exec()ed, not through the
> shell. What happens here, is that the script gets three arguments
> "start", "|", "/usr/bin/logger". It likely ignores everything but $1, so
> it seems to work.
> You might use StandardOutput= (see systemd.exec(5)), or just leave the
> redirection out entirely, it is now the default to redirect stdout to
> syslog.
> Best,
> Zbyszek
>> [Install]
>> WantedBy=graphical.target
>> Cheers&   thx
>> Josh

More information about the systemd-devel mailing list