fix: baseline analytics counters on planned release restart
This commit is contained in:
@@ -23,6 +23,8 @@ if systemctl --quiet is-active lisglosips-caller-analytics-redis.service && test
|
|||||||
cp -a /var/lib/redis-caller-analytics "$backup/redis-caller-analytics"
|
cp -a /var/lib/redis-caller-analytics "$backup/redis-caller-analytics"
|
||||||
fi
|
fi
|
||||||
cp -a /etc/opensips/opensips.cfg "$backup/opensips.cfg"
|
cp -a /etc/opensips/opensips.cfg "$backup/opensips.cfg"
|
||||||
|
checkpoint_file=/var/lib/lisglosips/caller-analytics-offset.json
|
||||||
|
if test -f "$checkpoint_file"; then cp -a "$checkpoint_file" "$backup/caller-analytics-offset.json"; fi
|
||||||
printf '%s\n' "$old" > "$backup/previous-release"
|
printf '%s\n' "$old" > "$backup/previous-release"
|
||||||
managed_files=(/etc/lisglosips/caller-analytics.env /etc/rsyslog.d/35-caller-analytics.conf /etc/redis/caller-analytics.conf /etc/systemd/system/lisglosips-caller-analytics-redis.service /etc/logrotate.d/lisglosips-caller-analytics /etc/systemd/system/lisglosips-caller-analytics-maintenance.service /etc/systemd/system/lisglosips-caller-analytics-maintenance.timer /etc/systemd/system/lisglosips.target)
|
managed_files=(/etc/lisglosips/caller-analytics.env /etc/rsyslog.d/35-caller-analytics.conf /etc/redis/caller-analytics.conf /etc/systemd/system/lisglosips-caller-analytics-redis.service /etc/logrotate.d/lisglosips-caller-analytics /etc/systemd/system/lisglosips-caller-analytics-maintenance.service /etc/systemd/system/lisglosips-caller-analytics-maintenance.timer /etc/systemd/system/lisglosips.target)
|
||||||
for file in "${managed_files[@]}"; do
|
for file in "${managed_files[@]}"; do
|
||||||
@@ -43,6 +45,7 @@ rollback() {
|
|||||||
systemctl stop lisglosips@caller-analytics || true
|
systemctl stop lisglosips@caller-analytics || true
|
||||||
systemctl stop lisglosips-caller-analytics-maintenance.timer lisglosips-caller-analytics-redis || true
|
systemctl stop lisglosips-caller-analytics-maintenance.timer lisglosips-caller-analytics-redis || true
|
||||||
cp -a "$backup/opensips.cfg" /etc/opensips/opensips.cfg
|
cp -a "$backup/opensips.cfg" /etc/opensips/opensips.cfg
|
||||||
|
if test -f "$backup/caller-analytics-offset.json"; then cp -a "$backup/caller-analytics-offset.json" "$checkpoint_file"; fi
|
||||||
for file in "${managed_files[@]}"; do
|
for file in "${managed_files[@]}"; do
|
||||||
if test -f "$backup/$(basename "$file")"; then cp -a "$backup/$(basename "$file")" "$file"; else rm -f "$file"; fi
|
if test -f "$backup/$(basename "$file")"; then cp -a "$backup/$(basename "$file")" "$file"; else rm -f "$file"; fi
|
||||||
done
|
done
|
||||||
@@ -114,6 +117,24 @@ chmod -R u=rwX,g=rX,o= "$new/apps/api/dist" "$new/apps/worker-cdr/dist" "$new/pa
|
|||||||
systemctl restart rsyslog
|
systemctl restart rsyslog
|
||||||
install -o root -g root -m 0644 "$new/opensips-candidate.cfg" /etc/opensips/opensips.cfg
|
install -o root -g root -m 0644 "$new/opensips-candidate.cfg" /etc/opensips/opensips.cfg
|
||||||
ln -sfn "$new" /opt/lisglosips/current
|
ln -sfn "$new" /opt/lisglosips/current
|
||||||
|
systemctl stop lisglosips@caller-analytics
|
||||||
|
# This is a coordinated producer restart after the spool is quiescent. Reset
|
||||||
|
# only the per-process reconciliation baseline; preserve any pre-existing gap.
|
||||||
|
if test -f "$checkpoint_file"; then
|
||||||
|
python3 - "$checkpoint_file" <<'PY'
|
||||||
|
import json, os, sys
|
||||||
|
p=sys.argv[1]; st=os.stat(p)
|
||||||
|
with open(p,encoding='utf-8') as f: data=json.load(f)
|
||||||
|
spool='/var/log/lisglosips/caller-analytics.log'
|
||||||
|
assert int(data.get('offset',-1)) == os.path.getsize(spool), 'analytics spool is not quiescent'
|
||||||
|
produced=data.get('lastProducerCount'); collected=data.get('eventsSinceProducerStart')
|
||||||
|
assert produced is None or produced == collected, 'producer/collector counters differ before planned restart'
|
||||||
|
data.pop('lastProducerCount',None); data['eventsSinceProducerStart']=0
|
||||||
|
t=p+'.deploy-tmp'
|
||||||
|
with open(t,'w',encoding='utf-8') as f: json.dump(data,f,separators=(',',':'))
|
||||||
|
os.chown(t,st.st_uid,st.st_gid); os.chmod(t,st.st_mode); os.replace(t,p)
|
||||||
|
PY
|
||||||
|
fi
|
||||||
systemctl restart opensips lisglosips@api
|
systemctl restart opensips lisglosips@api
|
||||||
systemctl enable --now lisglosips@caller-analytics
|
systemctl enable --now lisglosips@caller-analytics
|
||||||
systemctl restart lisglosips@caller-analytics
|
systemctl restart lisglosips@caller-analytics
|
||||||
|
|||||||
Reference in New Issue
Block a user