forked from mtusi2026/mtusi2026lab4
29 lines
932 B
Python
29 lines
932 B
Python
"""Restart the whole lab stack, retaining volumes and recording actual start times."""
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def snapshot():
|
|
ids = subprocess.check_output(['docker', 'compose', 'ps', '-q'], cwd=ROOT, text=True).split()
|
|
return subprocess.check_output(
|
|
['docker', 'inspect', '--format', '{{.Name}} {{.State.StartedAt}}', *ids],
|
|
cwd=ROOT, text=True,
|
|
)
|
|
|
|
|
|
def main():
|
|
before = snapshot()
|
|
subprocess.run(['docker', 'compose', 'restart', 'api', 'postgres', 'redis', 'nginx'],
|
|
cwd=ROOT, check=True, timeout=60)
|
|
after = snapshot()
|
|
(ROOT / 'evidence').mkdir(exist_ok=True)
|
|
(ROOT / 'evidence' / 'restart.txt').write_text(
|
|
'Command: docker compose restart api postgres redis nginx\nBefore (UTC):\n' + before
|
|
+ 'After (UTC):\n' + after, encoding='utf-8')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|