I want to systemd-ize our docker/docker-compose/podman setups, but it seems that systemd is incapable of properly dealing with service units that end without leaving a process behind. That is problematic, because the tools in question work by calling an API, scheduling processes to start but not spawning or forking them themselves, so by the time a call to, say, docker-compose returns, no processes are visible for systemd, so any variation of Type/RemainAfterExit still leads to the service marked as stop/dead/stopping/etc., because no surviving PID is detected.
I am not sure if this is relevant, but I run in userspace with --user. Lingering is enabled for the user.
This is one of my many attempts at getting systemd to work, but like any other combination of settings, it gets stopped after 5 seconds:
[Unit]
Description=%u service with docker compose
BindsTo=podman.service
After=podman.service
[Service]
Environment=DOCKER_HOST=unix:///run/user/%U/podman/podman.sock
Environment=XDG_RUNTIME_DIR=/run/user/%U
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/srv/podman/%u
ExecStart=/usr/local/bin/docker-compose up -d --remove-orphans
ExecStop=/usr/local/bin/docker-compose down -v
[Install]
WantedBy=default.target
I start above file with systemctl --user start myservice.service. It produces an output like this:
May 04 14:10:27 myhost systemd[841]: Starting myservice service with docker compose...
May 04 14:10:27 myhost docker-compose[106023]: Container nginx Creating
May 04 14:10:27 myhost docker-compose[106023]: Container nginx Created
May 04 14:10:27 myhost docker-compose[106023]: Container nginx Starting
May 04 14:10:27 myhost docker-compose[106023]: Container nginx Started
May 04 14:10:27 myhost systemd[841]: Finished myservice service with docker compose.
May 04 14:10:32 myhost systemd[841]: Stopping myservice service with docker compose...
May 04 14:12:03 myhost systemd[841]: myservice.service: Stopping timed out. Terminating.
May 04 14:12:03 myhost systemd[841]: myservice.service: Failed with result 'timeout'.
May 04 14:12:03 myhost systemd[841]: myservice.service: Unit process 106072 (docker-compose) remains running after unit stopped.
May 04 14:12:03 myhost systemd[841]: Stopped myservice service with docker compose.
May 04 14:12:03 myhost docker-compose[106072]: Container nginx Stopping
May 04 14:12:03 myhost docker-compose[106072]: Container nginx Stopped
May 04 14:12:03 myhost docker-compose[106072]: Container nginx Removing
May 04 14:12:03 myhost docker-compose[106072]: Container nginx Removed