Skip to content

Commit fb309b2

Browse files
committed
fix
1 parent 87b12b9 commit fb309b2

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

Github/Runners/run_linux.sh

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,30 @@ cleanup_on_exit() {
6767
fi
6868
CLEANUP_DONE=1
6969

70+
# Only proceed with cleanup if we're actually running containers
71+
if [[ "${ACTION:-}" == "cleanup" || "${ACTION:-}" == "stop" || "${ACTION:-}" == "logs" || "${ACTION:-}" == "status" ]]; then
72+
return
73+
fi
74+
7075
log_warn "Received exit signal, cleaning up..."
7176

72-
if [[ -n "${CONTAINER_ID}" ]]; then
77+
if [[ -n "${CONTAINER_ID:-}" ]]; then
7378
log_info "Stopping container: ${CONTAINER_ID}"
74-
${PODMAN_SUDO} podman stop "${CONTAINER_ID}" --time 10 &>/dev/null || true
79+
${PODMAN_SUDO:-} podman stop "${CONTAINER_ID}" --time 10 &>/dev/null || true
7580

7681
log_info "Removing container: ${CONTAINER_ID}"
77-
${PODMAN_SUDO} podman rm "${CONTAINER_ID}" --force &>/dev/null || true
82+
${PODMAN_SUDO:-} podman rm "${CONTAINER_ID}" --force &>/dev/null || true
7883
fi
7984

8085
#Clean up any containers with our name
81-
local cleanup_containers=()
82-
readarray -t cleanup_containers < <(${PODMAN_SUDO} podman ps -aq --filter "name=${CONTAINER_NAME}" 2>/dev/null || true)
83-
if [[ ${#cleanup_containers[@]} -gt 0 && -n "${cleanup_containers[0]}" ]]; then
84-
log_info "Cleaning up remaining containers with name: ${CONTAINER_NAME}"
85-
printf '%s\n' "${cleanup_containers[@]}" | xargs -r ${PODMAN_SUDO} podman stop --time 10 &>/dev/null || true
86-
printf '%s\n' "${cleanup_containers[@]}" | xargs -r ${PODMAN_SUDO} podman rm --force &>/dev/null || true
86+
if [[ -n "${CONTAINER_NAME:-}" && -n "${PODMAN_SUDO+x}" ]]; then
87+
local cleanup_containers=()
88+
readarray -t cleanup_containers < <(${PODMAN_SUDO} podman ps -aq --filter "name=${CONTAINER_NAME}" 2>/dev/null || true)
89+
if [[ ${#cleanup_containers[@]} -gt 0 && -n "${cleanup_containers[0]}" ]]; then
90+
log_info "Cleaning up remaining containers with name: ${CONTAINER_NAME}"
91+
printf '%s\n' "${cleanup_containers[@]}" | xargs -r ${PODMAN_SUDO} podman stop --time 10 &>/dev/null || true
92+
printf '%s\n' "${cleanup_containers[@]}" | xargs -r ${PODMAN_SUDO} podman rm --force &>/dev/null || true
93+
fi
8794
fi
8895

8996
log_info "Cleanup completed"
@@ -588,15 +595,21 @@ run_container() {
588595
#------------------------------------------------------------------------------------#
589596
#Main function
590597
main() {
591-
# Set up signal handlers early
592-
setup_signal_handlers
593-
594598
#Parse command line arguments
595599
parse_arguments "$@"
596600

597601
#Set configuration
598602
set_configuration
603+
604+
#Set up signal handlers early
605+
setup_signal_handlers
606+
607+
#Validate requirements
608+
validate_requirements
599609

610+
#Check sudo requirements
611+
check_sudo_requirements
612+
600613
#Handle special actions first
601614
case "${ACTION:-}" in
602615
cleanup)
@@ -617,12 +630,6 @@ main() {
617630
;;
618631
esac
619632

620-
#Validate requirements
621-
validate_requirements
622-
623-
#Check sudo requirements
624-
check_sudo_requirements
625-
626633
#Show configuration
627634
show_configuration
628635

0 commit comments

Comments
 (0)