[systemd-devel] Orchestrating a shutdown immediately after boot

Lennart Poettering lennart at poettering.net
Mon Jul 8 16:37:53 PDT 2013

On Mon, 08.07.13 00:08, Kerrick Staley (kerrick at kerrickstaley.com) wrote:

> I'd like my system to:
> 1. boot
> 2. run a command
> 3. shut down
> I've implemented step 2 in a .service file [1], but I can't figure out how
> to automatically shut the system down once it's finished. shutdown.target
> conflicts with all services that don't set DefaultDependencies=false (which
> is most of them), so it seems I'm out of luck—there is no way to specify a
> target that requires both multi-user.target and shutdown.target. Is there
> some way to handle this situation?

You cannot queue bootup and shutdown in the same transaction. If you do
then both transactions will be merged and hence the stop and start jobs
for your units will conflict and one of them removed.

The start-up transaction should be left as it is. And after the work you
want to do is done you should simply queue another transactaion.

> N.B. This is all running in an LXC; the overarching goal is to sandbox the
> command so it can't affect the rest of the system.
> - Kerrick
> [1] If it's useful, the .service file is as follows:
> [Unit]
> Description=Sandboxed Checkerbox command
> After=multi-user.target
> [Service]
> User=user
> Type=simple
> ExecStart=/bin/sh -c '/home/user/cmd </home/user/stdin >/home/user/stdout
> 2>/home/user/stderr'

A simple approach could be to simply add
"ExecStopPost=/usr/bin/systemctl --no-block poweroff" or so.


Lennart Poettering - Red Hat, Inc.

More information about the systemd-devel mailing list