Files

64 lines
2.5 KiB
Bash

#!/usr/bin/env bash
set -Eeuo pipefail
release_root=${1:-/opt/lisglosips/current}
stamp=$(date -u +%Y%m%dT%H%M%SZ)
backup=/var/backups/lisglosips-s58/$stamp
test -x "$release_root/infra/ops/startup/lisglosips-start-b.sh"
test -f "$release_root/infra/server-b/s58/systemd/lisglosips.target"
test -f "$release_root/infra/server-b/s58/systemd/lisglosips-boot-check.service"
install -d -m 0700 "$backup"
for path in \
/usr/local/sbin/lisglosips-start-b \
/etc/systemd/system/lisglosips.target \
/etc/systemd/system/lisglosips-boot-check.service; do
[ ! -e "$path" ] || cp -a "$path" "$backup/$(basename "$path").previous"
done
changed=0
rollback() {
rc=$?
if [ "$changed" -eq 1 ]; then
echo "phase=rollback rc=$rc"
systemctl disable lisglosips-boot-check.service lisglosips.target \
lisglosips@recording-worker.service lisglosips@config-publisher.service 2>/dev/null || true
for name in lisglosips-start-b lisglosips.target lisglosips-boot-check.service; do
previous="$backup/$name.previous"
case "$name" in
lisglosips-start-b) target=/usr/local/sbin/lisglosips-start-b ;;
*) target=/etc/systemd/system/$name ;;
esac
if [ -e "$previous" ]; then cp -a "$previous" "$target"; else rm -f "$target"; fi
done
systemctl daemon-reload
fi
exit "$rc"
}
trap rollback ERR
echo "phase=install"
install -o root -g root -m 0755 "$release_root/infra/ops/startup/lisglosips-start-b.sh" /usr/local/sbin/lisglosips-start-b
install -o root -g root -m 0644 "$release_root/infra/server-b/s58/systemd/lisglosips.target" /etc/systemd/system/lisglosips.target
install -o root -g root -m 0644 "$release_root/infra/server-b/s58/systemd/lisglosips-boot-check.service" /etc/systemd/system/lisglosips-boot-check.service
changed=1
systemctl daemon-reload
systemctl enable lisglosips.target lisglosips-boot-check.service \
lisglosips@api.service lisglosips@cdr-worker.service \
lisglosips@recording-worker.service lisglosips@config-publisher.service
echo "phase=start-and-verify"
systemctl start lisglosips.target
systemctl restart lisglosips-boot-check.service
test "$(systemctl is-enabled lisglosips.target)" = enabled
test "$(systemctl is-enabled lisglosips@recording-worker.service)" = enabled
test "$(systemctl is-enabled lisglosips@config-publisher.service)" = enabled
test "$(systemctl is-active lisglosips@recording-worker.service)" = active
test "$(systemctl is-active lisglosips@config-publisher.service)" = active
printf 'BACKUP=%s\nTARGET=%s\n' "$backup" "$(systemctl is-enabled lisglosips.target)"
changed=0
trap - ERR