]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
create a is_systemd helper
authorAlfredo Deza <alfredo.deza@inktank.com>
Tue, 23 Sep 2014 12:54:13 +0000 (08:54 -0400)
committerAlfredo Deza <alfredo.deza@inktank.com>
Tue, 23 Sep 2014 16:56:23 +0000 (12:56 -0400)
Signed-off-by: Alfredo Deza <alfredo.deza@inktank.com>
ceph_deploy/util/system.py

index 74e33c2c57866b17cac44091efe241827dd30275..7665dff794c3d5521a8ad33443c40705dbb88184 100644 (file)
@@ -1,4 +1,5 @@
 from ceph_deploy.exc import ExecutableNotFound
+from ceph_deploy.lib import remoto
 
 
 def executable_path(conn, executable):
@@ -13,3 +14,45 @@ def executable_path(conn, executable):
     if not executable_path:
         raise ExecutableNotFound(executable, conn.hostname)
     return executable_path
+
+
+def is_systemd(conn):
+    """
+    Attempt to detect if a remote system is a systemd one or not
+    by looking into ``/proc`` just like the ceph init script does::
+
+        # detect systemd
+        # SYSTEMD=0
+        grep -qs systemd /proc/1/comm && SYSTEMD=1
+    """
+    return conn.remote_module.grep(
+        'systemd',
+        '/proc/1/comm'
+    )
+
+
+def enable_service(conn, service='ceph'):
+    """
+    Enable a service on a remote host depending on the type of init system.
+    Obviously, this should be done for RHEL/Fedora/CentOS systems.
+
+    This function does not do any kind of detection.
+    """
+    if is_systemd(conn):
+        remoto.process.run(
+            conn,
+            [
+                'systemctl',
+                'enable',
+                'ceph',
+            ]
+        )
+    else:
+        remoto.process.run(
+            conn,
+            [
+                'chkconfig',
+                'ceph',
+                'on',
+            ]
+        )