Systemd/ENVIRONMENT.md
Colin Walters f38951a628 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.
2017-12-14 16:00:16 -05:00

3.9 KiB

Known Environment Variables

A number of systemd components take additional runtime parameters via environment variables. Many of these environment variables are not supported at the same level as command line switches and other interfaces are: we don't document them in the man pages and we make no stability guarantees for them. While they generally are unlikely to be dropped any time soon again, we do not want to guarantee that they stay around for good either.

Below is an (incomprehensive) list of the environment variables understood by the various tools. Note that this list only covers environment variables not documented in the proper man pages.

All tools:

  • $SYSTEMD_OFFLINE=[0|1] — if set to 1, then systemctl will refrain from talking to PID 1; this has the same effect as the historical detection of chroot(). Setting this variable to 0 instead has a similar effect as SYSTEMD_IGNORE_CHROOT=1; i.e. tools will try to communicate with PID 1 even if a chroot() environment is detected. You almost certainly want to set this to 1 if you maintain a package build system or similar and are trying to use a modern container system and not plain chroot().

  • $SYSTEMD_IGNORE_CHROOT=1 — if set, don't check whether being invoked in a chroot() environment. This is particularly relevant for systemctl, as it will not alter its behaviour for chroot() environments if set. Normally it refrains from talking to PID 1 in such a case; turning most operations such as start into no-ops. If that's what's explicitly desired, you might consider setting SYSTEMD_OFFLINE=1.

  • $SD_EVENT_PROFILE_DELAYS=1 — if set, the sd-event event loop implementation will print latency information at runtime.

  • $SYSTEMD_PROC_CMDLINE — if set, may contain a string that is used as kernel command line instead of the actual one readable from /proc/cmdline. This is useful for debugging, in order to test generators and other code against specific kernel command lines.

systemctl:

  • $SYSTEMCTL_FORCE_BUS=1 — if set, do not connect to PID1's private D-Bus listener, and instead always connect through the dbus-daemon D-bus broker.

  • $SYSTEMCTL_INSTALL_CLIENT_SIDE=1 — if set, enable or disable unit files on the client side, instead of asking PID 1 to do this.

  • $SYSTEMCTL_SKIP_SYSV=1 — if set, do not call out to SysV compatibility hooks.

systemd-nspawn:

  • $UNIFIED_CGROUP_HIERARCHY=1 — if set, force nspawn into unified cgroup hierarchy mode.

  • $SYSTEMD_NSPAWN_API_VFS_WRITABLE=1 — if set, make /sys and /proc/sys and friends writable in the container. If set to "network", leave only /proc/sys/net writable.

  • $SYSTEMD_NSPAWN_CONTAINER_SERVICE=… — override the "service" name nspawn uses to register with machined. If unset defaults to "nspawn", but with this variable may be set to any other value.

  • $SYSTEMD_NSPAWN_USE_CGNS=0 — if set, do not use cgroup namespacing, even if it is available.

  • $SYSTEMD_NSPAWN_LOCK=0 — if set, do not lock container images when running.

systemd-logind:

  • $SYSTEMD_BYPASS_HIBERNATION_MEMORY_CHECK=1 — if set, report that hibernation is available even if the swap devices do not provide enough room for it.

installed systemd tests:

  • $SYSTEMD_TEST_DATA — override the location of test data. This is useful if a test executable is moved to an arbitrary location.

nss-systemd:

  • $SYSTEMD_NSS_BYPASS_SYNTHETIC=1 — if set, nss-systemd won't synthesize user/group records for the root and nobody users if they are missing from /etc/passwd.

  • $SYSTEMD_NSS_DYNAMIC_BYPASS=1 — if set, nss-systemd won't return user/group records for dynamically registered service users (i.e. users registered through DynamicUser=1).

  • $SYSTEMD_NSS_BYPASS_BUS=1 — if set, nss-systemd won't use D-Bus to do dynamic user lookups. This is primarily useful to make nss-systemd work safely from within dbus-daemon.