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
# /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))
[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
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']