diff --git a/podman-matrix/00_status.sh b/podman-matrix/00_status.sh new file mode 100755 index 0000000..7fa3a1b --- /dev/null +++ b/podman-matrix/00_status.sh @@ -0,0 +1,18 @@ +#!/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 "Podman images status..." +podman images ${synapse_image} | grep ${synapse_image} || echo Image ${synapse_image} not found. +podman images ${postgres_image} | grep ${postgres_image} || echo Image ${postgres_image} not found. +echo +echo "Checking pod status..." +podman pod ps | grep ${pod_name} || echo Pod ${pod_name} not found. +echo +echo "Checking systemd unit status..." +systemctl --user status ${service_name} diff --git a/podman-matrix/05_freshinstall.sh b/podman-matrix/05_freshinstall.sh new file mode 100755 index 0000000..bc8bed7 --- /dev/null +++ b/podman-matrix/05_freshinstall.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +ABSDIR="$( dirname "$(readlink -f -- "$0")" )" +source ${ABSDIR}/../functions.sh +source ${ABSDIR}/vars.sh + +ensure_pwd_is_scriptdir +ensure_not_root + +if [[ -d ~/.local/share/containers/storage/volumes/${confvolume} ]]; then + echo "Error : conf volume ${confvolume} already exists. Please remove it first (prune?)." + exit 1 +fi + +if [[ -d ~/.local/share/containers/storage/volumes/${dbvolume} ]]; then + echo "Error : db volume ${dbvolume} already exists. Please remove it first (prune?)." + exit 1 +fi +podman volume create matrixdotorg_synapse-data +podman volume create matrixdotorg_synapse-pgsql + +podman run -it --name synapse-generate --mount type=volume,src=matrixdotorg_synapse-data,dst=/data -e SYNAPSE_SERVER_NAME=garbaye.fr -e SYNAPSE_REPORT_STATS=no matrixdotorg/synapse generate +podman rm synapse-generate + +# Modifier le fichier home/podman-matrix/.local/share/containers/storage/volumes/matrixdotorg_synapse-data/_data/homeserver.yaml avec les valeurs ci dessous +#< public_baseurl: https://qlf-matrix.garbaye.fr +# +#< enable_registration: false +# +#< database: +#< name: psycopg2 +#< user: synapse +#< password: mysecretpass +#< database: synapse +#< host: synapse-db +#< port: 5432 +#< cp_min: 5 +#< cp_max: 10 +${ABSDIR}/10_install.sh + diff --git a/podman-matrix/10_install.sh b/podman-matrix/10_install.sh new file mode 100755 index 0000000..0d8d626 --- /dev/null +++ b/podman-matrix/10_install.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +ABSDIR="$( dirname "$(readlink -f -- "$0")" )" +source ${ABSDIR}/../functions.sh +source ${ABSDIR}/vars.sh + +ensure_pwd_is_scriptdir +ensure_not_root + +if [[ ! -d ~/.local/share/containers/storage/volumes/${confvolume} ]]; then + echo "Error : conf volume ${confvolume} does not exists. Consider running 05_freshinstall.sh if this is the first install." + exit 1 +fi + +if [[ ! -d ~/.local/share/containers/storage/volumes/${dbvolume} ]]; then + echo "Error : conf volume ${dbvolume} does not exists. Consider running 05_freshinstall.sh if this is the first install." + exit 1 +fi +podman pod create --publish 8086:8008 --name ${pod_name} && \ +podman run -d --name ${db_container_name} --pod ${pod_name} \ + --mount type=volume,src=${dbvolume},dst=/var/lib/postgresql/data/${container_name} \ + -e POSTGRES_PASSWORD=mysecretpass \ + -e POSTGRES_USER=${container_name} \ + -e POSTGRES_DB=${container_name} \ + -e POSTGRES_INITDB_ARGS="--encoding=UTF8 --locale=C" \ + -e PGDATA=/var/lib/postgresql/data/${container_name} ${postgres_image} && \ +podman run -d --name synapse --pod ${pod_name} \ + --mount type=volume,src=${confvolume},dst=/data ${synapse_image} && \ +podman pod stop && \ +echo Pod built and stopped + diff --git a/podman-matrix/20_enable.sh b/podman-matrix/20_enable.sh new file mode 100755 index 0000000..e64292c --- /dev/null +++ b/podman-matrix/20_enable.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +ABSDIR="$( dirname "$(readlink -f -- "$0")" )" +source ${ABSDIR}/../functions.sh +source ${ABSDIR}/vars.sh + +ensure_pwd_is_scriptdir +ensure_not_root + +ensure_pod_exists ${pod_name} + +ensure_systemd_as_user_dir_exists + +# pod must be running and not managed by systemd +podman generate systemd --files --name ${pod_name} +mv *.service ~/.config/systemd/user/ + +podman pod stop ${pod_name} +systemctl --user enable ${service_name} diff --git a/podman-matrix/30_start.sh b/podman-matrix/30_start.sh new file mode 100755 index 0000000..d2c0a2e --- /dev/null +++ b/podman-matrix/30_start.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +ABSDIR="$( dirname "$(readlink -f -- "$0")" )" +source ${ABSDIR}/../functions.sh +source ${ABSDIR}/vars.sh + +ensure_pwd_is_scriptdir +ensure_not_root + +# FAIL if pod does not exists. +ensure_pod_exists ${pod_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 pod is already running - without systemd control. +ensure_pod_not_running ${pod_name} + +# OK +echo "Starting pod through systemd" +systemctl --user start ${service_name} diff --git a/podman-matrix/40_stop.sh b/podman-matrix/40_stop.sh new file mode 100755 index 0000000..5c29c2a --- /dev/null +++ b/podman-matrix/40_stop.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +ABSDIR="$( dirname "$(readlink -f -- "$0")" )" +source ${ABSDIR}/../functions.sh +source ${ABSDIR}/vars.sh + +ensure_pwd_is_scriptdir +ensure_not_root + +ensure_pod_exists ${pod_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_pod_running ${pod_name}; then + echo Pod found running without systemd unit, stopping it now. + podman pod stop ${pod_name} + exit 0 +else + echo Pod ${pod_name} is not running. + exit 1 +fi diff --git a/podman-matrix/70_disable.sh b/podman-matrix/70_disable.sh new file mode 100755 index 0000000..874ef25 --- /dev/null +++ b/podman-matrix/70_disable.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +ABSDIR="$( dirname "$(readlink -f -- "$0")" )" +source ${ABSDIR}/../functions.sh +source ${ABSDIR}/vars.sh + +ensure_pwd_is_scriptdir +ensure_not_root + +# FAIL if pod does not exists +ensure_pod_exists ${pod_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-matrix/80_destroy.sh b/podman-matrix/80_destroy.sh new file mode 100755 index 0000000..f4bea63 --- /dev/null +++ b/podman-matrix/80_destroy.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +ABSDIR="$( dirname "$(readlink -f -- "$0")" )" +source ${ABSDIR}/../functions.sh +source ${ABSDIR}/vars.sh + +ensure_pwd_is_scriptdir +ensure_not_root + +# FAIL if pod does not exists +ensure_pod_exists ${pod_name} + +# FAIL if pod is running +ensure_pod_not_running ${pod_name} + +${ABSDIR}/70_disable.sh + +rm -f ${HOME}/.config/systemd/user/${service_name} +systemctl --user daemon-reload +podman pod rm ${pod_name} diff --git a/podman-matrix/90_prune.sh b/podman-matrix/90_prune.sh new file mode 100755 index 0000000..080816a --- /dev/null +++ b/podman-matrix/90_prune.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +ABSDIR="$( dirname "$(readlink -f -- "$0")" )" +source ${ABSDIR}/../functions.sh +source ${ABSDIR}/vars.sh + +ensure_pwd_is_scriptdir +ensure_not_root + +# FAIL if pod is running +ensure_pod_not_running ${pod_name} + +# FAIL if pod exists +ensure_pod_not_exists ${pod_name} + +# FAIL if systemd unit exists +ensure_systemd_unit_not_exists ${service_name} + +# remove volume +#podman unshare rm -rf ~/${confvolume}/ + +# 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-matrix/vars.sh b/podman-matrix/vars.sh new file mode 100644 index 0000000..0db47a1 --- /dev/null +++ b/podman-matrix/vars.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +pod_name='podman-matrix' +service_name="pod-${pod_name}.service" +#upstream_images="docker.io/matrixdotorg/synapse docker.io/library/postgres" +#version='latest' +synapse_image="docker.io/matrixdotorg/synapse" +synapse_version='latest' +postgres_image="docker.io/library/postgres" +postgres_version='latest' +confvolume='matrixdotorg_synapse-data' +dbvolume='matrixdotorg_synapse-pgsql' +container_name='synapse' +db_container_name='synapse-db' +#GARBAYE_JITSI_URL="${GARBAYE_JITSI_ENV_URL:-https://jitsi.garbaye.fr}"