+ try:
+ logger.log("vsliver_vs: %s: creating runlevel3 symlink %s"%(self.name,rc3_link))
+ os.symlink(rc3_target,rc3_link)
+ 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):
+ 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("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))
+
+ # bind mount root side dir to sliver side
+ # needs to be done before sliver starts
+ def expose_ssh_dir (self):
+ try:
+ root_ssh="/home/%s/.ssh"%self.name
+ sliver_ssh="/vservers/%s/home/%s/.ssh"%(self.name,self.name)
+ # any of both might not exist yet
+ for path in [root_ssh,sliver_ssh]:
+ if not os.path.exists (path):
+ os.mkdir(path)
+ if not os.path.isdir (path):
+ raise Exception
+ mounts=file('/proc/mounts').read()
+ if mounts.find(sliver_ssh)<0:
+ # xxx perform mount
+ subprocess.call("mount --bind -o ro %s %s"%(root_ssh,sliver_ssh),shell=True)
+ logger.log("expose_ssh_dir: %s mounted into slice %s"%(root_ssh,self.name))
+ except:
+ logger.log_exc("expose_ssh_dir with slice %s failed"%self.name)