From: Milan Broz Date: Wed, 5 Aug 2015 12:49:57 +0000 (+0200) Subject: ceph-disk: set owner of created files to ceph X-Git-Tag: v9.1.0~294^2~12 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=09db67fdb5d6aacff27794550b0df3f90bd21df4;p=ceph.git ceph-disk: set owner of created files to ceph Signed-off-by: Milan Broz --- diff --git a/src/ceph-disk b/src/ceph-disk index 85196f94c235..20be6673ff3d 100755 --- a/src/ceph-disk +++ b/src/ceph-disk @@ -32,6 +32,8 @@ import tempfile import uuid import time import shlex +import pwd +import grp """ Prepare: @@ -710,6 +712,12 @@ def get_osd_id(path): check_osd_id(osd_id) return osd_id +def get_ceph_user(): + if pwd.getpwnam('ceph') and grp.getgrnam('ceph'): + return 'ceph' + else: + return 'root' + def path_set_context(path): # restore selinux context to default policy values if which('restorecon'): @@ -720,6 +728,15 @@ def path_set_context(path): ], ) + # if ceph user exists, set owner to ceph + if get_ceph_user() == 'ceph': + command( + [ + 'chown', '-R', 'ceph:ceph', + path, + ], + ) + def _check_output(args=None, **kwargs): out, ret = command(args, **kwargs) if ret: @@ -1806,6 +1823,8 @@ def mkfs( '--osd-journal', os.path.join(path, 'journal'), '--osd-uuid', fsid, '--keyring', os.path.join(path, 'keyring'), + '--setuser', get_ceph_user(), + '--setgroup', get_ceph_user(), ], ) # TODO ceph-osd --mkfs removes the monmap file?