a few fixes about initscripts under systemd
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 12 Mar 2015 15:46:59 +0000 (16:46 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 12 Mar 2015 15:46:59 +0000 (16:46 +0100)
initscript.py
sliver-systemd/vinit.service
sliver_lxc.py

index 29acd2e..0a3b17b 100644 (file)
@@ -76,16 +76,14 @@ class Initscript:
                 logger.log_exc("Initscript failed to create enabling symlink %s" % enable_link,name=name)
 
 
-#ln -s '/usr/lib/systemd/system/vinit.service' '/etc/systemd/system/multi-user.target.wants/vinit.service'
-
-
     # install or remove the slice inistscript, as instructed by the initscript tag
-    def refresh_slice_vinit(self):
-        code=self.initscript
-        sliver_initscript="/vservers/%s/etc/rc.d/init.d/vinit.slice"%self.name
-        if tools.replace_file_with_string(sliver_initscript,code,remove_if_empty=True,chmod=0755):
+    def refresh_slice_vinit(self, force=False):
+        logger.log("initscript.refresh_slice_vinit {}".format(self.name))
+        code = self.initscript
+        sliver_initscript="/vservers/%s/etc/rc.d/init.d/vinit.slice" % self.name
+        if tools.replace_file_with_string(sliver_initscript, code, remove_if_empty=True, chmod=0755) or force:
             if code:
-                logger.log("Initscript: %s: Installed new initscript in %s"%(self.name,sliver_initscript))
+                logger.log("Initscript: %s: Installed new initscript in %s" % (self.name, sliver_initscript))
                 if self.is_running():
                     # Only need to rerun the initscript if the vserver is
                     # already running. If the vserver isn't running, then the
@@ -93,5 +91,6 @@ class Initscript:
                     # /etc/rc.d/vinit when the vserver is started.
                     self.rerun_slice_vinit()
             else:
-                logger.log("Initscript: %s: Removed obsolete initscript %s"%(self.name,sliver_initscript))
-
+                logger.log("Initscript: %s: Removed obsolete initscript %s" % (self.name, sliver_initscript))
+        else:
+            logger.debug("initscript.refresh_slice_vinit {} - void".format(self.name))
index 55a408d..744897e 100644 (file)
@@ -8,10 +8,8 @@ After=network-online.target
 [Service]
 Type=oneshot
 RemainAfterExit=yes
-#ExecStart=/bin/bash -c '/etc/rc.d/init.d/vinit.slice start $(cat /etc/slicename) 2>&1 >> /var/log/vinit &'
-#ExecStop=/bin/bash -c '/etc/rc.d/init.d/vinit.slice stop $(cat /etc/slicename) 2>&1 >> /var/log/vinit &'
-ExecStart=/usr/bin/vinit.start
-ExecStop=/usr/bin/vinit.stop
+ExecStart=/bin/bash -c ' /etc/rc.d/init.d/vinit.slice start $(cat /etc/slicename) 2>&1 >> /var/log/vinit & '
+ExecStop=/bin/bash -c ' /etc/rc.d/init.d/vinit.slice stop $(cat /etc/slicename) 2>&1 >> /var/log/vinit & '
 
 [Install]
 WantedBy=multi-user.target
index b7cd45f..518f291 100644 (file)
@@ -62,20 +62,27 @@ class Sliver_LXC(Sliver_Libvirt, Initscript):
             Account.mount_ssh_dir(self.name)
         Sliver_Libvirt.start(self, delay)
         # if a change has occured in the slice initscript, reflect this in /etc/init.d/vinit.slice
-        self.refresh_slice_vinit()
-
-    def rerun_slice_vinit (self):
-        """This is called whenever the initscript code changes"""
-        # xxx - todo - not sure exactly how to:
-        # (.) invoke something in the guest
-        # (.) which options of systemctl should be used to trigger a restart
-        # should not prevent the first run from going fine hopefully
-        logger.log("WARNING: sliver_lxc.rerun_slice_vinit not implemented yet")
-
+        self.refresh_slice_vinit(force=True)
+
+    def rerun_slice_vinit(self):
+        """This is called at startup, and whenever the initscript code changes"""
+        logger.log("sliver_lxc.rerun_slice_vinit {}".format(self.name))
+        plain = "virsh -c lxc:/// lxc-enter-namespace --noseclabel -- {} /usr/bin/systemctl --system daemon-reload"\
+            .format(self.name)
+        command = plain.split()
+        logger.log_call(command, timeout=3)
+        plain = "virsh -c lxc:/// lxc-enter-namespace --noseclabel -- {} /usr/bin/systemctl restart vinit.service"\
+            .format(self.name)
+        command = plain.split()
+        logger.log_call(command, timeout=3)
+                
+        
     @staticmethod
     def create(name, rec=None):
-        ''' Create dirs, copy fs image, lxc_create '''
-        logger.verbose ('sliver_lxc: %s create'%(name))
+        '''
+        Create dirs, copy fs image, lxc_create
+        '''
+        logger.verbose('sliver_lxc: %s create' % name)
         conn = Sliver_Libvirt.getConnection(Sliver_LXC.TYPE)
 
         vref = rec['vref']