Site Map - skip to main content - dyslexic font - mobile - text - print

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes Monday through Friday.

hpr2134 :: Shutdown Sequence Systemd

Klaatu demonstrates how to sequence systemd shutdown processes

<< First, < Previous, Latest >>

Hosted by klaatu on 2016-10-06 and released under a CC-BY-SA license.
Listen in ogg, spx, or mp3 format. | Comments (0)

Set up a service to trigger FIRST (this would be the shutdown service):

# cat /lib/systemd/system/fakehalt.service

Description=Fake-Halt Service

ExecStart=/usr/local/bin/ #this will fail until fakevm succeeds

And then set up the one that you want to run and complete BEFORE shutdown is permitted:

# cat /lib/systemd/system/fake.service
Description=Fake Service


Create a script to represent the VM shutdown (or any process that you cannot anticipate the duration of)

# cat /usr/local/bin/

sleep 21
if [ X"$test" = "X1" ]; then
    echo "vm has shut down" > /tmp/fake.test
    exit 0
    exit 1

And a script to pass for a shutdown signal:

# cat /usr/local/bin/

sleep 3
cat /tmp/vmfake.test > /tmp/haltfake.test

Start the service you want to happen AFTER the first one:

# systemctl start fakehalt

What "should" happen is that fakehalt will fail to find a file called /tmp/fake.test to cat from, and so everything should go horribly wrong.

What actually happens is that systemd places fakehalt service on hold until it gets an exit 0 signal from the fake service. So if you wait 21 seconds and cat /tmp/fakehalt.test, you see that the cat from a file that did not exist when fakehalt was started - actually succeeded.


Subscribe to the comments RSS feed.

Leave Comment

Powered by Comment Script