Skip to content

Commit

Permalink
systemd: Document how to add custom shutdown actions
Browse files Browse the repository at this point in the history
As discussed in flatcar/Flatcar#65 the single
path that systemd supports for shutdown hooks does not work for read-
only images but we can use regular units to run custom shutdown
actions. Document one way to do it (there are many other ways how to
express this with systemd units).
  • Loading branch information
pothos committed Mar 17, 2023
1 parent a1c166e commit 8f8b6c8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions content/docs/latest/setup/systemd/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,24 @@ ExecStartPost=/usr/bin/etcdctl set /domains/example.com/%H:%i running

This gives us the flexibility to use a single unit file to announce multiple copies of the same container on a single machine (no port overlap) and on multiple machines (no hostname overlap).

## Shutdown hooks

While systemd allows to add custom hooks in `/usr/lib/systemd/system-shutdown/` that get run for `poweroff`/`halt`/`reboot`/`kexec` events, this path is not writable on Flatcar Container Linux. Therefore, regular units need to be used for running, e.g., a special cleanup action on shutdown:

```ini
[Unit]
Description=Custom cleanup on shutdown
DefaultDependencies=no
After=final.target

[Service]
Type=oneshot
ExecStart=bash -c 'echo bye; touch /bye'

[Install]
WantedBy=final.target
```

## More information

- [`systemd.service` Docs](http://www.freedesktop.org/software/systemd/man/systemd.service.html)
Expand Down

0 comments on commit 8f8b6c8

Please sign in to comment.