Don't wait for the initscripts to complete.
[util-vserver.git] / python / vserver.py
index 372f2aa..de8c164 100644 (file)
@@ -14,9 +14,6 @@ import traceback
 import subprocess
 import resource
 
-import mountimpl
-import runcmd
-import utmp
 import vserverimpl
 import cpulimit, bwlimit
 
@@ -396,18 +393,18 @@ class VServer:
 
         # set the initial runlevel
         f = open(RUNDIR + "/utmp", "w")
-        utmp.set_runlevel(f, runlevel)
+        vserverimpl.setrunlevel(f, runlevel)
         f.close()
 
         # mount /proc and /dev/pts
-        self.__do_mount("none", "/proc", "proc")
+        self.__do_mount("none", self.dir, "/proc", "proc")
         # XXX - magic mount options
-        self.__do_mount("none", "/dev/pts", "devpts", 0, "gid=5,mode=0620")
+        self.__do_mount("none", self.dir, "/dev/pts", "devpts", 0, "gid=5,mode=0620")
 
     def __do_mount(self, *mount_args):
 
         try:
-            mountimpl.mount(*mount_args)
+            vserverimpl.mount(*mount_args)
         except OSError, ex:
             if ex.errno == errno.EBUSY:
                 # assume already mounted
@@ -459,7 +456,7 @@ class VServer:
                          cmd_args = [cmd[0]] + map(lambda x: x % arg_subst,
                                                    cmd[1:])
                          print >>log, "executing '%s'" % " ".join(cmd_args)
-                         os.spawnvp(os.P_WAIT,cmd[0],cmd_args)
+                         os.spawnvp(os.P_NOWAIT,cmd[0],cmd_args)
                      except:
                          traceback.print_exc()
                          os._exit(1)
@@ -508,10 +505,17 @@ class VServer:
 
 def create(vm_name, static = False, ctor = VServer):
 
-    options = []
+    options = ['vuseradd']
     if static:
         options += ['--static']
-    runcmd.run('vuseradd', options + [vm_name])
+    ret = os.spawnvp(os.P_WAIT, 'vuseradd', options + [vm_name])
+    if !os.WIFEXITED(ret) || os.WEXITSTATUS(ret) != 0:
+        out = "system command ('%s') " % options
+        if os.WIFEXITED(ret):
+            out += "failed, rc = %d" % os.WEXITSTATUS(ret)
+        else:
+            out += "killed by signal %d" % os.WTERMSIG(ret)
+        raise SystemError, out
     vm_id = pwd.getpwnam(vm_name)[2]
 
     return ctor(vm_name, vm_id)