From 6382ca16c3b6422b08aa31cf8f4a2cc288302dea Mon Sep 17 00:00:00 2001 From: Faerbit Date: Sun, 1 Dec 2024 14:04:33 +0100 Subject: [PATCH] Add support for stop_grace_period --- main.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/main.py b/main.py index fe51558..5c27a76 100755 --- a/main.py +++ b/main.py @@ -1,11 +1,26 @@ #!/usr/bin/env python3 import argparse +import re import sys +from datetime import timedelta from pathlib import Path import yaml +TIME_REGEX = re.compile(r'((?P\d+?)h)?((?P\d+?)m)?((?P\d+?)s)?') + +def parse_time(time_str): + parts = TIME_REGEX.match(time_str) + if not parts or parts.span() == (0, 0): + return + parts = parts.groupdict() + time_params = {} + for name, param in parts.items(): + if param: + time_params[name] = int(param) + return timedelta(**time_params) + class IniFile: PREAMBLE = "### Generated by dcqc - do not edit ###" def __init__(self): @@ -196,6 +211,8 @@ def write_service_units(args, yaml_dict): if unmask: unit_file["Container"]["Unmask"] = unmask + if "stop_grace_period" in service: + unit_file["Container"]["StopTimeout"] = int(parse_time(service["stop_grace_period"]).total_seconds()) unit_file["Service"] = {}