From 0fc41ff1973ac16a261c90767173cb8343f3faa2 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Fri, 13 Mar 2015 12:02:24 +0100 Subject: [PATCH] deprecate refresh_slice_vinit and move this code up to Initscript.configure --- initscript.py | 45 ++++++++++++++++++--------------------------- sliver_lxc.py | 4 ++-- sliver_vs.py | 11 ++++++----- 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/initscript.py b/initscript.py index 3548394..8e6e4a3 100644 --- a/initscript.py +++ b/initscript.py @@ -10,14 +10,25 @@ class Initscript: self.initscript = '' def configure(self, rec): -# logger.log("Initscript.configure") + # install or remove the slice inistscript, as instructed by the initscript tag new_initscript = rec['initscript'] - if new_initscript != self.initscript: - self.initscript = new_initscript - # not used anymore, we always check against the installed script - #self.initscriptchanged = True - self.refresh_slice_vinit() - + if new_initscript == self.initscript: + return + logger.log("initscript.configure {}".format(self.name)) + self.initscript = new_initscript + 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): + if code: + 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 + # initscript will automatically be started by + # /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)) def install_and_enable_vinit(self): "prepare sliver rootfs init and systemd so the vinit service kicks in" # the fact that systemd attempts to run old-style services @@ -74,23 +85,3 @@ class Initscript: os.symlink(enable_target, enable_link) except: logger.log_exc("Initscript failed to create enabling symlink %s" % enable_link,name=name) - - - # install or remove the slice inistscript, as instructed by the initscript tag - def refresh_slice_vinit(self): - 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): - if code: - 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 - # initscript will automatically be started by - # /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)) - else: - logger.log("initscript.refresh_slice_vinit {} - void".format(self.name)) diff --git a/sliver_lxc.py b/sliver_lxc.py index 5892eed..8a8ebed 100644 --- a/sliver_lxc.py +++ b/sliver_lxc.py @@ -65,9 +65,9 @@ class Sliver_LXC(Sliver_Libvirt, Initscript): # expose .ssh for omf_friendly slivers if 'tags' in self.rspec and 'omf_control' in self.rspec['tags']: Account.mount_ssh_dir(self.name) +# logger.log("NM is exiting for debug - just about to start {}".format(self.name)) +# exit(0) 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 at startup, and whenever the initscript code changes""" diff --git a/sliver_vs.py b/sliver_vs.py index c4dfadb..a1f1b66 100644 --- a/sliver_vs.py +++ b/sliver_vs.py @@ -148,11 +148,14 @@ class Sliver_VS(vserver.VServer, Account, Initscript): self.set_resources() # do the configure part from Initscript - Initscript.configure(self,rec) - - Account.configure(self, rec) # install ssh keys + # i.e. install slice initscript if defined + Initscript.configure(self, rec) + # install ssh keys + Account.configure(self, rec) # remember configure() always gets called *before* start() + # in particular the slice initscript + # is expected to be in place already at this point def start(self, delay=0): if self.rspec['enabled'] <= 0: logger.log('sliver_vs: not starting %s, is not enabled'%self.name) @@ -164,8 +167,6 @@ class Sliver_VS(vserver.VServer, Account, Initscript): # expose .ssh for omf_friendly slivers if 'omf_control' in self.rspec['tags']: Account.mount_ssh_dir(self.name) - # if a change has occured in the slice initscript, reflect this in /etc/init.d/vinit.slice - self.refresh_slice_vinit() child_pid = os.fork() if child_pid == 0: # VServer.start calls fork() internally, -- 2.43.0