X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sliver_vs.py;h=57de4f944365fe7165a03ea1b159ad51e078cee6;hb=refs%2Fheads%2F1.8;hp=7ee1825595185d7f4839afc90e052e09d2f8166c;hpb=93e6938856540ba2f4ed050a7631281aa2b63f3f;p=nodemanager.git diff --git a/sliver_vs.py b/sliver_vs.py index 7ee1825..57de4f9 100644 --- a/sliver_vs.py +++ b/sliver_vs.py @@ -19,6 +19,7 @@ don't have to guess if there is a running process or not. import errno import traceback import os, os.path +import sys import time import vserver @@ -27,6 +28,7 @@ import accounts import logger import tools from threading import BoundedSemaphore +import subprocess globalsem = BoundedSemaphore() @@ -148,6 +150,9 @@ class Sliver_VS(accounts.Account, vserver.VServer): def destroy(name): logger.log_call('/usr/sbin/vuserdel', name) def configure(self, rec): + # in case we update nodemanager.. + self.install_and_enable_vinit() + new_rspec = rec['_rspec'] if new_rspec != self.rspec: self.rspec = new_rspec @@ -182,6 +187,11 @@ class Sliver_VS(accounts.Account, vserver.VServer): except: logger.log_exc("vsliver_vs: %s: failed to create runlevel3 symlink %s"%rc3_link) + def rerun_slice_vinit(self): + command = "/usr/sbin/vserver %s exec /etc/rc.d/init.d/vinit restart" % (self.name) + logger.log("vsliver_vs: %s: Rerunning slice initscript: %s" % (self.name, command)) + subprocess.call(command + "&", stdin=open('/dev/null', 'r'), stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT, shell=True) + # this one checks for the existence of the slice initscript # install or remove the slice inistscript, as instructed by the initscript tag def refresh_slice_vinit(self): @@ -190,6 +200,12 @@ class Sliver_VS(accounts.Account, vserver.VServer): if tools.replace_file_with_string(sliver_initscript,body,remove_if_empty=True,chmod=0755): if body: logger.log("vsliver_vs: %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("vsliver_vs: %s: Removed obsolete initscript %s"%(self.name,sliver_initscript))