forked from mtusi2026/mtusi2026lab3
Реализовать обязательный минимум: балансировку, общие повторы и сохранность при отказе
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
"""Явные действия оператора только над контейнерами проекта lab3."""
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def docker(*args):
|
||||
return subprocess.check_output(['docker', *args], text=True).strip()
|
||||
|
||||
|
||||
def main():
|
||||
action = sys.argv[1]
|
||||
if action == 'restart':
|
||||
docker('compose', 'restart', 'db', 'redis', 'api', 'lb')
|
||||
elif action == 'stop':
|
||||
target = os.environ['TARGET_INSTANCE_ID'].split('-')[0]
|
||||
containers = docker('compose', 'ps', '-q', 'api').splitlines()
|
||||
for container in containers:
|
||||
hostname = docker('inspect', '--format', '{{.Config.Hostname}}', container)
|
||||
if hostname == target:
|
||||
docker('stop', '--time', '1', container)
|
||||
return
|
||||
raise SystemExit('Выбранная реплика проекта не найдена')
|
||||
else:
|
||||
raise SystemExit('Неизвестное действие')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user