22 lines
1.1 KiB
Python
22 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Systemd stop hook: expose timeout/kill failures even if Python could not save."""
|
|
import importlib.util
|
|
import json
|
|
import os
|
|
from datetime import datetime, timezone
|
|
from pathlib import Path
|
|
|
|
spec = importlib.util.spec_from_file_location('cycle', Path(__file__).with_name('release-cycle.py'))
|
|
cycle = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(cycle)
|
|
config = json.loads(Path(os.environ.get('ARCHIPELAGO_CYCLE_CONFIG', '/etc/archipelago/release-cycle.json')).read_text())
|
|
base = Path(config['coordinator_root'])
|
|
parent = base / 'data/private/release-cycle'
|
|
latest = parent / 'latest.json'
|
|
if latest.exists():
|
|
state = json.loads(latest.read_text())
|
|
if state.get('invocation_id') == os.environ.get('INVOCATION_ID') and state['state'] not in ('complete', 'failed'):
|
|
state.update(failed_phase=state['state'], state='failed', stage_title='Release cycle failed',
|
|
error='Coordinator terminated: ' + os.environ.get('SERVICE_RESULT', 'unknown'),
|
|
updated=datetime.now(timezone.utc).isoformat())
|
|
cycle.write_status(base, state)
|