16 lines
924 B
Python
16 lines
924 B
Python
"""Stop the real process selected by X-Instance-Id; do not stop any dependency."""
|
|
import json
|
|
import os
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
from stack import ROOT, docker, instance, replicas
|
|
target=os.environ['TARGET_INSTANCE_ID']
|
|
before=replicas()
|
|
with ThreadPoolExecutor(max_workers=2) as pool:
|
|
matches=[cid for cid,alias in zip(before,pool.map(instance,before)) if alias==target]
|
|
assert len(matches)==1,'Target does not uniquely identify a running API'
|
|
# Immediate process crash, without adding a graceful-drain delay to the fault.
|
|
docker('kill','--signal','KILL',matches[0])
|
|
assert docker('inspect','--format','{{.State.Running}}',matches[0])=='false'
|
|
(ROOT/'evidence').mkdir(exist_ok=True)
|
|
(ROOT/'evidence/stop-one.json').write_text(json.dumps({'target_instance':target,'stopped_container':matches[0],'before_containers':before,'after_running_containers':replicas()},indent=2)+'\n',encoding='utf-8')
|