tmpfile_dest_dir => sereral options
This commit is contained in:
parent
540b108e8e
commit
5b459927fb
19 changed files with 48 additions and 22 deletions
|
@ -102,10 +102,27 @@ Le répertoire de temporaire est géré dans la clef "tmp_dir" et a comme valeur
|
|||
|
||||
Le répertoire de destination des fichiers générés est géré dans la clef "destinations_dir" et a comme valeur par défaut : "/srv/rougail/destinations".
|
||||
|
||||
### Le nom du répertoire où se trouve les fichiers pour tmpfile.d
|
||||
### Les informations systemd
|
||||
|
||||
Le répertoire où se trouve les fichiers tmpfile.d sont par défaut dans "/usr/local/lib", il est possible de changer ce répertoire avec la clef "tmpfile_dest_dir".
|
||||
Un certain nombre de variables concerne les templates systemd.
|
||||
|
||||
#### Les services
|
||||
|
||||
Les services sont générés dans le sous-répertoire de la clef "systemd_service_directory" (par défault "/systemd") du répertoire "destinations_dir" (voir plus haut) .
|
||||
|
||||
Par contre la racine de ce sous répertoire sur le système finale sera la valeur de la clef "systemd_service_destination_directory" (par défaut "/usr/local/lib").
|
||||
Les autres services, non généré via Rougail, devront être dans le répertoire de la clef "system_service_directory" (par défault "/usr/lib/systemd/system").
|
||||
|
||||
Lorsqu'on [réécrit un service](../service/override.md) le fichier définit dans la clef "systemd_service_file" (par défaut "rougail.conf").
|
||||
Les [IP](../service/ip.md) seront dans le fichier définit dans la clef "systemd_service_ip_file" (par défaut "rougail_ip.conf").
|
||||
|
||||
### Les tmpfiles
|
||||
|
||||
Les fichiers tmpfiles sont générés dans le sous-répertoire de la clef "systemd_tmpfile_directory" (par défault "/tmpfiles.d") du répertoire "destinations_dir" (voir plus haut) .
|
||||
|
||||
Par contre la racine de ce sous répertoire sur le système finale sera la valeur de la clef "systemd_tmpfile_factory_dir" (par défaut "/usr/local/lib").
|
||||
|
||||
Le fichier généré dans ce répertoire aura le nom définit dans la clef "systemd_tmpfile_file", donc "0rougail.conf" par défaut.
|
||||
|
||||
## La configuration par défaut des fichiers
|
||||
|
||||
|
|
|
@ -44,7 +44,14 @@ RougailConfig = {'dictionaries_dir': [join(ROUGAILROOT, 'dictionaries')],
|
|||
'dtdfilename': join(DTDDIR, 'rougail.dtd'),
|
||||
'yamlschema_filename': join(DTDDIR, 'rougail.yml'),
|
||||
'functions_file': join(ROUGAILROOT, 'functions.py'),
|
||||
'tmpfile_dest_dir': '/usr/local/lib',
|
||||
'system_service_directory': '/usr/lib/systemd/system',
|
||||
'systemd_service_destination_directory': '/usr/local/lib',
|
||||
'systemd_service_directory': '/systemd',
|
||||
'systemd_service_file': 'rougail.conf',
|
||||
'systemd_service_ip_file': 'rougail_ip.conf',
|
||||
'systemd_tmpfile_factory_dir': '/usr/local/lib',
|
||||
'systemd_tmpfile_directory': '/tmpfiles.d',
|
||||
'systemd_tmpfile_file': '0rougail.conf',
|
||||
'variable_namespace': 'rougail',
|
||||
'variable_namespace_description': 'Rougail',
|
||||
'auto_freeze_variable': 'server_deployed',
|
||||
|
@ -61,7 +68,6 @@ RougailConfig = {'dictionaries_dir': [join(ROUGAILROOT, 'dictionaries')],
|
|||
'default_files_included': 'no',
|
||||
'default_overrides_engine': 'cheetah',
|
||||
'default_service_names_engine': 'none',
|
||||
'default_systemd_directory': '/systemd',
|
||||
'base_option_name': 'baseoption',
|
||||
'export_with_import': True,
|
||||
'force_convert_dyn_option_description': False,
|
||||
|
|
|
@ -299,7 +299,6 @@ class RougailBaseTemplate:
|
|||
) -> str:
|
||||
"""Run templatisation on one file
|
||||
"""
|
||||
self.log.info(_("Instantiating file '{filename}'"))
|
||||
if 'variable' in filevar:
|
||||
variable = filevar['variable']
|
||||
else:
|
||||
|
@ -327,6 +326,9 @@ class RougailBaseTemplate:
|
|||
if data is None:
|
||||
continue
|
||||
filename, source, true_destfilename, var = data
|
||||
self.log.info(_(f'Instantiating file "{filename}"'))
|
||||
if not true_destfilename.startswith('/'):
|
||||
raise Exception(f'true_destfilename must starts with a / in function {func}')
|
||||
destfilename = join(self.destinations_dir, true_destfilename[1:])
|
||||
makedirs(dirname(destfilename), exist_ok=True)
|
||||
self.log.info(_(f"{filevar['engine']} processing: '{destfilename}'"))
|
||||
|
|
|
@ -41,8 +41,6 @@ IPAddressDeny=any
|
|||
"""
|
||||
|
||||
|
||||
ROUGAIL_GLOBAL_SYSTEMD_FILE = '/usr/lib/systemd/system'
|
||||
ROUGAIL_DEST_FILE = '/tmpfiles.d/0rougail.conf'
|
||||
LOCAL_DIR = ('/etc/', '/var/', '/srv/')
|
||||
|
||||
|
||||
|
@ -58,7 +56,7 @@ class RougailSystemdTemplate(RougailBaseTemplate):
|
|||
tmp_local_dir = (f"%%filename.startswith('{local_dir}')" for local_dir in LOCAL_DIR)
|
||||
self.rougail_tmpl_template += '%if ' + ' or '.join(tmp_local_dir)
|
||||
self.rougail_tmpl_template += f"""
|
||||
C %%filename %%file.mode %%file.owner %%file.group - {self.rougailconfig['tmpfile_dest_dir']}%%filename
|
||||
C %%filename %%file.mode %%file.owner %%file.group - {self.rougailconfig['systemd_tmpfile_factory_dir']}%%filename
|
||||
%end if
|
||||
%end def
|
||||
%for %%service in %%services
|
||||
|
@ -89,7 +87,7 @@ C %%filename %%file.mode %%file.owner %%file.group - {self.rougailconfig['tmpfil
|
|||
raise FileNotFound(_(f'Override source file "{source}" does not exist in {", ".join(self.templates_dir)}'))
|
||||
tmp_file = join(self.tmp_dir, source)
|
||||
service_name = filevar['name']
|
||||
destfile = f'{self.rougailconfig["default_systemd_directory"]}/system/{service_name}.d/rougail.conf'
|
||||
destfile = f'{self.rougailconfig["systemd_service_directory"]}/system/{service_name}.d/{self.rougailconfig["systemd_service_file"]}'
|
||||
return tmp_file, None, destfile, None
|
||||
|
||||
def get_data_ip(self,
|
||||
|
@ -119,28 +117,30 @@ C %%filename %%file.mode %%file.owner %%file.group - {self.rougailconfig['tmpfil
|
|||
):
|
||||
tmp_file = join(self.tmp_dir, service_name)
|
||||
var = None
|
||||
destfile = f'{self.rougailconfig["default_systemd_directory"]}/system/{service_name}'
|
||||
destfile = f'{self.rougailconfig["systemd_service_directory"]}/system/{service_name}'
|
||||
return tmp_file, None, destfile, var
|
||||
|
||||
|
||||
def desactive_service(self,
|
||||
service_name: str,
|
||||
):
|
||||
filename = f'{self.destinations_dir}/systemd/system/{service_name}'
|
||||
filename = f'{self.destinations_dir}/{self.rougailconfig["systemd_service_directory"]}/system/{service_name}'
|
||||
makedirs(dirname(filename), exist_ok=True)
|
||||
symlink('/dev/null', filename)
|
||||
|
||||
def target_service(self,
|
||||
service_name: str,
|
||||
target_name: str,
|
||||
global_service: bool,
|
||||
system_service: bool,
|
||||
):
|
||||
filename = f'{self.destinations_dir}/systemd/system/{target_name}.target.wants/{service_name}'
|
||||
"""system_service: means that the service is not generated by rougail
|
||||
"""
|
||||
filename = f'{self.destinations_dir}/{self.rougailconfig["systemd_service_directory"]}/system/{target_name}.target.wants/{service_name}'
|
||||
makedirs(dirname(filename), exist_ok=True)
|
||||
if global_service:
|
||||
source_filename = f'{ROUGAIL_GLOBAL_SYSTEMD_FILE}/{service_name}'
|
||||
if system_service:
|
||||
source_filename = f'{self.rougailconfig["system_service_directory"]}/{service_name}'
|
||||
else:
|
||||
source_filename = f"{self.rougailconfig['tmpfile_dest_dir']}/systemd/system/{service_name}"
|
||||
source_filename = f'{self.rougailconfig["systemd_service_destination_directory"]}{self.rougailconfig["systemd_service_directory"]}/system/{service_name}'
|
||||
symlink(source_filename, filename)
|
||||
|
||||
def post_instance_service(self,
|
||||
|
@ -148,7 +148,7 @@ C %%filename %%file.mode %%file.owner %%file.group - {self.rougailconfig['tmpfil
|
|||
) -> None: # pragma: no cover
|
||||
if self.ip_per_service is None:
|
||||
return
|
||||
destfile = f'{self.rougailconfig["default_systemd_directory"]}/system/{service_name}.d/rougail_ip.conf'
|
||||
destfile = f'{self.rougailconfig["systemd_service_directory"]}/system/{service_name}.d/{self.rougailconfig["systemd_service_ip_file"]}'
|
||||
destfilename = join(self.destinations_dir, destfile[1:])
|
||||
makedirs(dirname(destfilename), exist_ok=True)
|
||||
self.log.info(_(f"Cheetah processing: '{destfilename}'"))
|
||||
|
@ -181,12 +181,13 @@ C %%filename %%file.mode %%file.owner %%file.group - {self.rougailconfig['tmpfil
|
|||
super().process(filename, destfilename, mode, owner, group)
|
||||
|
||||
def post_instance(self):
|
||||
destfilename = join(self.destinations_dir, ROUGAIL_DEST_FILE[1:])
|
||||
tmpfiles_filename = f"{self.rougailconfig['systemd_tmpfile_directory']}/{self.rougailconfig['systemd_tmpfile_file']}"
|
||||
destfilename = join(self.destinations_dir, tmpfiles_filename[1:])
|
||||
makedirs(dirname(destfilename), exist_ok=True)
|
||||
self.log.info(_(f"Cheetah processing: '{destfilename}'"))
|
||||
self.engines['cheetah'].process(filename=None,
|
||||
source=self.rougail_tmpl_template,
|
||||
true_destfilename=ROUGAIL_DEST_FILE,
|
||||
true_destfilename=tmpfiles_filename,
|
||||
destfilename=destfilename,
|
||||
destdir=self.destinations_dir,
|
||||
variable=None,
|
||||
|
|
|
@ -67,10 +67,10 @@ async def template(test_dir, filename, root, engine_name):
|
|||
RougailConfig['tmp_dir'] = tmp_dir
|
||||
RougailConfig['functions_file'] = funcs_file
|
||||
RougailConfig['destinations_dir'] = dest_dir
|
||||
if isfile(join(test_dir, 'file_tmpfile_dest_dir')):
|
||||
RougailConfig['tmpfile_dest_dir'] = '/test/new/file'
|
||||
if isfile(join(test_dir, 'file_tmpfiles_factory_dir')):
|
||||
RougailConfig['systemd_tmpfile_factory_dir'] = '/test/new/file'
|
||||
else:
|
||||
RougailConfig['tmpfile_dest_dir'] = '/usr/local/lib'
|
||||
RougailConfig['systemd_tmpfile_factory_dir'] = '/usr/local/lib'
|
||||
if engine_name == 'base':
|
||||
engine = RougailBaseTemplate(config)
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue