Add support for stop_grace_period
This commit is contained in:
parent
602c3a45cf
commit
6382ca16c3
17
main.py
17
main.py
@ -1,11 +1,26 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import argparse
|
import argparse
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
from datetime import timedelta
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
|
TIME_REGEX = re.compile(r'((?P<hours>\d+?)h)?((?P<minutes>\d+?)m)?((?P<seconds>\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:
|
class IniFile:
|
||||||
PREAMBLE = "### Generated by dcqc - do not edit ###"
|
PREAMBLE = "### Generated by dcqc - do not edit ###"
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -196,6 +211,8 @@ def write_service_units(args, yaml_dict):
|
|||||||
if unmask:
|
if unmask:
|
||||||
unit_file["Container"]["Unmask"] = 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"] = {}
|
unit_file["Service"] = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user