mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-29 06:17:25 +00:00
systemd disables the start timeout of Type=oneshot units by default (systemd.service: TimeoutStartSec), and RuntimeMaxSec does not apply to them, so a hung oneshot unit ran forever. system_service_tpl_timeout_start_sec now renders SYS_SERVICE_DEFAULT_RUNTIME (86400s) for oneshot units and stays empty for every other type, so roles that pass their own cap (sys-ctl-hlth-csp, sys-ctl-hlth-webserver, sys-ctl-cln-bkps) keep it. The comment that called the empty value intended is gone. Tests: test_oneshot_start_timeout.py renders the expression from vars/main.yml: a oneshot unit gets the default runtime, a simple unit keeps the manager default (2 passed; negative control on main: 1 failed). quality-high green on this tree (test 4/4, lint 15/15). Residual: a backup oneshot that runs longer than 24 h is now stopped; the prod hlth-runtime durations decide the per-role cap. 🎯 Fix: 92 % 💥 Break: 5 % 💸 Cost: – ⏱️ Time: – 🛡️ Security: 100 % 🏆 Score: 87 🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
import unittest
|
|
|
|
from jinja2 import Environment, select_autoescape
|
|
|
|
from utils.cache.files import PROJECT_ROOT
|
|
from utils.cache.yaml import load_yaml_any
|
|
from utils.roles.mapping import ROLE_FILE_DEFAULTS_MAIN, ROLE_FILE_VARS_MAIN
|
|
|
|
ROLE = PROJECT_ROOT / "roles" / "sys-service"
|
|
RUNTIME = load_yaml_any(str(ROLE / ROLE_FILE_DEFAULTS_MAIN))[
|
|
"SYS_SERVICE_DEFAULT_RUNTIME"
|
|
]
|
|
|
|
|
|
def _start_timeout(unit_type: str) -> str:
|
|
expression = load_yaml_any(str(ROLE / ROLE_FILE_VARS_MAIN))[
|
|
"system_service_tpl_timeout_start_sec"
|
|
]
|
|
return (
|
|
Environment(autoescape=select_autoescape())
|
|
.from_string(expression)
|
|
.render(system_service_tpl_type=unit_type, SYS_SERVICE_DEFAULT_RUNTIME=RUNTIME)
|
|
)
|
|
|
|
|
|
class TestOneshotStartTimeout(unittest.TestCase):
|
|
def test_a_oneshot_unit_gets_a_bounded_start(self) -> None:
|
|
self.assertTrue(RUNTIME)
|
|
self.assertEqual(_start_timeout("oneshot"), RUNTIME)
|
|
|
|
def test_other_unit_types_keep_the_manager_default(self) -> None:
|
|
self.assertEqual(_start_timeout("simple"), "")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|