confd: misc. fixes and cleanup

- drop debug logs
 - no need to restart upgraded containers, they restart automatically
 - fix ordering in volume prune (when containers are removed)
 - skip directories in container activation (inbox -> execd queue)
 - Fix 'container pull IMG creds USER[:PASS]' bug, extra '=' variable
   assignment inside infix.xml
 - Fix 'container run IMG CMD ARGS' to actually put the CMD in
   ENTRYPOINT and append ARGS to image.  The podman run and create
   commands are *not* behaving the same way
 - Rename 'attach' to 'exec', execute command inside an running container
 - Add 'container [shell | connect]' to start shell in -- " -- " -- " --
 - Add 'container [stat | cleanup | usage stats]' commands
 - Add in="tty" to commands thay may end up being interactive
 - Split <ACTION> line into multiple lines for readability
 - Fix container shift logic:

     root@infix-00-00-00:/> show container
     /usr/sbin/container: line 361: shift: shift count out of range

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2024-02-25 19:49:27 +01:00
parent b7d119b23f
commit 580599f549
3 changed files with 100 additions and 27 deletions
+37 -13
View File
@@ -43,8 +43,6 @@ create()
fi
# --syslog --log-level info
log "Calling \"podman create --name $name --conmon-pidfile=$pidfn $ro $vol $mount $hostname $entrypoint $env $network $port $args $image $*\""
set -x
# shellcheck disable=SC2048
if podman create --name "$name" --conmon-pidfile="$pidfn" $ro $vol $mount $hostname $entrypoint $env $network $port $args "$image" $*; then
log "Successfully created container $name from $image"
@@ -83,6 +81,7 @@ options:
-a, --all Show all, of something
--dns NAMESERVER Set nameserver(s) when creating a container
--dns-search LIST Set host lookup search list when creating container
-d, --detach Detach a container started with 'run IMG [CMD]'
-e, --env FILE Environment variables when creating container
--entrypoint Disable container image's ENTRYPOINT, run cmd + arg
-f, --force Force operation, e.g. remove
@@ -99,12 +98,15 @@ options:
commands:
create NAME IMAGE NET Create container NAME using IMAGE with networks NET
delete NAME Kill and remove container NAME
exec NAME CMD Run a command inside a container
help Show this help text
list [image] List names (only) of containers or images
remove IMAGE Remove an (unused) container image
restart NAME Restart a crashed container
run NAME CMD Execute a command (interactively) in container
run NAME [CMD] Run a container interactively, with an optional command
shell Start a shell inside a container
show [image | volume] Show containers, images, or volumes
stat Show continuous stats about containers (Ctrl-C aborts)
start NAME Start a container
stop NAME Stop a container
volume [prune] Prune unused volumes
@@ -116,6 +118,9 @@ while [ "$1" != "" ]; do
-a | --all)
all="-a"
;;
-d | --detach)
detach="-d"
;;
--dns)
shift
dns="$dns $1"
@@ -177,9 +182,11 @@ if [ -n "$cmd" ]; then
fi
case $cmd in
attach)
podman exec -it "$1" "$2"
;;
# Does not work atm., cannot attach to TTY because
# we monitor 'podman start -ai foo' with Finit.
# attach)
# podman attach "$1"
# ;;
create)
log "Got create args: $*"
create "$@"
@@ -187,12 +194,15 @@ case $cmd in
delete)
delete "$@"
;;
exec)
podman exec -it "$@"
;;
help)
usage
;;
ls | list)
cmd=$1
shift
[ -n "$cmd" ] && shift
case $cmd in
image*)
podman images $all --format "{{.Repository}}:{{.Tag}}"
@@ -209,12 +219,24 @@ case $cmd in
podman rmi $all $force -i "$1"
;;
run)
echo "Starting container $1 :: use Ctrl-p Ctrl-q to exit"
podman run -it --rm "$@"
img=$1
cmd=$2
[ -n "$port" ] || port="-P"
if [ -n "$cmd" ]; then
shift 2
[ -n "$detach" ] || echo "Starting $img ENTRYPOINT $cmd :: use Ctrl-p Ctrl-q to detach"
podman run -it --rm $detach $port --entrypoint="$cmd" "$img" "$@"
else
[ -n "$detach" ] || echo "Starting $img :: use Ctrl-p Ctrl-q to detach"
podman run -it --rm $detach $port "$img"
fi
;;
shell)
podman exec -it "$1" sh -l
;;
show)
cmd=$1
shift
[ -n "$cmd" ] && shift
case $cmd in
image*)
if [ -n "$simple" ]; then
@@ -251,6 +273,9 @@ case $cmd in
stop)
initctl -bq stop "container:$1" || podman kill "$1"
;;
stat*)
podman stats -i 2
;;
upgrade)
img=$(podman inspect "$1" | jq -r .[].ImageName)
if [ -z "$img" ]; then
@@ -260,14 +285,13 @@ case $cmd in
podman stop "$1"
podman pull "$img" || (echo "Failed fetching $img, check your network (settings)."; exit 1)
"/var/lib/containers/active/${1}.sh" || (echo "Failed recreating container $1"; exit 1)
echo "Container $1 recreated, restart with 'container start $1'"
;;
volume)
cmd=$1
shift
[ -n "$cmd" ] && shift
case $cmd in
prune)
podman $force volume prune
podman volume $force prune
;;
*)
false
+3
View File
@@ -293,6 +293,9 @@ void infix_containers_launch(void)
char curr[strlen(ACTIVE_QUEUE) + strlen(d->d_name) + 2];
char next[strlen(INBOX_QUEUE) + strlen(d->d_name) + 2];
if (d->d_name[0] == '.')
continue;
snprintf(curr, sizeof(curr), "%s/%s", ACTIVE_QUEUE, d->d_name);
snprintf(next, sizeof(next), "%s/%s", INBOX_QUEUE, d->d_name);
if (!systemf("cmp %s %s", curr, next)) {
+60 -14
View File
@@ -184,11 +184,25 @@
</COMMAND>
<COMMAND name="container" help="Manage containers, images, and volumes" mode="switch">
<COMMAND name="attach" help="Attach to a running container (exec sh)">
<COMMAND name="cleanup" help="Clean up all unused containers, images and volume data">
<ACTION sym="script" in="tty" out="tty" interrupt="true">
podman system prune
</ACTION>
</COMMAND>
<!-- alias for -container shell' -->
<COMMAND name="connect" help="Start a shell inside a container, if available">
<PARAM name="name" ptype="/CONTAINERSa" help="Container name" />
<ACTION sym="script" in="tty" out="tty" interrupt="true">
container shell $KLISH_PARAM_name
</ACTION>
</COMMAND>
<COMMAND name="exec" help="Execute command in a running container, default: sh">
<PARAM name="name" ptype="/CONTAINERS" help="Container name" />
<SWITCH name="optional" min="0">
<COMMAND name="command" help="Command to run">
<PARAM name="command" ptype="/STRING" help="Command to run2"/>
<PARAM name="command" ptype="/STRING" help="Command to run"/>
</COMMAND>
</SWITCH>
<ACTION sym="script" in="tty" out="tty" interrupt="true">
@@ -196,7 +210,7 @@
echo "Missing container name."
else
cmd=${KLISH_PARAM_command:-sh}
container attach $KLISH_PARAM_name $cmd
container exec $KLISH_PARAM_name $cmd
fi
</ACTION>
</COMMAND>
@@ -205,45 +219,71 @@
<PARAM name="image" ptype="/STRING" help="Image url and tag, e.g. docker://hello-world:latest" />
<SWITCH name="optional" min="0">
<COMMAND name="creds" help="Credentials">
<PARAM name="creds" ptype="/STRING" help="[username[:password]]"/>
<PARAM name="creds" ptype="/STRING" help="username[:password]"/>
</COMMAND>
</SWITCH>
<ACTION sym="script" out="tty" interrupt="true">
creds==${KLISH_PARAM_creds:+--creds=$KLISH_PARAM_creds}
<ACTION sym="script" in="tty" out="tty" interrupt="true">
creds=${KLISH_PARAM_creds:+--creds=$KLISH_PARAM_creds}
container pull $creds $KLISH_PARAM_image
</ACTION>
</COMMAND>
<COMMAND name="remove" help="Remove a container image from local storage">
<PARAM name="name" ptype="/IMAGES" help="Image name" />
<ACTION sym="script" out="tty" interrupt="true">container remove $KLISH_PARAM_name</ACTION>
<ACTION sym="script" in="tty" out="tty" interrupt="true">
container remove $KLISH_PARAM_name
</ACTION>
</COMMAND>
<COMMAND name="restart" help="Restart a crashed container">
<PARAM name="name" ptype="/CONTAINERSa" help="Container name" />
<ACTION sym="script" out="tty" interrupt="true">container restart $KLISH_PARAM_name</ACTION>
<ACTION sym="script" out="tty" interrupt="true">
container restart $KLISH_PARAM_name
</ACTION>
</COMMAND>
<COMMAND name="run" help="Run a container image, with optional command">
<COMMAND name="run" help="Interactivly run a container image, with optional command">
<PARAM name="image" ptype="/IMAGES" help="Image name" />
<SWITCH name="optional" min="0">
<COMMAND name="command" help="Command to run">
<PARAM name="command" ptype="/STRING" help="Command to run2"/>
<PARAM name="command" ptype="/STRING" help="Command to run"/>
</COMMAND>
<COMMAND name="port" help="Port to publish, default all exposed">
<PARAM name="port" ptype="/STRING" help="HOST:CONTAINER[/udp]"/>
</COMMAND>
</SWITCH>
<ACTION sym="script" out="tty" interrupt="true">
container run $KLISH_PARAM_image ${KLISH_PARAM_command}
<ACTION sym="script" in="tty" out="tty" interrupt="true">
port=${KLISH_PARAM_port:+-p $KLISH_PARAM_port}
container $port run $KLISH_PARAM_image ${KLISH_PARAM_command}
</ACTION>
<SWITCH name="optional" min="0">
<COMMAND name="detach" help="Run container in background and print container ID">
<ACTION sym="script" out="tty">
container -d $port run $KLISH_PARAM_image ${KLISH_PARAM_command}
</ACTION>
</COMMAND>
</SWITCH>
</COMMAND>
<COMMAND name="shell" help="Start a shell inside a container, if available">
<PARAM name="name" ptype="/CONTAINERSa" help="Container name" />
<ACTION sym="script" in="tty" out="tty" interrupt="true">
container shell $KLISH_PARAM_name
</ACTION>
</COMMAND>
<COMMAND name="start" help="Start a container">
<PARAM name="name" ptype="/CONTAINERSa" help="Container name" />
<ACTION sym="script" out="tty" interrupt="true">container start $KLISH_PARAM_name</ACTION>
<ACTION sym="script" out="tty" interrupt="true">
container start $KLISH_PARAM_name
</ACTION>
</COMMAND>
<COMMAND name="stop" help="Stop a container">
<PARAM name="name" ptype="/CONTAINERS" help="Container name" />
<ACTION sym="script" out="tty" interrupt="true">container stop $KLISH_PARAM_name</ACTION>
<ACTION sym="script" out="tty" interrupt="true">
container stop $KLISH_PARAM_name
</ACTION>
</COMMAND>
<COMMAND name="upgrade" help="Upgrade image of a container (writable layer is lost!)">
@@ -351,6 +391,12 @@
</COMMAND>
</SWITCH>
</COMMAND>
<COMMAND name="stat" help="Show continuous containers stats (Ctrl-C aborts)">
<ACTION sym="script">container stat</ACTION>
</COMMAND>
<COMMAND name="usage" help="Show container resource usage">
<ACTION sym="script">podman system df -v</ACTION>
</COMMAND>
<COMMAND name="volumes" help="Show container volumes">
<ACTION sym="script">container show volumes</ACTION>
</COMMAND>