367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
45 lines
2.4 KiB
Python
45 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Back up/restart only the recorded local gateway, preserving private bindings.
|
|
No client/server/database/credential mutations; no arbitrary process names.
|
|
"""
|
|
import datetime
|
|
import argparse
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import signal
|
|
import subprocess
|
|
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
|
|
def main():
|
|
os.umask(0o077)
|
|
parser=argparse.ArgumentParser();parser.add_argument('--feature',action='append',default=[],help='Explicit GATEWAY_* experiment/audit NAME=on|off override')
|
|
args=parser.parse_args()
|
|
pid=int((ROOT/'runtime/relay.pid').read_text())
|
|
proc=Path('/proc')/str(pid)
|
|
binary=str(ROOT/'build/gateway-relay')
|
|
if os.readlink(proc/'exe').removesuffix(' (deleted)')!=binary or (proc/'cmdline').read_bytes().split(b'\0')[0].decode()!=binary:
|
|
raise RuntimeError('Recorded process is not the exact local gateway binary')
|
|
env=os.environ.copy();flags={}
|
|
for pair in (proc/'environ').read_bytes().split(b'\0'):
|
|
if pair.startswith(b'GATEWAY_'):
|
|
key,value=pair.decode().split('=',1);env[key]=value;flags[key]=value
|
|
allowed={'GATEWAY_'+name+'_EXPERIMENT' for name in ('WORLD','GO','INSTANCE','NPC','POPULATION','SPLINE','TALENT')}|{'GATEWAY_POPULATION_AUDIT','GATEWAY_MOVEMENT_AUDIT'}
|
|
for feature in args.feature:
|
|
name,separator,value=feature.partition('=')
|
|
if not separator or name not in allowed or value not in ('on','off'):raise RuntimeError('Feature override outside explicit local experiment/audit flags')
|
|
if value=='on':env[name]='1'
|
|
else:env.pop(name,None)
|
|
recovery=ROOT/'recovery'/('gateway-'+datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%S%fZ'))
|
|
recovery.mkdir(mode=0o700)
|
|
shutil.copyfile(proc/'exe',recovery/'gateway-relay');(recovery/'gateway-relay').chmod(0o700)
|
|
(recovery/'flags.json').write_text(json.dumps(flags,indent=2)+'\n')
|
|
(recovery/'RESTORE.txt').write_text('Validate and stop only runtime/relay.pid, restore gateway-relay to build/gateway-relay, then start ops/run_relay.py with flags.json environment. Reconnect actual WowB. No client, database, service, credential or account-permission changes.\n')
|
|
os.kill(pid,signal.SIGTERM)
|
|
subprocess.run(['python3',str(ROOT/'ops/run_relay.py')],cwd=ROOT,env=env,check=True)
|
|
print('Gateway binary recovery:',recovery)
|
|
|
|
if __name__=='__main__':main()
|