from cephadmlib.container_daemon_form import ContainerDaemonForm
from cephadmlib.sysctl import install_sysctl, migrate_sysctl_dir
from cephadmlib.firewalld import Firewalld, update_firewalld
+from cephadmlib import templating
FuncT = TypeVar('FuncT', bound=Callable)
""" % (fsid, ' '.join(targets), '|'.join(targets)))
-def get_unit_file(ctx, fsid):
- # type: (CephadmContext, str) -> str
- extra_args = ''
- if isinstance(ctx.container_engine, Podman):
- extra_args = ('ExecStartPre=-/bin/rm -f %t/%n-pid %t/%n-cid\n'
- 'ExecStopPost=-/bin/rm -f %t/%n-pid %t/%n-cid\n'
- 'Type=forking\n'
- 'PIDFile=%t/%n-pid\n')
- if ctx.container_engine.supports_split_cgroups:
- extra_args += 'Delegate=yes\n'
-
- docker = isinstance(ctx.container_engine, Docker)
- u = """# generated by cephadm
+_TMPL_DAEMON_UNIT = """# generated by cephadm
[Unit]
-Description=Ceph %i for {fsid}
+Description=Ceph %i for {{fsid}}
# According to:
# http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget
# these can be removed once ceph-mon will dynamically change network
# configuration.
-After=network-online.target local-fs.target time-sync.target{docker_after}
+After=network-online.target local-fs.target time-sync.target{% if has_docker_engine %} docker.service{% endif %}
Wants=network-online.target local-fs.target time-sync.target
-{docker_requires}
+{%- if has_docker_engine %}
+Requires=docker.service
+{%- endif %}
-PartOf=ceph-{fsid}.target
-Before=ceph-{fsid}.target
+PartOf=ceph-{{fsid}}.target
+Before=ceph-{{fsid}}.target
[Service]
LimitNOFILE=1048576
LimitNPROC=1048576
EnvironmentFile=-/etc/environment
-ExecStart=/bin/bash {data_dir}/{fsid}/%i/unit.run
-ExecStop=-/bin/bash -c 'bash {data_dir}/{fsid}/%i/unit.stop'
-ExecStopPost=-/bin/bash {data_dir}/{fsid}/%i/unit.poststop
+ExecStart=/bin/bash {{ctx.data_dir}}/{{fsid}}/%i/unit.run
+ExecStop=-/bin/bash -c 'bash {{ctx.data_dir}}/{{fsid}}/%i/unit.stop'
+ExecStopPost=-/bin/bash {{ctx.data_dir}}/{{fsid}}/%i/unit.poststop
KillMode=none
Restart=on-failure
RestartSec=10s
TimeoutStopSec=120
StartLimitInterval=30min
StartLimitBurst=5
-{extra_args}
+{%- if has_podman_engine %}
+ExecStartPre=-/bin/rm -f %t/%n-pid %t/%n-cid
+ExecStopPost=-/bin/rm -f %t/%n-pid %t/%n-cid
+Type=forking
+PIDFile=%t/%n-pid
+{%- if has_podman_split_version %}
+Delegate=yes
+{%- endif %}
+{%- endif %}
+
[Install]
-WantedBy=ceph-{fsid}.target
-""".format(fsid=fsid,
- data_dir=ctx.data_dir,
- extra_args=extra_args,
- # if docker, we depend on docker.service
- docker_after=' docker.service' if docker else '',
- docker_requires='Requires=docker.service\n' if docker else '')
-
- return u
+WantedBy=ceph-{{fsid}}.target
+"""
+
+
+def get_unit_file(ctx: CephadmContext, fsid: str) -> str:
+ has_docker_engine = isinstance(ctx.container_engine, Docker)
+ has_podman_engine = isinstance(ctx.container_engine, Podman)
+ has_podman_split_version = (
+ has_podman_engine and ctx.container_engine.supports_split_cgroups
+ )
+ return templating.template_str(
+ ctx,
+ _TMPL_DAEMON_UNIT,
+ fsid=fsid,
+ has_docker_engine=has_docker_engine,
+ has_podman_engine=has_podman_engine,
+ has_podman_split_version=has_podman_split_version,
+ )
##################################