From ed9972aad1bf8e72f75b4e400c4cda75bc7cdc93 Mon Sep 17 00:00:00 2001 From: Gitouche <26656-gitouche@users.noreply.framagit.org> Date: Thu, 10 Feb 2022 22:10:02 +0100 Subject: [PATCH] peerjs : standardisation scripts container (pas de pod) --- _podman-common/00_status_container.sh | 19 +++++++++++++++++ _podman-common/20_enable_container.sh | 20 ++++++++++++++++++ _podman-common/30_start_container.sh | 24 +++++++++++++++++++++ _podman-common/40_stop_container.sh | 28 +++++++++++++++++++++++++ _podman-common/70_disable_container.sh | 19 +++++++++++++++++ _podman-common/80_destroy_container.sh | 20 ++++++++++++++++++ _podman-common/90_prune_container.sh | 22 +++++++++++++++++++ podman-peerjs/00_status.sh | 20 +----------------- podman-peerjs/20_enable.sh | 21 +------------------ podman-peerjs/30_start.sh | 25 +--------------------- podman-peerjs/40_stop.sh | 29 +------------------------- podman-peerjs/70_disable.sh | 20 +----------------- podman-peerjs/80_destroy.sh | 21 +------------------ podman-peerjs/90_prune.sh | 23 +------------------- 14 files changed, 159 insertions(+), 152 deletions(-) create mode 100755 _podman-common/00_status_container.sh create mode 100755 _podman-common/20_enable_container.sh create mode 100755 _podman-common/30_start_container.sh create mode 100755 _podman-common/40_stop_container.sh create mode 100755 _podman-common/70_disable_container.sh create mode 100755 _podman-common/80_destroy_container.sh create mode 100755 _podman-common/90_prune_container.sh mode change 100755 => 120000 podman-peerjs/00_status.sh mode change 100755 => 120000 podman-peerjs/20_enable.sh mode change 100755 => 120000 podman-peerjs/30_start.sh mode change 100755 => 120000 podman-peerjs/40_stop.sh mode change 100755 => 120000 podman-peerjs/70_disable.sh mode change 100755 => 120000 podman-peerjs/80_destroy.sh mode change 100755 => 120000 podman-peerjs/90_prune.sh diff --git a/_podman-common/00_status_container.sh b/_podman-common/00_status_container.sh new file mode 100755 index 0000000..bdfda4c --- /dev/null +++ b/_podman-common/00_status_container.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +ABSDIR="$( dirname "$(realpath -s -- "$0")" )" +source ${ABSDIR}/../functions.sh +source ${ABSDIR}/vars.sh + +ensure_pwd_is_scriptdir +ensure_not_root + +echo "Podman images status..." +for image in ${upstream_images} ; do + podman images ${image} | grep ${image} || echo Image ${image} not found. +done +echo +echo "Checking container status..." +podman ps -a | grep ${container_name} || echo container ${container_name} not found. +echo +echo "Checking systemd unit status..." +systemctl --user status ${service_name} diff --git a/_podman-common/20_enable_container.sh b/_podman-common/20_enable_container.sh new file mode 100755 index 0000000..3720f22 --- /dev/null +++ b/_podman-common/20_enable_container.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +ABSDIR="$( dirname "$(realpath -s -- "$0")" )" +source ${ABSDIR}/../functions.sh +source ${ABSDIR}/vars.sh + +ensure_pwd_is_scriptdir +ensure_not_root + +# container should exist +ensure_container_exists ${container_name} +# container should NOT be running. Installation script must have stopped it. +ensure_container_not_running ${container_name} + +ensure_systemd_as_user_dir_exists + +podman generate systemd --files --name ${container_name} +mv *.service ~/.config/systemd/user/ + +systemctl --user enable ${service_name} diff --git a/_podman-common/30_start_container.sh b/_podman-common/30_start_container.sh new file mode 100755 index 0000000..16f2608 --- /dev/null +++ b/_podman-common/30_start_container.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +ABSDIR="$( dirname "$(realpath -s -- "$0")" )" +source ${ABSDIR}/../functions.sh +source ${ABSDIR}/vars.sh + +ensure_pwd_is_scriptdir +ensure_not_root + +# FAIL if container does not exists. +ensure_container_exists ${container_name} + +# FAIL if systemd unit does not exists. +ensure_systemd_unit_exists ${service_name} + +# FAIL if systemd unit is running. +ensure_systemd_unit_not_running ${service_name} + +# FAIL if container is already running - without systemd control. +ensure_container_not_running ${container_name} + +# OK +echo "Starting container through systemd" +systemctl --user start ${service_name} diff --git a/_podman-common/40_stop_container.sh b/_podman-common/40_stop_container.sh new file mode 100755 index 0000000..dcd9e06 --- /dev/null +++ b/_podman-common/40_stop_container.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +ABSDIR="$( dirname "$(realpath -s -- "$0")" )" +source ${ABSDIR}/../functions.sh +source ${ABSDIR}/vars.sh + +ensure_pwd_is_scriptdir +ensure_not_root + +ensure_container_exists ${container_name} + +# Check of running through systemd (as it should be) +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. + fi +fi + +# Check if running through podman (no systemd), stop with podman stop , then exit +if check_container_running ${container_name}; then + echo Container found running without systemd unit, stopping it now. + podman stop ${container_name} + exit 0 +else + echo Container ${container_name} is not running. + exit 1 +fi diff --git a/_podman-common/70_disable_container.sh b/_podman-common/70_disable_container.sh new file mode 100755 index 0000000..6a3793f --- /dev/null +++ b/_podman-common/70_disable_container.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +ABSDIR="$( dirname "$(realpath -s -- "$0")" )" +source ${ABSDIR}/../functions.sh +source ${ABSDIR}/vars.sh + +ensure_pwd_is_scriptdir +ensure_not_root + +# FAIL if container does not exists +ensure_container_exists ${container_name} + +# FAIL if systemd unit does not exists +ensure_systemd_unit_exists ${service_name} + +# FAIL if systemd unit is running (stop it first) +ensure_systemd_unit_not_running ${service_name} + +systemctl --user disable ${service_name} diff --git a/_podman-common/80_destroy_container.sh b/_podman-common/80_destroy_container.sh new file mode 100755 index 0000000..4697dfe --- /dev/null +++ b/_podman-common/80_destroy_container.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +ABSDIR="$( dirname "$(realpath -s -- "$0")" )" +source ${ABSDIR}/../functions.sh +source ${ABSDIR}/vars.sh + +ensure_pwd_is_scriptdir +ensure_not_root + +# FAIL if container does not exists +ensure_container_exists ${container_name} + +# FAIL if container is running +ensure_container_not_running ${container_name} + +${ABSDIR}/70_disable.sh + +rm -f ${HOME}/.config/systemd/user/${service_name} +systemctl --user daemon-reload +podman rm ${container_name} diff --git a/_podman-common/90_prune_container.sh b/_podman-common/90_prune_container.sh new file mode 100755 index 0000000..d33c1a2 --- /dev/null +++ b/_podman-common/90_prune_container.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +ABSDIR="$( dirname "$(realpath -s -- "$0")" )" +source ${ABSDIR}/../functions.sh +source ${ABSDIR}/vars.sh + +ensure_pwd_is_scriptdir +ensure_not_root + +# FAIL if container is running +ensure_container_not_running ${container_name} + +# FAIL if container exists +ensure_container_not_exists ${container_name} + +# FAIL if systemd unit exists +ensure_systemd_unit_not_exists ${service_name} + +# remove images +for image in ${upstream_images} ; do + podman rmi $(podman images -a -q -- ${image}) || echo Image ${image} not found. +done diff --git a/podman-peerjs/00_status.sh b/podman-peerjs/00_status.sh deleted file mode 100755 index bdfda4c..0000000 --- a/podman-peerjs/00_status.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -ABSDIR="$( dirname "$(realpath -s -- "$0")" )" -source ${ABSDIR}/../functions.sh -source ${ABSDIR}/vars.sh - -ensure_pwd_is_scriptdir -ensure_not_root - -echo "Podman images status..." -for image in ${upstream_images} ; do - podman images ${image} | grep ${image} || echo Image ${image} not found. -done -echo -echo "Checking container status..." -podman ps -a | grep ${container_name} || echo container ${container_name} not found. -echo -echo "Checking systemd unit status..." -systemctl --user status ${service_name} diff --git a/podman-peerjs/00_status.sh b/podman-peerjs/00_status.sh new file mode 120000 index 0000000..89a8a9b --- /dev/null +++ b/podman-peerjs/00_status.sh @@ -0,0 +1 @@ +../_podman-common/00_status_container.sh \ No newline at end of file diff --git a/podman-peerjs/20_enable.sh b/podman-peerjs/20_enable.sh deleted file mode 100755 index 3720f22..0000000 --- a/podman-peerjs/20_enable.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -ABSDIR="$( dirname "$(realpath -s -- "$0")" )" -source ${ABSDIR}/../functions.sh -source ${ABSDIR}/vars.sh - -ensure_pwd_is_scriptdir -ensure_not_root - -# container should exist -ensure_container_exists ${container_name} -# container should NOT be running. Installation script must have stopped it. -ensure_container_not_running ${container_name} - -ensure_systemd_as_user_dir_exists - -podman generate systemd --files --name ${container_name} -mv *.service ~/.config/systemd/user/ - -systemctl --user enable ${service_name} diff --git a/podman-peerjs/20_enable.sh b/podman-peerjs/20_enable.sh new file mode 120000 index 0000000..62674d2 --- /dev/null +++ b/podman-peerjs/20_enable.sh @@ -0,0 +1 @@ +../_podman-common/20_enable_container.sh \ No newline at end of file diff --git a/podman-peerjs/30_start.sh b/podman-peerjs/30_start.sh deleted file mode 100755 index 16f2608..0000000 --- a/podman-peerjs/30_start.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash - -ABSDIR="$( dirname "$(realpath -s -- "$0")" )" -source ${ABSDIR}/../functions.sh -source ${ABSDIR}/vars.sh - -ensure_pwd_is_scriptdir -ensure_not_root - -# FAIL if container does not exists. -ensure_container_exists ${container_name} - -# FAIL if systemd unit does not exists. -ensure_systemd_unit_exists ${service_name} - -# FAIL if systemd unit is running. -ensure_systemd_unit_not_running ${service_name} - -# FAIL if container is already running - without systemd control. -ensure_container_not_running ${container_name} - -# OK -echo "Starting container through systemd" -systemctl --user start ${service_name} diff --git a/podman-peerjs/30_start.sh b/podman-peerjs/30_start.sh new file mode 120000 index 0000000..784face --- /dev/null +++ b/podman-peerjs/30_start.sh @@ -0,0 +1 @@ +../_podman-common/30_start_container.sh \ No newline at end of file diff --git a/podman-peerjs/40_stop.sh b/podman-peerjs/40_stop.sh deleted file mode 100755 index dcd9e06..0000000 --- a/podman-peerjs/40_stop.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash - -ABSDIR="$( dirname "$(realpath -s -- "$0")" )" -source ${ABSDIR}/../functions.sh -source ${ABSDIR}/vars.sh - -ensure_pwd_is_scriptdir -ensure_not_root - -ensure_container_exists ${container_name} - -# Check of running through systemd (as it should be) -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. - fi -fi - -# Check if running through podman (no systemd), stop with podman stop , then exit -if check_container_running ${container_name}; then - echo Container found running without systemd unit, stopping it now. - podman stop ${container_name} - exit 0 -else - echo Container ${container_name} is not running. - exit 1 -fi diff --git a/podman-peerjs/40_stop.sh b/podman-peerjs/40_stop.sh new file mode 120000 index 0000000..3d0c193 --- /dev/null +++ b/podman-peerjs/40_stop.sh @@ -0,0 +1 @@ +../_podman-common/40_stop_container.sh \ No newline at end of file diff --git a/podman-peerjs/70_disable.sh b/podman-peerjs/70_disable.sh deleted file mode 100755 index 6a3793f..0000000 --- a/podman-peerjs/70_disable.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -ABSDIR="$( dirname "$(realpath -s -- "$0")" )" -source ${ABSDIR}/../functions.sh -source ${ABSDIR}/vars.sh - -ensure_pwd_is_scriptdir -ensure_not_root - -# FAIL if container does not exists -ensure_container_exists ${container_name} - -# FAIL if systemd unit does not exists -ensure_systemd_unit_exists ${service_name} - -# FAIL if systemd unit is running (stop it first) -ensure_systemd_unit_not_running ${service_name} - -systemctl --user disable ${service_name} diff --git a/podman-peerjs/70_disable.sh b/podman-peerjs/70_disable.sh new file mode 120000 index 0000000..83e4e91 --- /dev/null +++ b/podman-peerjs/70_disable.sh @@ -0,0 +1 @@ +../_podman-common/70_disable_container.sh \ No newline at end of file diff --git a/podman-peerjs/80_destroy.sh b/podman-peerjs/80_destroy.sh deleted file mode 100755 index 4697dfe..0000000 --- a/podman-peerjs/80_destroy.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -ABSDIR="$( dirname "$(realpath -s -- "$0")" )" -source ${ABSDIR}/../functions.sh -source ${ABSDIR}/vars.sh - -ensure_pwd_is_scriptdir -ensure_not_root - -# FAIL if container does not exists -ensure_container_exists ${container_name} - -# FAIL if container is running -ensure_container_not_running ${container_name} - -${ABSDIR}/70_disable.sh - -rm -f ${HOME}/.config/systemd/user/${service_name} -systemctl --user daemon-reload -podman rm ${container_name} diff --git a/podman-peerjs/80_destroy.sh b/podman-peerjs/80_destroy.sh new file mode 120000 index 0000000..97efd57 --- /dev/null +++ b/podman-peerjs/80_destroy.sh @@ -0,0 +1 @@ +../_podman-common/80_destroy_container.sh \ No newline at end of file diff --git a/podman-peerjs/90_prune.sh b/podman-peerjs/90_prune.sh deleted file mode 100755 index d33c1a2..0000000 --- a/podman-peerjs/90_prune.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash - -ABSDIR="$( dirname "$(realpath -s -- "$0")" )" -source ${ABSDIR}/../functions.sh -source ${ABSDIR}/vars.sh - -ensure_pwd_is_scriptdir -ensure_not_root - -# FAIL if container is running -ensure_container_not_running ${container_name} - -# FAIL if container exists -ensure_container_not_exists ${container_name} - -# FAIL if systemd unit exists -ensure_systemd_unit_not_exists ${service_name} - -# remove images -for image in ${upstream_images} ; do - podman rmi $(podman images -a -q -- ${image}) || echo Image ${image} not found. -done diff --git a/podman-peerjs/90_prune.sh b/podman-peerjs/90_prune.sh new file mode 120000 index 0000000..9c9670b --- /dev/null +++ b/podman-peerjs/90_prune.sh @@ -0,0 +1 @@ +../_podman-common/90_prune_container.sh \ No newline at end of file