containers / podman

Podman: A tool for managing OCI containers and pods.
https://podman.io
Apache License 2.0
23.61k stars 2.4k forks source link

podman pod logs enhancements: when to exit #13268

Closed muayyad-alsadi closed 2 years ago

muayyad-alsadi commented 2 years ago

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind feature

Description

a way specify for podman pod logs -f

for example --exit-code-from <MY_CNT> and --exit-with-container=all | any | <CNT1,CNT2>

this might help creating a simpler systemd unit for multi-container pod

Steps to reproduce the issue:

podman pod create --name=pod_testlogs 
podman run --name=testlogs_loop1_1 -d --pod=pod_testlogs busybox /bin/sh -c 'for i in `seq 1 10000`; do echo "loop1: $i"; sleep 1; done'
podman run --name=testlogs_loop2_1 -d --pod=pod_testlogs busybox /bin/sh -c 'for i in `seq 1 10000`; do echo "loop2: $i"; sleep 3; done'
podman pod logs --tail=100 -f pod_testlogs

and then on another screen

podman run --name=testlogs_loop3_1 -d --pod=pod_testlogs busybox /bin/sh -c 'for i in `seq 1 10000`; do echo "loop3: $i"; sleep 3; done'

Describe the results you received:

podman pod logs --tail=100 -f pod_testlogs exits instantly if run after podman pod create --name=pod_testlogs

Describe the results you expected:

it should have a way to ask it wait containers to join

related to

https://github.com/containers/podman/issues/13261

muayyad-alsadi commented 2 years ago

we might be able to create systemd for an entire stack, discussion here

https://github.com/containers/podman-compose/issues/307

[Unit]
Description=%i rootless pod (podman-compose)

[Service]
WorkingDirectory=%h/.config/containers/compose/%i
# assert existence of pod
ExecStartPre=/usr/bin/podman-compose up --no-start
# start the pod
ExecStartPre=/usr/bin/podman pod start pod_%i
# wait
ExecStart=/usr/bin/podman pod logs -f pod_%i
# stop
ExecStop=/usr/bin/podman pod stop pod_%i

[Install]
WantedBy=default.target

and any suggestion to make it Type=simple or forking instead of Type=oneshot and anyway to have a pid file

Luap99 commented 2 years ago

podman pod create does not start the pod so podman logs will exit immediately because no containers are running. I think you have to run podman pod create followed by podman pod start.

muayyad-alsadi commented 2 years ago

I need to start following before starting so that I won't miss the logs in-between

$ podman pod create --name=pod_testlogs2 --infra=false --share=
$ podman pod start pod_testlogs2 ; podman pod logs -f pod_testlogs2
Error: no containers in pod 30ec21f40d4461d250ebe25f641e5092a3186d599ea2450ac6a313549424638f have no dependencies, cannot start pod: no such container
Luap99 commented 2 years ago

Ah I see because you have a pod without infra container it does not work.

muayyad-alsadi commented 2 years ago

yes, I'm attaching a stack of containers for example wordpress stack (wordpress php-fpm, nginx, memcached, mysql) or awx stack

version: '2'
services:
  web:
    image: docker.io/ansible/awx:17.1.0
    container_name: awx_web
    depends_on:
      - redis
      - postgres
    hostname: awxweb
    user: root
    restart: unless-stopped
    volumes:
      - "./SECRET_KEY:/etc/tower/SECRET_KEY"
  task:
    image: docker.io/ansible/awx:17.1.0
    container_name: awx_task
    depends_on:
      - redis
      - web
      - postgres
    command: /usr/bin/launch_awx_task.sh
    hostname: awx
    user: root
    restart: unless-stopped
    volumes:
      - "./SECRET_KEY:/etc/tower/SECRET_KEY"
  redis:
    image: redis
    container_name: awx_redis
    restart: unless-stopped
    command: ["/usr/local/etc/redis/redis.conf"]
    volumes:
      - "./redis.conf:/usr/local/etc/redis/redis.conf:ro"
      - "./redis_socket:/var/run/redis/:rw"
  postgres:
    image: postgres:12
    container_name: awx_postgres
    restart: unless-stopped
    volumes:
      - "./data/pg/12/data/:/var/lib/postgresql/data:Z"
    environment:
      POSTGRES_USER: awx
      POSTGRES_DB: awx
      http_proxy: 
      https_proxy: 
      no_proxy: 

each of them have different mounts, hostname, userns stack, ...etc. that's why I use --share= and when we share nothing the infra pod is useless and cause the podman pod ps to show it as degared (I'm not sure if this is a bug or international)

I create the pod then create containers with --requires (the wordpress container requires the mysql one) then follow the logs then start the containers

later stop the pod and start it

I hope if there is a flag to tell -f to wait for "rising containers" and only exit on first fall (after the initial rising)

github-actions[bot] commented 2 years ago

A friendly reminder that this issue had no activity for 30 days.

github-actions[bot] commented 2 years ago

A friendly reminder that this issue had no activity for 30 days.

rhatdan commented 2 years ago

@muayyad-alsadi @Luap99 where are we on this issue? Does it still exists, or did you find a workaround?

github-actions[bot] commented 2 years ago

A friendly reminder that this issue had no activity for 30 days.

github-actions[bot] commented 2 years ago

A friendly reminder that this issue had no activity for 30 days.

rhatdan commented 2 years ago

Since I have never heard back, I am going to guess this is no longer needed and close. Reopen if I am mistaken.