From d23cf0113d56eb34c2e11d93ac84bc03d1f8ab58 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 24 Oct 2019 21:03:34 -0500 Subject: [PATCH] ceph-daemon: /var/run/ceph -> /var/run/ceph/$fsid This is better than having a single /var/run/ceph on the host with a weird naming scheme. Among other things, it means that we can access the asok for any daemon for a given fsid from any container on the same host with the same fsid (notably, a shell). Signed-off-by: Sage Weil --- src/ceph-daemon | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/ceph-daemon b/src/ceph-daemon index 2fa8647b97d..6d64d9c740c 100755 --- a/src/ceph-daemon +++ b/src/ceph-daemon @@ -257,10 +257,6 @@ def get_daemon_args(fsid, daemon_type, daemon_id): '--default-log-to-file=false', '--default-log-to-stderr=true', ] - if fsid and daemon_id: - r += ['--default-admin-socket', - '/var/run/ceph/' + fsid + '-' + daemon_type + '.' + daemon_id + - '.asok'] r += ['--setuser', 'ceph'] r += ['--setgroup', 'ceph'] return r @@ -337,6 +333,7 @@ def get_config_and_both_keyrings(): def get_container_mounts(fsid, daemon_type, daemon_id): mounts = {} if fsid: + mounts['/var/run/ceph/%s' % fsid] = '/var/run/ceph:z' log_dir = get_log_dir(fsid) mounts[log_dir] = '/var/log/ceph:z' mounts['/var/lib/ceph/%s/crash' % fsid] = '/var/lib/ceph/crash:z' @@ -447,9 +444,9 @@ def deploy_daemon(fsid, daemon_type, daemon_id, c, uid, gid, ) pc.run() - deploy_daemon_units(fsid, daemon_type, daemon_id, c) + deploy_daemon_units(fsid, uid, gid, daemon_type, daemon_id, c) -def deploy_daemon_units(fsid, daemon_type, daemon_id, c, +def deploy_daemon_units(fsid, uid, gid, daemon_type, daemon_id, c, enable=True, start=True): # cmd data_dir = get_data_dir(fsid, daemon_type, daemon_id) @@ -459,7 +456,7 @@ def deploy_daemon_units(fsid, daemon_type, daemon_id, c, # systemd install_base_units(fsid) - unit = get_unit_file(fsid) + unit = get_unit_file(fsid, uid, gid) unit_file = 'ceph-%s@.service' % (fsid) with open(args.unit_dir + '/' + unit_file + '.new', 'w') as f: f.write(unit) @@ -587,7 +584,7 @@ def deploy_crash(fsid, uid, gid, config, keyring): subprocess.check_output(['systemctl', 'enable', unit_name]) subprocess.check_output(['systemctl', 'start', unit_name]) -def get_unit_file(fsid): +def get_unit_file(fsid, uid, gid): u = """[Unit] Description=Ceph daemon for {fsid} @@ -606,10 +603,9 @@ LimitNOFILE=1048576 LimitNPROC=1048576 EnvironmentFile=-/etc/environment ExecStartPre=-{podman_path} rm ceph-{fsid}-%i -ExecStartPre=-mkdir -p /var/run/ceph +ExecStartPre=-install -d -m0770 -o {uid} -g {gid} /var/run/ceph/{fsid} ExecStart={data_dir}/{fsid}/%i/cmd ExecStop=-{podman_path} stop ceph-{fsid}-%i -ExecStopPost=-/bin/rm -f /var/run/ceph/{fsid}-%i.asok Restart=on-failure RestartSec=10s TimeoutStartSec=120 @@ -622,6 +618,8 @@ WantedBy=ceph-{fsid}.target """.format( podman_path=podman_path, fsid=fsid, + uid=uid, + gid=gid, data_dir=args.data_dir) return u @@ -856,7 +854,7 @@ def command_bootstrap(): f.write(config) mon_c = get_container(fsid, 'mon', mon_id) - deploy_daemon_units(fsid, 'mon', mon_id, mon_c) + deploy_daemon_units(fsid, uid, gid, 'mon', mon_id, mon_c) logger.info('Waiting for mon to start...') while True: @@ -1288,7 +1286,7 @@ def command_adopt(): logger.info('Creating new units...') c = get_container(fsid, daemon_type, daemon_id) - deploy_daemon_units(fsid, daemon_type, daemon_id, c, + deploy_daemon_units(fsid, uid, gid, daemon_type, daemon_id, c, enable=True, # unconditionally enable the new unit start=active) else: