Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / ceph-detect-init / ceph_detect_init / gentoo / __init__.py
1 import os
2 distro = None
3 release = None
4 codename = None
5
6
7 # From ceph-disk, but there is no way to access it since it's not in a module
8 def is_systemd():
9     """
10     Detect whether systemd is running;
11     WARNING: not mutually exclusive with openrc
12     """
13     with open('/proc/1/comm') as i:
14         return 'systemd' in i.read()
15
16
17 def is_openrc():
18     """
19     Detect whether openrc is running.
20     """
21     OPENRC_CGROUP = '/sys/fs/cgroup/openrc'
22     return os.path.isdir(OPENRC_CGROUP)
23
24
25 def choose_init():
26     """Select a init system
27
28     Returns the name of a init system (upstart, sysvinit ...).
29     """
30     if is_openrc():
31         return 'openrc'
32     if is_systemd():
33         return 'systemd'
34     return 'unknown'