systemctl,verbs: Introduce SYSTEMD_OFFLINE environment variable
authorColin Walters <walters@verbum.org>
Wed, 13 Dec 2017 21:04:41 +0000 (16:04 -0500)
committerColin Walters <walters@verbum.org>
Thu, 14 Dec 2017 21:00:16 +0000 (16:00 -0500)
commitf38951a62837a00a0b1ff42d007e9396b347742d
treec5933bbc1a2a50e2450e6ef20edacbcc910185c8
parent2de2abad62d4f23f7d9af0c3871f9955896d085c
systemctl,verbs: Introduce SYSTEMD_OFFLINE environment variable

A lot of code references the `running_in_chroot()` function; while
I didn't dig I'm pretty certain this arose to deal with situations
like RPM package builds in `mock` - there we don't want the `%post`s
to `systemctl start` for example.

And actually this exact same use case arises for
[rpm-ostree](https://github.com/projectatomic/rpm-ostree/)
where we implement offline upgrades by default; the `%post`s are
always run in a new chroot using [bwrap](https://github.com/projectatomic/bubblewrap).

And here's the problem: bwrap creates proper mount roots, so it
passes `running_in_chroot()`, and then if a script tries to do
`systemctl start` we get:
`System has not been booted with systemd as init system (PID 1)`
but that's an *error*, unlike the `running_in_chroot()` case where we ignore.

Further complicating things is there are real world RPM packages
like `glusterfs` which end up invoking `systemctl start`.

A while ago, the `SYSTEMD_IGNORE_CHROOT` environment variable was
added for the inverse case of running in a chroot, but still wanting
to use systemd as PID 1 (presumably some broken initramfs setups?).

Let's introduce a `SYSTEMD_OFFLINE` environment variable for cases like
mock/rpm-ostree so we can force on the "ignore everything except preset" logic.
This way we'll still not start services even if mock switches to use nspawn or
bwrap or something else that isn't a chroot.

We also cleanly supercede the `SYSTEMD_IGNORE_CHROOT=1` which is now spelled
`SYSTEMD_OFFLINE=0`.  (Suggested by @poettering)

Also I made things slightly nicer here and we now print the ignored operation.
ENVIRONMENT.md
src/basic/verbs.c
src/basic/verbs.h
src/systemctl/systemctl.c