diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/ceph-volume/ceph_volume/systemd/systemctl.py | |
parent | Initial commit. (diff) | |
download | ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/ceph-volume/ceph_volume/systemd/systemctl.py')
-rw-r--r-- | src/ceph-volume/ceph_volume/systemd/systemctl.py | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/src/ceph-volume/ceph_volume/systemd/systemctl.py b/src/ceph-volume/ceph_volume/systemd/systemctl.py new file mode 100644 index 00000000..778ad147 --- /dev/null +++ b/src/ceph-volume/ceph_volume/systemd/systemctl.py @@ -0,0 +1,101 @@ +""" +Utilities to control systemd units +""" +import logging + +from ceph_volume import process + +logger = logging.getLogger(__name__) + +def start(unit): + process.run(['systemctl', 'start', unit]) + + +def stop(unit): + process.run(['systemctl', 'stop', unit]) + + +def enable(unit, runtime=False): + if runtime: + process.run(['systemctl', 'enable', '--runtime', unit]) + else: + process.run(['systemctl', 'enable', unit]) + + +def disable(unit): + process.run(['systemctl', 'disable', unit]) + + +def mask(unit): + process.run(['systemctl', 'mask', unit]) + + +def is_active(unit): + out, err, rc = process.call( + ['systemctl', 'is-active', unit], + verbose_on_failure=False + ) + return rc == 0 + +def get_running_osd_ids(): + out, err, rc = process.call([ + 'systemctl', + 'show', + '--no-pager', + '--property=Id', + '--state=running', + 'ceph-osd@*', + ]) + osd_ids = [] + if rc == 0: + for line in out: + if line: + # example line looks like: Id=ceph-osd@1.service + try: + osd_id = line.split("@")[1].split(".service")[0] + osd_ids.append(osd_id) + except (IndexError, TypeError): + logger.warning("Failed to parse output from systemctl: %s", line) + return osd_ids + +def start_osd(id_): + return start(osd_unit % id_) + + +def stop_osd(id_): + return stop(osd_unit % id_) + + +def enable_osd(id_): + return enable(osd_unit % id_, runtime=True) + + +def disable_osd(id_): + return disable(osd_unit % id_) + + +def osd_is_active(id_): + return is_active(osd_unit % id_) + + +def enable_volume(id_, fsid, device_type='lvm'): + return enable(volume_unit % (device_type, id_, fsid)) + + +def mask_ceph_disk(): + # systemctl allows using a glob like '*' for masking, but there was a bug + # in that it wouldn't allow this for service templates. This means that + # masking ceph-disk@* will not work, so we must link the service directly. + # /etc/systemd takes precedence regardless of the location of the unit + process.run( + ['ln', '-sf', '/dev/null', '/etc/systemd/system/ceph-disk@.service'] + ) + + +# +# templates +# + +osd_unit = "ceph-osd@%s" +ceph_disk_unit = "ceph-disk@%s" +volume_unit = "ceph-volume@%s-%s-%s" |