Launch a toolbox with systemd

I installed Apache in a toolbox. What’s the best way to launch it at boot time?

I can write my own apache.service on the host, but is there a way to use whatever the package provides?

1 Like

There is no systemd instance running in a toolbox. If you want to launch user level services via containers, I’d recommend you use podman rootless containers.

3 Likes

I agree with @siosm. Use a rootless Podman container to deploy Apache. It will have you create a volume for it for your site, so if you’re developing a website you just do it in the volume directory. As for your original question: once you have the container running you can have Podman create a systemd unit for you with podman generate systemd -f -n <container / pod name>. Then you just copy that file into ${HOME}/.local/share/systemd/user/, run systemctl --user daemon-reload, followed by systemctl --user enable <container / pod name>.service --now and your Apache container will start at boot every time.

2 Likes

For the sake of completeness, podman comes with a user-space systemd that restarts all services marked as such.

systemctl --user status podman-restart.service 
○ podman-restart.service - Podman Start All Containers With Restart Policy Set To Always
     Loaded: loaded (/usr/lib/systemd/user/podman-restart.service; disabled; preset: disabled)
    Drop-In: /usr/lib/systemd/user/service.d
             └─10-timeout-abort.conf
     Active: inactive (dead)
       Docs: man:podman-start(1)

The modern solution (for the past couple years):

You’re probably looking for “quadlets”, which lets you define containers as services. To migrate an existing configuration or even command-line values from podman to quadlets (without having to write them from scratch), look into the podlet command.

You basically drop an ini-style .container file definition of a container (which can be made with the podlet command or written from scratch) in /etc/containers/systemd/ (or $HOME/.config/containers/systemd/ for rootless containers in your user account) then run systemctl daemon-reload (with --user if it’s a user service) and then you can use systemctl with enable/disable start/stop like any other systemd service.

The podlet readme can get you started; the “quadlet” blog has more details.

2 Likes

How does this work with podman-compose managed containers?

podlet supports converting compose files to quadlets (among all its various supported formats):