podman-compose icon indicating copy to clipboard operation
podman-compose copied to clipboard

Support handling SIGINT when running any "up" command

Open criess opened this issue 2 years ago • 8 comments

It should be trapped the same way docker-compose does:

When up command was invoked and podman-compose process receives SIGINT (e.g. from keyboard by Ctrl+C'ing) it should trap this signal and bring all containers down in a controlled manner and then end itself as decribed here:

  • https://github.com/docker/compose/blob/v2/docs/reference/compose_up.md

I am open for discussion, whether this makes sense or not but it can be considered a usability feature for developers using the shell builtin keyboard shortcuts (or any other means) to send signals to a process (the Ctrl+C'ing is my usecase basically)

criess avatar Feb 23 '22 10:02 criess

it is most annoying when pressing ctrl+c that I've got a container that is still spamming to the terminal

ztane avatar May 03 '22 05:05 ztane

Is there any workaround possible? Especially when compose is used for test setups, being unable to shut it down is a show stopper

universam1 avatar May 25 '22 07:05 universam1

@universam1 workaround? Sure. Just run: podman-compose down

typekpb avatar Jul 06 '22 04:07 typekpb

This would also be incredibly useful for systemd units. The commonly used method to start {podman,docker}-compose systemd is with oneshot and RemainAfterExit (and -d in ExecStart). When the service is launched that way, systemd won't know when and how it terminates. I could even stop or bring down the container myself and systemd would still think it's running. Because of that, it is currently difficult to make sure a service is up.

I'm struggling every time to make these systemd units resilient because Type=simple and ExecStop don't appear to go along well.

With podman handling SIGTERM/SIGINT, it would be possible to use Type=simple directly (without having to anything extra). Maybe an additional parameter --down-on-exit prevents it from interfering with existing setups.

Just to illustrate what it could look like:

Type=simple
ExecStart=/usr/bin/podman-compose up --down-on-exit --remove-orphans
Restart=always
RestartSec=10

yogo1212 avatar Sep 25 '22 06:09 yogo1212

The current behavior of podman-compose up appears to be similar to podman-compose logs -f, as it does not handle container shutdown.

A temporary solution is, create run-podman-compose.sh

#!/bin/bash

# Function to clean up containers on Ctrl+C
cleanup() {
    echo "Cleaning up containers..."
    podman-compose down
}

# Trap Ctrl+C and call the cleanup function
trap cleanup SIGINT

# Run podman-compose in the foreground
podman-compose up

and use run-podman-compose.sh instead of podman-compose up

akhiljalagam avatar Sep 16 '23 19:09 akhiljalagam

As someone moving from Docker + Docker Compose -> Podman + Podman Compose, this really caught me off guard. IMO this is a small UX feature that should really be replicated from Docker Compose. I'm not sure how representative my workflow is, but it's a constant stream of docker compose up -> Ctrl+C -> docker compose up -> Ctrl+C -> ...

mschwager avatar Mar 20 '24 11:03 mschwager

Upon closer inspection, it looks like perhaps SIGINT is expected to work:

https://github.com/containers/podman-compose/blob/d704622522c3b4e517b084ad87bd4a15a29311c3/podman_compose.py#L2283-L2303

Is there some weird interaction with the scoping of tasks here? In other words, when the lambda is created, tasks is empty. It is then populated, and SIGINT is likely (but not always) handled after the containers are started.

mschwager avatar Mar 20 '24 11:03 mschwager

It appears the SIGINT handling code hasn't been released yet. It was committed in Feb 2024: https://github.com/containers/podman-compose/commit/38b13a34eaaff02538aec8b7d35ee98b48884c8c. Looks like the current Podman Compose version is 1.0.6, and the start of version 1.0.7 was committed in Apr 2023: https://github.com/containers/podman-compose/commit/7f5ce26b1b8103f48d5702dce7d52afe8b76daa5.

Looks like this project may be lacking support: https://github.com/containers/podman-compose/issues/825.

mschwager avatar Mar 20 '24 11:03 mschwager