[experimental] peerjs : cleanup
This commit is contained in:
parent
9adbb1da5f
commit
832c3c1940
16
functions.sh
16
functions.sh
|
@ -28,3 +28,19 @@ ensure_pwd_is_scriptdir () {
|
|||
ensure_systemd_as_user_dir_exists () {
|
||||
mkdir -p ${HOME}/.config/systemd/user/
|
||||
}
|
||||
|
||||
check_systemd_unit_exists () {
|
||||
systemctl --user cat -- ${1} &> /dev/null
|
||||
}
|
||||
|
||||
check_systemd_unit_running () {
|
||||
systemctl --user is-active --quiet service ${1}
|
||||
}
|
||||
|
||||
check_container_exists () {
|
||||
podman container exists ${1}
|
||||
}
|
||||
|
||||
check_container_running () {
|
||||
[[ $("podman container inspect -f '{{.State.Status}}' ${1}") == "running" ]] || exit 1
|
||||
}
|
||||
|
|
15
podman-peerjs/00_status.sh
Executable file
15
podman-peerjs/00_status.sh
Executable file
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
ABSDIR="$( dirname "$(readlink -f -- "$0")" )"
|
||||
source ${ABSDIR}/../functions.sh
|
||||
source ${ABSDIR}/vars.sh
|
||||
|
||||
ensure_pwd_is_scriptdir
|
||||
ensure_not_root
|
||||
|
||||
echo "Checking podman images..."
|
||||
podman images ${image_name}
|
||||
echo "Checking container status..."
|
||||
podman ps -a | grep ${container_name}
|
||||
echo "Checking systemd unit status..."
|
||||
systemctl --user status ${service_name}
|
|
@ -7,10 +7,9 @@ source ${ABSDIR}/vars.sh
|
|||
ensure_pwd_is_scriptdir
|
||||
ensure_not_root
|
||||
|
||||
if podman container exists ${container_name}; then
|
||||
check_container_exists ${container_name} && {
|
||||
echo container ${container_name} alredy exists, please remove it first.
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
podman run --name ${container_name} --user nobody -p ${listen_if}:${listen_port}:9000 -d ${upstream_image}:${upstream_version}
|
||||
|
||||
|
|
|
@ -7,13 +7,13 @@ source ${ABSDIR}/vars.sh
|
|||
ensure_pwd_is_scriptdir
|
||||
ensure_not_root
|
||||
|
||||
if ! podman container exists ${container_name}; then
|
||||
check_container_exists ${container_name} || {
|
||||
echo container ${container_name} must exist in order to add it to systemd
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
ensure_systemd_as_user_dir_exists
|
||||
podman generate systemd --name ${container_name} > ~/.config/systemd/user/${service_name}
|
||||
podman generate systemd --name ${container_name} > ${HOME}/.config/systemd/user/${service_name}
|
||||
|
||||
podman stop ${container_name}
|
||||
systemctl --user enable ${service_name}
|
||||
|
|
|
@ -7,11 +7,33 @@ source ${ABSDIR}/vars.sh
|
|||
ensure_pwd_is_scriptdir
|
||||
ensure_not_root
|
||||
|
||||
if systemctl --user is-active --quiet service ${service_name}; then
|
||||
# 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
|
||||
}
|
||||
|
||||
# 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
|
||||
}
|
||||
|
||||
# FAIL if systemd unit is running.
|
||||
check_systemd_unit_running ${service_name} && {
|
||||
echo Service ${service_name} is already running.
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Add check if running, ask to stop it first, then exit.
|
||||
# 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
|
||||
}
|
||||
|
||||
# OK
|
||||
echo "Starting container through systemd"
|
||||
systemctl --user start ${service_name}
|
||||
|
|
|
@ -7,11 +7,28 @@ source ${ABSDIR}/vars.sh
|
|||
ensure_pwd_is_scriptdir
|
||||
ensure_not_root
|
||||
|
||||
if ! systemctl --user is-active --quiet service ${service_name}; then
|
||||
echo Service ${service_name} is already stopped.
|
||||
check_container_exists ${container_name} || {
|
||||
echo Container ${container_name} does not exists.
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
# Check if running through podman (no systemd), stop with podman stop , then exit
|
||||
|
||||
systemctl --user stop ${service_name}
|
||||
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
|
||||
|
|
|
@ -7,10 +7,14 @@ source ${ABSDIR}/vars.sh
|
|||
ensure_pwd_is_scriptdir
|
||||
ensure_not_root
|
||||
|
||||
# check if active in systemd, then
|
||||
systemctl --user stop ${service_name}
|
||||
# check if running in podman, then
|
||||
podman stop ${container_name}
|
||||
check_container_exists ${container_name} || {
|
||||
echo Container ${container_name} does not exists
|
||||
exit 1
|
||||
}
|
||||
|
||||
# always
|
||||
systemctl --user disable ${service_name}
|
||||
check_systemd_unit_exists ${service_name} || {
|
||||
echo "Systemd unit ${service_name} does not exists"
|
||||
exit 1
|
||||
}
|
||||
|
||||
systemctl --user --now disable ${service_name}
|
||||
|
|
|
@ -7,12 +7,24 @@ source ${ABSDIR}/vars.sh
|
|||
ensure_pwd_is_scriptdir
|
||||
ensure_not_root
|
||||
|
||||
if ! podman container exists ${container_name}; then
|
||||
echo container ${container_name} does not exists.
|
||||
# FAIL if container does not exists
|
||||
check_container_exists ${container_name} || {
|
||||
echo Container ${container_name} does not exists.
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# add check if running, ask to stop first
|
||||
# add check if systemctl exists, ask to disable first
|
||||
# FAIL if systemd unit is running
|
||||
check_systemd_unit_running ${service_name} && {
|
||||
echo Systemd unit ${service_name} is running. Stop it first.
|
||||
exit 1
|
||||
}
|
||||
|
||||
# FAIL if container is running
|
||||
check_container_running ${container_name} && {
|
||||
echo Container ${container_name} is running. Stop it first.
|
||||
exit 1
|
||||
}
|
||||
|
||||
rm -f ${HOME}/.config/systemd/user/${service_name}
|
||||
systemctl --user daemon-reload
|
||||
podman rm ${container_name}
|
||||
|
|
|
@ -7,5 +7,14 @@ source ${ABSDIR}/vars.sh
|
|||
ensure_pwd_is_scriptdir
|
||||
ensure_not_root
|
||||
|
||||
podman rm ${container_name}
|
||||
check_systemd_unit_exists ${service_name} && {
|
||||
echo "Systemd unit ${service_name} exists. Please destroy first."
|
||||
exit 1
|
||||
}
|
||||
|
||||
check_container_exists ${container_name} && {
|
||||
echo "Container ${container_name} exists. Please destroy first."
|
||||
exit 1
|
||||
}
|
||||
|
||||
podman rmi "$(podman images -a -q -- ${upstream_image})"
|
||||
|
|
Loading…
Reference in a new issue