#!/usr/bin/env python3
-CEPH_USER_UID=167
-CEPH_USER_GID=167
DEFAULT_IMAGE='ceph/daemon-base'
DATA_DIR='/var/lib/ceph'
LOG_DIR='/var/log/ceph'
def get_log_dir(base, fsid):
return base + '/' + fsid
-def get_daemon_args(fsid, daemon_type, daemon_id):
+def get_daemon_args(fsid, daemon_type, daemon_id, uid, gid):
r = [
'--default-admin-socket', '/var/run/ceph/' + fsid + '-' + daemon_type + '.' + daemon_id + '.asok',
'--default-log-to-file=false',
'--default-log-to-stderr=true',
]
- if args.uid != 0:
- r = r + ['--setuser', str(args.uid)]
- if args.gid != 0:
- r = r + ['--setgroup', str(args.gid)]
+ r += ['--setuser', str(uid)]
+ r += ['--setgroup', str(gid)]
return r
-
-def create_daemon_dirs(fsid, daemon_type, daemon_id,
+def create_daemon_dirs(fsid, daemon_type, daemon_id, uid, gid,
config=None, keyring=None):
data_dir = get_data_dir(args.data_dir, fsid, daemon_type, daemon_id)
makedirs(data_dir)
- if args.uid and args.gid:
- os.chown(data_dir, args.uid, args.gid)
+ os.chown(data_dir, uid, gid)
log_dir = get_log_dir(args.log_dir, fsid)
makedirs(log_dir)
- if args.uid and args.gid:
- os.chown(log_dir, args.uid, args.gid)
+ os.chown(log_dir, uid, gid)
if config:
with open(data_dir + '/conf', 'w') as f:
f.write(config)
- if args.uid and args.gid:
- os.fchown(f.fileno(), args.uid, args.gid)
+ os.fchown(f.fileno(), uid, gid)
if keyring:
with open(data_dir + '/keyring', 'w') as f:
f.write(keyring)
os.fchmod(f.fileno(), 0o600)
- if args.uid and args.gid:
- os.fchown(f.fileno(), args.uid, args.gid)
+ os.fchown(f.fileno(), uid, gid)
def get_config_and_keyring():
if args.conf_and_key:
config = f.read()
return (config, keyring)
-def get_container(fsid, daemon_type, daemon_id):
+def get_container(fsid, daemon_type, daemon_id, uid, gid):
data_dir = get_data_dir(args.data_dir, fsid, daemon_type, daemon_id)
log_dir = get_log_dir(args.log_dir, fsid)
args=['-i', daemon_id,
'-c', cdata_dir + '/conf',
'-f', # foreground
- ] + extra_args + get_daemon_args(fsid, daemon_type, daemon_id),
+ ] + extra_args + get_daemon_args(fsid, daemon_type, daemon_id, uid, gid),
volume_mounts={
log_dir: '/var/log/ceph:z',
data_dir: cdata_dir + ':z',
cname='ceph-%s-%s.%s' % (fsid, daemon_type, daemon_id),
)
-def deploy_daemon(fsid, daemon_type, daemon_id, c, config=None, keyring=None):
+def extract_uid_gid():
+ out = CephContainer(
+ image=args.image,
+ entrypoint='grep',
+ args=['ceph', '/etc/passwd'],
+ ).run().decode('utf-8')
+ (uid, gid) = out.split(':')[2:4]
+ return (int(uid), int(gid))
+
+def deploy_daemon(fsid, daemon_type, daemon_id, c, uid, gid,
+ config=None, keyring=None):
# dirs, conf, keyring
create_daemon_dirs(
fsid, daemon_type, daemon_id,
+ uid, gid,
config, keyring)
# cmd
mgr_id = args.mgr_id or get_hostname()
logging.info('cluster fsid: %s' % fsid)
+ (uid, gid) = extract_uid_gid()
+
# create some initial keys
mon_key = CephContainer(
image=args.image,
# tmp keyring file
tmp_keyring = tempfile.NamedTemporaryFile(mode='w')
os.fchmod(tmp_keyring.fileno(), 0o600)
- if args.uid and args.gid:
- os.fchown(tmp_keyring.fileno(), args.uid, args.gid)
+ os.fchown(tmp_keyring.fileno(), uid, gid)
tmp_keyring.write(keyring)
tmp_keyring.flush()
).run()
# create mon
- create_daemon_dirs(fsid, 'mon', mon_id)
+ create_daemon_dirs(fsid, 'mon', mon_id, uid, gid)
mon_dir = get_data_dir(args.data_dir, fsid, 'mon', mon_id)
log_dir = get_log_dir(args.log_dir, fsid)
out = CephContainer(
'--monmap', '/tmp/monmap',
'--keyring', '/tmp/keyring',
'--debug-mon', '20',
- ] + get_daemon_args(fsid, 'mon', mon_id),
+ ] + get_daemon_args(fsid, 'mon', mon_id, uid, gid),
volume_mounts={
log_dir: '/var/log/ceph:z',
mon_dir: '/var/lib/ceph/mon/ceph-%s:z' % (mon_id),
with open(mon_dir + '/conf', 'w') as f:
f.write(config)
- mon_c = get_container(fsid, 'mon', mon_id)
- deploy_daemon(fsid, 'mon', mon_id, mon_c)
+ mon_c = get_container(fsid, 'mon', mon_id, uid, gid)
+ deploy_daemon(fsid, 'mon', mon_id, mon_c, uid, gid)
# create mgr
mgr_keyring = '[mgr.%s]\n\tkey = %s\n' % (mgr_id, mgr_key)
- mgr_c = get_container(fsid, 'mgr', mgr_id)
- deploy_daemon(fsid, 'mgr', mgr_id, mgr_c, config, mgr_keyring)
+ mgr_c = get_container(fsid, 'mgr', mgr_id, uid, gid)
+ deploy_daemon(fsid, 'mgr', mgr_id, mgr_c, uid, gid, config, mgr_keyring)
# output files
if args.output_keyring:
if daemon_type not in ['mon', 'mgr', 'mds', 'osd', 'rgw']:
raise RuntimeError('daemon type %s not recognized' % daemon_type)
(config, keyring) = get_config_and_keyring()
-
- c = get_container(args.fsid, daemon_type, daemon_id)
- deploy_daemon(args.fsid, daemon_type, daemon_id, c, config, keyring)
+ (uid, gid) = extract_uid_gid()
+ c = get_container(args.fsid, daemon_type, daemon_id, uid, gid)
+ deploy_daemon(args.fsid, daemon_type, daemon_id, c, uid, gid,
+ config, keyring)
##################################
def command_run():
(daemon_type, daemon_id) = args.name.split('.')
- c = get_container(args.fsid, daemon_type, daemon_id)
+ (uid, gid) = extract_uid_gid()
+ c = get_container(args.fsid, daemon_type, daemon_id, uid, gid)
c.run()
'--image',
default=DEFAULT_IMAGE,
help='container image')
-parser.add_argument(
- '--uid',
- default=CEPH_USER_UID,
- help='UID to use for new folders/files')
-parser.add_argument(
- '--gid',
- default=CEPH_USER_GID,
- help='GID to use for new folders/files')
parser.add_argument(
'--conf', '-c',
help='ceph conf file to incorporate')