Ajout des scripts de gestion de matrix

This commit is contained in:
Loïc 2021-06-14 12:42:59 +02:00
parent 955a9c2921
commit 66b66ccd2e
10 changed files with 239 additions and 0 deletions

18
podman-matrix/00_status.sh Executable file
View file

@ -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}

View file

@ -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

31
podman-matrix/10_install.sh Executable file
View file

@ -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

19
podman-matrix/20_enable.sh Executable file
View file

@ -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}

24
podman-matrix/30_start.sh Executable file
View file

@ -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}

28
podman-matrix/40_stop.sh Executable file
View file

@ -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

19
podman-matrix/70_disable.sh Executable file
View file

@ -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}

20
podman-matrix/80_destroy.sh Executable file
View file

@ -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}

25
podman-matrix/90_prune.sh Executable file
View file

@ -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

15
podman-matrix/vars.sh Normal file
View file

@ -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}"