Files
mtusi2026lab5/scripts/actions.py
T

32 lines
931 B
Python

"""Windows hooks for the public resilience client."""
import os
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
def docker(*args):
return subprocess.check_output(['docker', *args], cwd=ROOT, text=True).strip()
def main():
if sys.argv[1] == 'restart':
docker('compose', 'restart', '-t', '4', 'db', 'redis', 's3', 'broker', 'api',
'dispatcher', 'worker', 'staging-cleaner', 'lb')
return
target = os.environ['TARGET_INSTANCE_ID']
for container in docker('compose', 'ps', '-q', 'api').splitlines():
name = docker('inspect', '--format', '{{.Config.Hostname}}', container)
prefix, _, suffix = target.rpartition('-')
if prefix == name and len(suffix) == 8:
docker('stop', '-t', '2', container)
return
raise SystemExit('API instance not found')
if __name__ == '__main__':
main()