feat(ssh): improve the flow of logs and improve session management

This commit is contained in:
yeti 2025-04-18 02:56:25 +01:00
parent c4e196f4af
commit 3d176b09d1

View File

@ -60,29 +60,30 @@ rw)
# Run $TMUX_CMD session inside the container
if ! podman exec -it --user "$DEV_USER" "$CONTAINER" "${TMUX_CMD[@]}" has-session -t "$TMUX_SESSION" >/dev/null 2>&1; then
if ! podman exec -it --user "$DEV_USER" "$CONTAINER" "${TMUX_CMD[@]}" new-session -s "$TMUX_SESSION" >/dev/null 2>&1; then
if ! podman exec -it --user "$DEV_USER" "$CONTAINER" "${TMUX_CMD[@]}" new-session -d -s "$TMUX_SESSION" >/dev/null 2>&1; then
log "❌ Could not create new ${TMUX_CMD[*]} session. Please contact admin or try again later."
exit 1
fi
else
log "$PERSON is logging in..."
if ! podman exec -it --user "$DEV_USER" "$CONTAINER" "${TMUX_CMD[@]}" attach -t "$TMUX_SESSION"; then
log "❌ Could not attach to ${TMUX_CMD[*]} session. Please contact admin or try again later."
exit 1
fi
fi
log "$PERSON is working on $CONTAINER"
if ! podman exec -it --user "$DEV_USER" "$CONTAINER" "${TMUX_CMD[@]}" attach -t "$TMUX_SESSION"; then
log "❌ Could not attach to ${TMUX_CMD[*]} session. Please contact admin or try again later."
exit 1
fi
log "$PERSON finished working on $CONTAINER"
check_devuser_attached
exit 0
;;
ro)
if (podman container exists "$CONTAINER" && podman inspect -f '{{.State.Running}}' "$CONTAINER" | grep -q true) >/dev/null 2>&1; then
log "📜 $PERSON is viewing..."
if podman exec -it --user "$DEV_USER" "$CONTAINER" "${TMUX_CMD[@]}" attach -r -t "$TMUX_SESSION"; then
log "📜 $PERSON is viewing $CONTAINER"
if ! podman exec -it --user "$DEV_USER" "$CONTAINER" "${TMUX_CMD[@]}" attach -r -t "$TMUX_SESSION"; then
log "❌ Could not attach to ${TMUX_CMD[*]} session. Please contact admin or try again later."
exit 1
fi
log "🏃 $PERSON stopped viewing..."
log "🏃 $PERSON stopped viewing $CONTAINER"
exit 0
else
log "❌ Container $CONTAINER does not exist."