2022-02-10 21:10:02 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
ABSDIR="$( dirname "$(realpath -s -- "$0")" )"
|
2023-07-29 14:48:12 +00:00
|
|
|
source "${ABSDIR}"/../functions.sh
|
|
|
|
source "${ABSDIR}"/vars.sh
|
2022-02-10 21:10:02 +00:00
|
|
|
|
|
|
|
ensure_pwd_is_scriptdir
|
|
|
|
ensure_not_root
|
|
|
|
|
2023-07-29 14:48:12 +00:00
|
|
|
ensure_container_exists "${container_name}"
|
2022-02-10 21:10:02 +00:00
|
|
|
|
|
|
|
# Check of running through systemd (as it should be)
|
2023-07-29 14:48:12 +00:00
|
|
|
if check_systemd_unit_exists "${service_name}"; then
|
|
|
|
if check_systemd_unit_running "${service_name}"; then
|
|
|
|
systemctl --user stop "${service_name}" &&
|
|
|
|
echo Systemd service "${service_name}" stopped.
|
2022-02-10 21:10:02 +00:00
|
|
|
fi
|
2022-02-12 12:11:28 +00:00
|
|
|
# Leave if container is correctly stopped
|
2023-07-29 14:48:12 +00:00
|
|
|
if ! check_container_running "${container_name}"; then
|
2022-02-12 12:11:28 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
2022-02-10 21:10:02 +00:00
|
|
|
fi
|
|
|
|
|
2023-04-21 11:53:55 +00:00
|
|
|
# Check if running through podman (no systemd), stop with podman container stop , then exit
|
2023-07-29 14:48:12 +00:00
|
|
|
if check_container_running "${container_name}"; then
|
2022-02-10 21:10:02 +00:00
|
|
|
echo Container found running without systemd unit, stopping it now.
|
2023-07-29 14:48:12 +00:00
|
|
|
podman container stop "${container_name}"
|
2022-02-10 21:10:02 +00:00
|
|
|
exit 0
|
|
|
|
else
|
2023-07-29 14:48:12 +00:00
|
|
|
echo Container "${container_name}" is not running.
|
2022-02-10 21:10:02 +00:00
|
|
|
exit 1
|
|
|
|
fi
|