self.env: List[str] = []
self.memory_request: Optional[int] = None
self.memory_limit: Optional[int] = None
+ self.log_to_journald: Optional[bool] = None
self.container_init: bool = CONTAINER_INIT
self.container_engine: Optional[ContainerEngine] = None
return fsid
+def should_log_to_journald(ctx):
+ if ctx.log_to_journald is not None:
+ return ctx.log_to_journald
+ return isinstance(ctx.container_engine, Podman) and \
+ ctx.container_engine.version >= CGROUPS_SPLIT_PODMAN_VERSION
+
+
def get_daemon_args(ctx, fsid, daemon_type, daemon_id):
# type: (CephadmContext, str, str, Union[int, str]) -> List[str]
r = list() # type: List[str]
'--setuser', 'ceph',
'--setgroup', 'ceph',
'--default-log-to-file=false',
- '--default-log-to-stderr=true',
- '--default-log-stderr-prefix=debug ',
]
+ log_to_journald = should_log_to_journald(ctx)
+ if log_to_journald:
+ r += [
+ '--default-log-to-journald=true',
+ '--default-log-to-stderr=false',
+ ]
+ else:
+ r += [
+ '--default-log-to-stderr=true',
+ '--default-log-stderr-prefix=debug ',
+ ]
if daemon_type == 'mon':
r += [
'--default-mon-cluster-log-to-file=false',
- '--default-mon-cluster-log-to-stderr=true',
]
+ if log_to_journald:
+ r += [
+ '--default-mon-cluster-log-to-journald=true',
+ '--default-mon-cluster-log-to-stderr=false',
+ ]
+ else:
+ r += ['--default-mon-cluster-log-to-stderr=true']
elif daemon_type in Monitoring.components:
metadata = Monitoring.components[daemon_type]
r += metadata.get('args', list())
crash_dir = '/var/lib/ceph/%s/crash' % fsid
if os.path.exists(crash_dir):
mounts[crash_dir] = '/var/lib/ceph/crash:z'
+ if daemon_type != 'crash' and should_log_to_journald(ctx):
+ journald_sock_dir = '/run/systemd/journal'
+ mounts[journald_sock_dir] = journald_sock_dir
if daemon_type in Ceph.daemons and daemon_id:
data_dir = get_data_dir(fsid, ctx.data_dir, daemon_type, daemon_id)
image = cd._filter_last_local_ceph_image(out)
assert image == 'docker.io/ceph/ceph:v15.2.5'
+ def test_should_log_to_journald(self):
+ ctx = mock.Mock()
+ # explicit
+ ctx.log_to_journald = True
+ assert cd.should_log_to_journald(ctx)
+
+ ctx.log_to_journald = None
+ # enable if podman support --cgroup=split
+ ctx.container_engine = self.mock_podman()
+ ctx.container_engine.version = (2, 1, 0)
+ assert cd.should_log_to_journald(ctx)
+
+ # disable on old podman
+ ctx.container_engine.version = (2, 0, 0)
+ assert not cd.should_log_to_journald(ctx)
+
+ # disable on docker
+ ctx.container_engine = self.mock_docker()
+ assert not cd.should_log_to_journald(ctx)
+
class TestCustomContainer(unittest.TestCase):
cc: cd.CustomContainer