toolbox: systemctl does not work inside the toolbox

I’m setting up a toolbox for a development environment for a web application that requires postgresql running. I’m installing postgresql-server on the toolbox and then trying to start it using the usual method:

INS mildred@toolbox$ sudo systemctl start postgresql.service
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

This is understandable as I’m running within a container, and systemd usually is not started in containers. Still, it means I have to manually start up postgresql by reading the systemd service file.

It would be great if systemd was started as entrypoint in the toolbox image, instead of sleep +Inf. Of course, udev and low level services would have to be prevented from starting so that a blank toolbox would not start any service.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 17
  • Comments: 15 (1 by maintainers)

Commits related to this issue

Most upvoted comments

Yep, it’s possible to execute postgresql in a podman container instead, but you lack the easy use and integration. I believe the toolbox is much more easy to use of you can just toolbox enterand then start working. Instead if you have to execute some lengthy podman commands outside of the toolbox first, and redirect ports, you are not as productive.

Also, podman gave me an error when I tried to start the container, but that’s not an issue with toolbox.

In my case, this issue doesn’t allow to run MongoDB:

toolbox enter sudo systemctl enable mongod systemctl status mongod.service

System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

@debarshiray The issue blocks the migration to non-testing usage of ostree-based distros like Silverblue, Gnome OS, Endless OS. Can I hope this problem will be fixed in the short term?

I believe this warrants a separate issue, but I found this because I was investigating using toolbox for debugging and wanted systemctl status <service> to work inside of it.

I was able to get this to work by running:

ln -s /run/host/var/run/systemd/system /run/systemd/system

SYSTEMD_IGNORE_CHROOT=1 systemctl status

This issue seems to be more about starting services inside of the toolbox, however. I’m less interested in that, and more interested in making the toolbox as transparent as possible on the host, while still allowing for installing tools, etc. for debugging.

Trying to use nsenter to have systemd running in a PID namespace and toolbox shells running in the host PID namespace does not work so well. the /proc filesystem mounted within the container represents the container PID namespace and not the host. As such, commands are complaining with errors like:

ls: cannot read symbolic link '/proc/self': No such file or directory

Perhaps we can have different features enabled for the toolboxes, and we can choose for each toolbox if we want to

  • run an init system but have a separate PID namespace
  • do not run an init system and keep the same PID namespace

It corresponds to two different use cases.

Trying out running systemd with the toolbox, I find a problem with it. systemd is not running as PID 1 and tries to start in user mode and not in system mode.

This is because there is the --pid=host option passed to podman create.

May I suggest that podman create keeps the PID namespace (so systemd can run) but podman exec gets a new option to keep the PID namespace of the host. it is possible with nsenter, why not podman exec ?

found a nice post here: https://developers.redhat.com/blog/2019/04/24/how-to-run-systemd-in-a-container/