diff --git a/functions.sh b/functions.sh index 3ed4c8f..77e41e2 100644 --- a/functions.sh +++ b/functions.sh @@ -122,7 +122,7 @@ check_container_running () { [[ "podman container inspect -f '{{.State.Status}}' ${1}" == "running" ]] } -# ok if container exists +# ok if container is running ensure_container_running () { if ! check_container_running ${1}; then echo "ERROR : container ${1} is not running" @@ -132,7 +132,7 @@ ensure_container_running () { fi } -# ok if container does not exists +# ok if container is not running ensure_container_not_running () { if check_container_running ${1}; then echo "ERROR : container ${1} is running" diff --git a/podman-peerjs/10_install.sh b/podman-peerjs/10_install.sh index cf65be8..7f3d2e9 100755 --- a/podman-peerjs/10_install.sh +++ b/podman-peerjs/10_install.sh @@ -7,9 +7,6 @@ source ${ABSDIR}/vars.sh ensure_pwd_is_scriptdir ensure_not_root -check_container_exists ${container_name} && { - echo container ${container_name} alredy exists, please remove it first. - exit 1 -} +ensure_container_not_exists ${container_name} podman run --name ${container_name} --user nobody -p ${listen_if}:${listen_port}:9000 -d ${upstream_image}:${upstream_version} diff --git a/podman-peerjs/20_enable.sh b/podman-peerjs/20_enable.sh index 203e3d6..0c0c92a 100755 --- a/podman-peerjs/20_enable.sh +++ b/podman-peerjs/20_enable.sh @@ -7,13 +7,10 @@ source ${ABSDIR}/vars.sh ensure_pwd_is_scriptdir ensure_not_root -check_container_exists ${container_name} || { - echo container ${container_name} must exist in order to add it to systemd - exit 1 -} +ensure_container_exists ${container_name} ensure_systemd_as_user_dir_exists -podman generate systemd --name ${container_name} > ${HOME}/.config/systemd/user/${service_name} +podman generate systemd --name ${container_name} > ${HOME}/.config/systemd/user/${service_name} podman stop ${container_name} -systemctl --user --now enable ${service_name} +systemctl --user enable ${service_name} diff --git a/podman-peerjs/30_start.sh b/podman-peerjs/30_start.sh index 5f6fe21..02d21b8 100755 --- a/podman-peerjs/30_start.sh +++ b/podman-peerjs/30_start.sh @@ -8,31 +8,16 @@ ensure_pwd_is_scriptdir ensure_not_root # FAIL if container does not exists. -check_container_exists ${container_name} || { - echo Container ${container_name} does not exists. - echo Please create it first with install script. - exit 1 -} +ensure_container_exists ${container_name} # FAIL if systemd unit does not exists. -check_systemd_unit_exists ${service_name} || { - echo Systemd unit for this container does not exists. - echo Please create if first with enable script. - exit 1 -} +ensure_systemd_unit_exists ${service_name} # FAIL if systemd unit is running. -check_systemd_unit_running ${service_name} && { - echo Service ${service_name} is already running. - exit 1 -} +ensure_systemd_unit_not_running ${service_name} # FAIL if container is already running - without systemd control. -check_container_running ${container_name} && { - echo Container ${container_name} is already running, but not controlled by systemd. - echo Stop it first and rerun this script. - exit 1 -} +ensure_container_not_running ${container_name} # OK echo "Starting container through systemd" diff --git a/podman-peerjs/40_stop.sh b/podman-peerjs/40_stop.sh index dba94f4..a7e3e33 100755 --- a/podman-peerjs/40_stop.sh +++ b/podman-peerjs/40_stop.sh @@ -7,21 +7,14 @@ source ${ABSDIR}/vars.sh ensure_pwd_is_scriptdir ensure_not_root -check_container_exists ${container_name} || { - echo Container ${container_name} does not exists. - exit 1 -} +ensure_container_exists ${container_name} +# Check of running through systemd (as it should be) if check_systemd_unit_exists ${service_name}; then - # WARN if systemd unit not running, but continue. - check_systemd_unit_running ${service_name} || { - echo Service ${service_name} is not in running state. - systemctl --user status ${service_name} - } - # Stopping with systemd - systemctl --user stop ${service_name} - exit 0 -} + if check_systemd_unit_running ${service_name}; then + systemctl --user stop ${service_name} + fi +fi # Check if running through podman (no systemd), stop with podman stop , then exit if check_container_running ${container_name}; then diff --git a/podman-peerjs/70_disable.sh b/podman-peerjs/70_disable.sh index ebc9093..3c5ee57 100755 --- a/podman-peerjs/70_disable.sh +++ b/podman-peerjs/70_disable.sh @@ -7,14 +7,7 @@ source ${ABSDIR}/vars.sh ensure_pwd_is_scriptdir ensure_not_root -check_container_exists ${container_name} || { - echo Container ${container_name} does not exists - exit 1 -} - -check_systemd_unit_exists ${service_name} || { - echo "Systemd unit ${service_name} does not exists" - exit 1 -} +ensure_container_exists ${container_name} +ensure_systemd_unit_exists ${service_name} systemctl --user --now disable ${service_name} diff --git a/podman-peerjs/80_destroy.sh b/podman-peerjs/80_destroy.sh index 76aecdd..43d8664 100755 --- a/podman-peerjs/80_destroy.sh +++ b/podman-peerjs/80_destroy.sh @@ -8,22 +8,13 @@ ensure_pwd_is_scriptdir ensure_not_root # FAIL if container does not exists -check_container_exists ${container_name} || { - echo Container ${container_name} does not exists. - exit 1 -} +ensure_container_exists ${container_name} # FAIL if systemd unit is running -check_systemd_unit_running ${service_name} && { - echo Systemd unit ${service_name} is running. Stop it first. - exit 1 -} +ensure_systemd_unit_not_running ${service_name} # FAIL if container is running -check_container_running ${container_name} || { - echo Container ${container_name} is running. Stop it first. - exit 1 -} +ensure_container_not_running ${container_name} rm -f ${HOME}/.config/systemd/user/${service_name} systemctl --user disable ${service_name} diff --git a/podman-peerjs/90_prune.sh b/podman-peerjs/90_prune.sh index afa6e1f..a68e5ef 100755 --- a/podman-peerjs/90_prune.sh +++ b/podman-peerjs/90_prune.sh @@ -7,14 +7,10 @@ source ${ABSDIR}/vars.sh ensure_pwd_is_scriptdir ensure_not_root -check_systemd_unit_exists ${service_name} && { - echo "Systemd unit ${service_name} exists. Please destroy first." - exit 1 -} +# FAIL if systemd unit exists +ensure_systemd_unit_not_exists ${service_name} -check_container_exists ${container_name} && { - echo "Container ${container_name} exists. Please destroy first." - exit 1 -} +# FAIL if container exists +ensure_container_not_exists ${container_name} podman rmi "$(podman images -a -q -- ${upstream_image})"