[systemd-devel] Cannot get Shutdown Script to Run (Libvirt Virtual Machine Shutdown)

"Jóhann B. Guðmundsson" johannbg at gmail.com
Thu Oct 9 13:28:30 PDT 2014


On 10/09/2014 02:26 PM, Lennart Poettering wrote:
> On Thu, 09.10.14 12:14, Jóhann B. Guðmundsson (johannbg at gmail.com) wrote:
>
>> On 10/08/2014 11:41 PM, Lennart Poettering wrote:
>>> TODO list to allow services also when they have no ExecStart= but with
>>> an ExecStop=, but this has not been implemented yet.
>> What's the usecase for this behaviour?
> Precisely cases like the one described earlier in this thread: when
> you want to run something only at shutdown, properly ordered against
> other units that are also shut down.

To me that already works just fine.

[Unit]
Description=My Shutdown Test
Before=shutdown.target
DefaultDependencies=no

[Service]
Type=oneshot
ExecStart=/bin/systemd-cat -t "SHUTDOWN" /bin/echo "Systemd shutdown test-2"

[Install]
WantedBy=shutdown.target


  journalctl SYSLOG_IDENTIFIER=SHUTDOWN
-- Logs begin at Thu 2013-10-24 11:47:22 GMT, end at Thu 2014-10-09 
20:00:17 GMT. --
Oct 09 19:57:51 localhost.localdomain SHUTDOWN[1968]: Systemd shutdown 
test-1
-- Reboot --
Oct 09 19:59:19 localhost.localdomain SHUTDOWN[1898]: Systemd shutdown 
test-2
( the former log is from when I initially tested the unit before reboot )

If I wanted to order it after an service I added After=httpd.service

[Unit]
Description=My Shutdown Test
Before=shutdown.target
After=httpd.service
DefaultDependencies=no

[Service]
Type=oneshot
ExecStart=/bin/systemd-cat -t "SHUTDOWN" /bin/echo "Systemd shutdown test-3"

[Install]
WantedBy=shutdown.target


In my test I added this line to httpd.service
ExecStop=/bin/systemd-cat -t "SHUTDOWN" /bin/echo "Systemd shutdown 
test-3 Apache Stopped"

Then I rebooted and as you can see things seem to work perfectly as in 
the test case was stopped after apache had stopped make the shutdown 
order correct

# journalctl SYSLOG_IDENTIFIER=SHUTDOWN

-- Reboot --
Oct 09 20:16:37 localhost.localdomain SHUTDOWN[1972]: Systemd shutdown 
test-3 Apache Stopped
Oct 09 20:16:38 localhost.localdomain SHUTDOWN[1985]: Systemd shutdown 
test-3

What I dont understand what's the usecase for somekind of ExecStop= 
modfications, why do we need to do that?

JBG


More information about the systemd-devel mailing list