]>
Commit | Line | Data |
---|---|---|
d2e6a577 FG |
1 | """ |
2 | Utilities to control systemd units | |
3 | """ | |
4 | from ceph_volume import process | |
5 | ||
6 | ||
7 | def start(unit): | |
b32b8144 | 8 | process.run(['systemctl', 'start', unit]) |
d2e6a577 FG |
9 | |
10 | ||
11 | def stop(unit): | |
b32b8144 | 12 | process.run(['systemctl', 'stop', unit]) |
d2e6a577 FG |
13 | |
14 | ||
1adf2230 AA |
15 | def enable(unit, runtime=False): |
16 | if runtime: | |
17 | process.run(['systemctl', 'enable', '--runtime', unit]) | |
18 | else: | |
19 | process.run(['systemctl', 'enable', unit]) | |
d2e6a577 FG |
20 | |
21 | ||
22 | def disable(unit): | |
b32b8144 | 23 | process.run(['systemctl', 'disable', unit]) |
d2e6a577 FG |
24 | |
25 | ||
3efd9988 | 26 | def mask(unit): |
b32b8144 | 27 | process.run(['systemctl', 'mask', unit]) |
3efd9988 FG |
28 | |
29 | ||
94b18763 FG |
30 | def is_active(unit): |
31 | out, err, rc = process.call( | |
32 | ['systemctl', 'is-active', unit], | |
33 | verbose_on_failure=False | |
34 | ) | |
35 | return rc == 0 | |
36 | ||
37 | ||
d2e6a577 FG |
38 | def start_osd(id_): |
39 | return start(osd_unit % id_) | |
40 | ||
41 | ||
42 | def stop_osd(id_): | |
43 | return stop(osd_unit % id_) | |
44 | ||
45 | ||
46 | def enable_osd(id_): | |
1adf2230 | 47 | return enable(osd_unit % id_, runtime=True) |
d2e6a577 FG |
48 | |
49 | ||
50 | def disable_osd(id_): | |
51 | return disable(osd_unit % id_) | |
52 | ||
53 | ||
94b18763 FG |
54 | def osd_is_active(id_): |
55 | return is_active(osd_unit % id_) | |
56 | ||
57 | ||
d2e6a577 FG |
58 | def enable_volume(id_, fsid, device_type='lvm'): |
59 | return enable(volume_unit % (device_type, id_, fsid)) | |
60 | ||
61 | ||
3efd9988 FG |
62 | def mask_ceph_disk(): |
63 | # systemctl allows using a glob like '*' for masking, but there was a bug | |
64 | # in that it wouldn't allow this for service templates. This means that | |
65 | # masking ceph-disk@* will not work, so we must link the service directly. | |
94b18763 | 66 | # /etc/systemd takes precedence regardless of the location of the unit |
3efd9988 | 67 | process.run( |
b32b8144 | 68 | ['ln', '-sf', '/dev/null', '/etc/systemd/system/ceph-disk@.service'] |
3efd9988 FG |
69 | ) |
70 | ||
71 | ||
d2e6a577 FG |
72 | # |
73 | # templates | |
74 | # | |
75 | ||
76 | osd_unit = "ceph-osd@%s" | |
3efd9988 | 77 | ceph_disk_unit = "ceph-disk@%s" |
d2e6a577 | 78 | volume_unit = "ceph-volume@%s-%s-%s" |