chore(release): add server B recording deployment script
This commit is contained in:
@@ -0,0 +1,98 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
commit=${1:?commit is required}
|
||||||
|
archive=${2:?archive path is required}
|
||||||
|
expected_sha=${3:?archive sha256 is required}
|
||||||
|
stamp=$(date -u +%Y%m%dT%H%M%SZ)
|
||||||
|
backup=/var/backups/lisglosips-s56/$stamp
|
||||||
|
old=$(readlink -f /opt/lisglosips/current)
|
||||||
|
new=/opt/lisglosips/releases/s56-b-consolidation-$stamp
|
||||||
|
|
||||||
|
echo "phase=verify-upload"
|
||||||
|
test "$(sha256sum "$archive" | awk '{print $1}')" = "$expected_sha"
|
||||||
|
test -d "$old"
|
||||||
|
test ! -e "$new"
|
||||||
|
|
||||||
|
echo "phase=data-backup"
|
||||||
|
systemctl start lisglosips-backup.service
|
||||||
|
if systemctl --quiet is-failed lisglosips-backup.service; then
|
||||||
|
systemctl status --no-pager lisglosips-backup.service
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
find /data/backups/mysql -mindepth 1 -maxdepth 1 -type d | sort | tail -1
|
||||||
|
find /data/backups/redis -mindepth 1 -maxdepth 1 -type d | sort | tail -1
|
||||||
|
|
||||||
|
echo "phase=config-backup"
|
||||||
|
install -d -m 0700 "$backup"
|
||||||
|
cp -a /etc/lisglosips/recording-worker.env "$backup/recording-worker.env"
|
||||||
|
cp -a /etc/systemd/system/lisglosips@recording-worker.service.d/10-s28-recording.conf "$backup/10-s28-recording.conf"
|
||||||
|
printf '%s\n' "$old" > "$backup/previous-release"
|
||||||
|
[ ! -e /usr/local/sbin/lisglosips-recording-finalize ] || cp -a /usr/local/sbin/lisglosips-recording-finalize "$backup/finalizer.previous"
|
||||||
|
[ ! -e /etc/systemd/system/lisglosips-recording-finalize.service ] || cp -a /etc/systemd/system/lisglosips-recording-finalize.service "$backup/finalizer-service.previous"
|
||||||
|
[ ! -e /etc/systemd/system/lisglosips-recording-finalize.timer ] || cp -a /etc/systemd/system/lisglosips-recording-finalize.timer "$backup/finalizer-timer.previous"
|
||||||
|
|
||||||
|
changed=0
|
||||||
|
rollback() {
|
||||||
|
rc=$?
|
||||||
|
if [ "$changed" -eq 1 ]; then
|
||||||
|
echo "phase=rollback rc=$rc"
|
||||||
|
systemctl disable --now lisglosips-recording-finalize.timer 2>/dev/null || true
|
||||||
|
cp -a "$backup/recording-worker.env" /etc/lisglosips/recording-worker.env
|
||||||
|
cp -a "$backup/10-s28-recording.conf" /etc/systemd/system/lisglosips@recording-worker.service.d/10-s28-recording.conf
|
||||||
|
ln -sfn "$old" /opt/lisglosips/current
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl restart lisglosips@recording-worker || true
|
||||||
|
fi
|
||||||
|
exit "$rc"
|
||||||
|
}
|
||||||
|
trap rollback ERR
|
||||||
|
|
||||||
|
echo "phase=stage-release"
|
||||||
|
cp -a --reflink=auto "$old" "$new"
|
||||||
|
tar -xzf "$archive" -C "$new"
|
||||||
|
printf '%s\n' "$commit" > "$new/.deployed-commit"
|
||||||
|
printf '%s\n' "$old" > "$new/.delta-base-release"
|
||||||
|
chown -R root:lisglosips "$new/apps/worker-recording/dist" "$new/infra/server-b/s56"
|
||||||
|
chmod -R u=rwX,g=rX,o= "$new/apps/worker-recording/dist" "$new/infra/server-b/s56"
|
||||||
|
chmod 0755 "$new/infra/server-b/s56/scripts/lisglosips-recording-finalize"
|
||||||
|
|
||||||
|
echo "phase=install-local-recording"
|
||||||
|
install -o root -g root -m 0755 "$new/infra/server-b/s56/scripts/lisglosips-recording-finalize" /usr/local/sbin/lisglosips-recording-finalize
|
||||||
|
install -o root -g root -m 0644 "$new/infra/server-b/s56/systemd/lisglosips-recording-finalize.service" /etc/systemd/system/lisglosips-recording-finalize.service
|
||||||
|
install -o root -g root -m 0644 "$new/infra/server-b/s56/systemd/lisglosips-recording-finalize.timer" /etc/systemd/system/lisglosips-recording-finalize.timer
|
||||||
|
install -o root -g root -m 0644 "$new/infra/server-b/s56/systemd/10-local-recording.conf" /etc/systemd/system/lisglosips@recording-worker.service.d/10-s28-recording.conf
|
||||||
|
|
||||||
|
tmp_env=$(mktemp)
|
||||||
|
grep -Ev '^(RECORDING_SOURCE_MODE|RECORDING_LOCAL_READY_DIR|RECORDING_REMOTE_HOST|RECORDING_SSH_CONFIG|RECORDING_REMOTE_READY_DIR)=' /etc/lisglosips/recording-worker.env > "$tmp_env"
|
||||||
|
printf '%s\n' 'RECORDING_SOURCE_MODE=local' 'RECORDING_LOCAL_READY_DIR=/dev/shm/voip_rec/ready' >> "$tmp_env"
|
||||||
|
install -o root -g lisglosips -m 0640 "$tmp_env" /etc/lisglosips/recording-worker.env
|
||||||
|
rm -f "$tmp_env"
|
||||||
|
install -d -o rtpengine -g rtpengine -m 0750 /dev/shm/voip_rec /dev/shm/voip_rec/incoming /dev/shm/voip_rec/ready /dev/shm/voip_rec/failed
|
||||||
|
|
||||||
|
changed=1
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl enable --now lisglosips-recording-finalize.timer
|
||||||
|
systemctl start lisglosips-recording-finalize.service
|
||||||
|
ln -sfn "$new" /opt/lisglosips/current
|
||||||
|
systemctl restart lisglosips@recording-worker
|
||||||
|
sleep 12
|
||||||
|
|
||||||
|
echo "phase=verify"
|
||||||
|
test "$(readlink -f /opt/lisglosips/current)" = "$new"
|
||||||
|
test "$(cat /opt/lisglosips/current/.deployed-commit)" = "$commit"
|
||||||
|
test "$(systemctl is-active lisglosips-recording-finalize.timer)" = active
|
||||||
|
test "$(systemctl is-active rtpengine-recording-daemon)" = active
|
||||||
|
test "$(systemctl is-active lisglosips@recording-worker)" = active
|
||||||
|
/opt/lisglosips/current/infra/server-b/s30/lisglosips-release-preflight.sh
|
||||||
|
journalctl -u lisglosips@recording-worker --since "@$(( $(date +%s) - 60 ))" --no-pager | tail -30
|
||||||
|
echo "ENV_MODE"
|
||||||
|
grep -E '^(RECORDING_SOURCE_MODE|RECORDING_LOCAL_READY_DIR|RECORDING_LOCAL_ROOT|RECORDING_DELETE_SOURCE_AFTER_COPY)=' /etc/lisglosips/recording-worker.env
|
||||||
|
echo "PROCESS_CHECK"
|
||||||
|
worker_pid=$(systemctl show -p MainPID --value lisglosips@recording-worker)
|
||||||
|
ps -o pid,ppid,comm,args --forest -g "$(ps -o sid= -p "$worker_pid" | tr -d ' ')" || true
|
||||||
|
pgrep -a ssh || true
|
||||||
|
printf 'BACKUP=%s\nRELEASE=%s\nCOMMIT=%s\n' "$backup" "$new" "$commit"
|
||||||
|
|
||||||
|
changed=0
|
||||||
|
trap - ERR
|
||||||
Reference in New Issue
Block a user