Skip to content
Snippets Groups Projects
Commit 04cf30b9 authored by Martin Mareš's avatar Martin Mareš
Browse files

Implement create_on_start

parent 90a71da1
No related branches found
No related tags found
No related merge requests found
root_dir = "/tmp/root"
# Example configuration of a container
# Image to pull
image = "registry.ks.matfyz.cz/gimli/web-checker"
# Root directory where data of the container reside
root_dir = "/tmp/root"
# Users and groups allowed to operate the container
allowed_users = ['root', 'mj']
allowed_groups = []
# Do we re-create the container on every start?
create_on_start = false
......@@ -3,8 +3,14 @@
# Where to find container configuration files
container_config_dir = "/etc/shipcat/containers"
# Where to find container roots (can be overridden by container's config)
container_root_dir = "/aux/containers"
# Overall verbosity
verbosity = 0
# Default values of container configuration
[defaults]
# Where to find container root: root_dir/container_name
root_dir = "/aux/containers"
# Do we re-create the container on every start?
create_on_start = false
......@@ -17,8 +17,9 @@ class ConfigError(RuntimeError):
class GlobalConfig:
container_config_path: Path
container_root_path: Path
verbosity: int
default_root_path: Path
default_create_on_start: bool
@classmethod
def load(self, filename: str) -> 'GlobalConfig':
......@@ -41,9 +42,12 @@ class GlobalConfig:
def parse(self, walker: Walker) -> None:
with walker.enter_object() as w:
self.container_config_path = Path(w['container_config_dir'].as_str())
self.container_root_path = Path(w['container_root_dir'].as_str())
self.verbosity = w['verbosity'].as_int(0)
with w['defaults'].enter_object() as d:
self.default_root_path = Path(d['root_dir'].as_str())
self.default_create_on_start = d['create_on_start'].as_bool(False)
class ContainerConfig:
name: str
......@@ -52,6 +56,7 @@ class ContainerConfig:
image: str
allowed_users: Set[int]
allowed_groups: Set[int]
create_on_start: bool
global_config: GlobalConfig
# Automatically generated
......@@ -88,7 +93,7 @@ class ContainerConfig:
if rd.is_present():
self.root_path = Path(rd.as_str())
else:
self.root_path = self.global_config.container_root_path / self.name
self.root_path = self.global_config.default_root_path / self.name
self.data_path = self.root_path / 'data'
self.root_dir = w['root_dir'].as_str()
......@@ -112,5 +117,7 @@ class ContainerConfig:
wu.raise_error(f'Unknown group {name}')
self.allowed_groups.add(grp.gr_gid)
self.create_on_start = w['create_on_start'].as_bool(self.global_config.default_create_on_start)
self.pid_file = f'/run/shc/{self.name}.pid'
self.user_name = self.name
......@@ -312,6 +312,9 @@ def main_service_start():
pid_file = f'/run/shc/{cc.name}.pid'
Path(pid_file).unlink(missing_ok=True)
if cc.create_on_start:
create_container(cc)
run_command(['podman', 'start', cc.name])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment