X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=python%2Fvserver.py;h=8aa410e17d691c80feca75205653fae0d7baea32;hb=8c938b9ba948fdb03ead8d12ec2a968e3ad5f999;hp=69e150cef5ee61629af1c7423e2248b504c60ee4;hpb=e42b91ff38049501d06ec043cf2d49ee43881fb9;p=util-vserver-pl.git diff --git a/python/vserver.py b/python/vserver.py index 69e150c..8aa410e 100644 --- a/python/vserver.py +++ b/python/vserver.py @@ -369,40 +369,47 @@ class VServer: state_file.close() if vserverimpl.chcontext(self.ctx, vserverimpl.text2bcaps(self.get_capabilities_config())): - self.set_resources() + self.set_resources(True) vserverimpl.setup_done(self.ctx) + def __prep(self, runlevel): """ Perform all the crap that the vserver script does before actually executing the startup scripts. """ - # remove /var/run and /var/lock/subsys files - # but don't remove utmp from the top-level /var/run - RUNDIR = "/var/run" - LOCKDIR = "/var/lock/subsys" - filter_fn = lambda fs: filter(lambda f: f != 'utmp', fs) - garbage = reduce((lambda (out, ff), (dir, subdirs, files): - (out + map((dir + "/").__add__, ff(files)), - lambda fs: fs)), - list(os.walk(RUNDIR)), - ([], filter_fn))[0] - garbage += filter(os.path.isfile, map((LOCKDIR + "/").__add__, - os.listdir(LOCKDIR))) - if False: - for f in garbage: - os.unlink(f) # set the initial runlevel - vserverimpl.setrunlevel(RUNDIR + "/utmp", runlevel) + vserverimpl.setrunlevel(self.dir + "/var/run/utmp", runlevel) # mount /proc and /dev/pts self.__do_mount("none", self.dir, "/proc", "proc") # XXX - magic mount options self.__do_mount("none", self.dir, "/dev/pts", "devpts", 0, "gid=5,mode=0620") - def __do_mount(self, *mount_args): + def __cleanvar(self): + """ + Clean the /var/ directory so RH startup scripts can run + """ + + RUNDIR = "/var/run" + LOCKDIR = "/var/lock/subsys" + + filter = ["utmp"] + garbage = [] + for topdir in [RUNDIR, LOCKDIR]: + #os.walk() = (dirpath, dirnames, filenames) + for root, dirs, files in os.walk(topdir): + for file in files: + if not file in filter: + garbage.append(root + "/" + file) + + for f in garbage: os.unlink(f) + return garbage + + + def __do_mount(self, *mount_args): try: vserverimpl.mount(*mount_args) except OSError, ex: @@ -411,11 +418,13 @@ class VServer: return raise ex + def enter(self): self.config.cache_it() self.__do_chroot() self.__do_chcontext(None) + def start(self, runlevel = 3): if (os.fork() != 0): @@ -445,13 +454,17 @@ class VServer: self.config.cache_it() self.__do_chroot() + removed = self.__cleanvar() + log = open("/var/log/boot.log", "a", 0) if log.fileno() != 1: os.dup2(log.fileno(), 1) os.dup2(1, 2) + print >>log, ("%s: removing %s" % + (time.asctime(time.gmtime()), removed)) print >>log, ("%s: starting the virtual server %s" % - (time.asctime(time.gmtime()), self.name)) + (time.asctime(time.gmtime()), self.name)) # execute each init script in turn # XXX - we don't support all scripts that vserver script does self.__do_chcontext(state_file) @@ -472,7 +485,7 @@ class VServer: self.log(traceback.format_exc()) os._exit(0) - def set_resources(self): + def set_resources(self,setup=False): """ Called when vserver context is entered for first time, should be overridden by subclass. """