]> glassweightruler.freedombox.rocks Git - waydroid.git/blobdiff - tools/actions/container_manager.py
tools: Drop need of sudo as much as possible
[waydroid.git] / tools / actions / container_manager.py
index 994dceab4fcee7da96815183a5fcb74b68b36689..37ab7e7f6a7d7a25151fa82198dc1eaf3c437081 100644 (file)
@@ -48,7 +48,7 @@ def start(args):
         def chmod(path, mode):
             if os.path.exists(path):
                 command = ["chmod", mode, "-R", path]
-                tools.helpers.run.root(args, command, check=False)
+                tools.helpers.run.user(args, command, check=False)
 
         # Nodes list
         if not perm_list:
@@ -70,10 +70,6 @@ def start(args):
                 # Graphics
                 "/dev/dri",
                 "/dev/graphics",
-
-                # Wayland and pulse socket permissions
-                session_cfg["session"]["pulse_runtime_path"],
-                session_cfg["session"]["xdg_runtime_dir"]
             ]
 
             # Framebuffers
@@ -122,11 +118,11 @@ def start(args):
         # Networking
         command = [tools.config.tools_src +
                    "/data/scripts/waydroid-net.sh", "start"]
-        tools.helpers.run.root(args, command, check=False)
+        tools.helpers.run.user(args, command, check=False)
 
         # Sensors
-        tools.helpers.run.root(
-            args, ["waydroid-sensord", args.HWBINDER_DRIVER], output="background")
+        tools.helpers.run.user(
+            args, ["waydroid-sensord", "/dev/" + args.HWBINDER_DRIVER], output="background")
 
         # Mount rootfs
         helpers.images.mount_rootfs(args, cfg["waydroid"]["images_path"])
@@ -138,23 +134,31 @@ def start(args):
         # Cgroup hacks
         if which("start"):
             command = ["start", "cgroup-lite"]
-            tools.helpers.run.root(args, command, check=False)
+            tools.helpers.run.user(args, command, check=False)
         helpers.mount.umount_all(args, "/sys/fs/cgroup/schedtune")
 
         #TODO: remove NFC hacks
         if which("stop"):
             command = ["stop", "nfcd"]
-            tools.helpers.run.root(args, command, check=False)
+            tools.helpers.run.user(args, command, check=False)
 
         # Set permissions
         set_permissions()
         
         helpers.lxc.start(args)
         session_cfg["session"]["state"] = helpers.lxc.status(args)
+        timeout = 10
+        while session_cfg["session"]["state"] != "RUNNING" and timeout > 0:
+            session_cfg["session"]["state"] = helpers.lxc.status(args)
+            logging.info(
+                "waiting {} seconds for container to start...".format(timeout))
+            timeout = timeout - 1
+            time.sleep(1)
+        if session_cfg["session"]["state"] != "RUNNING":
+            raise OSError("container failed to start")
         tools.config.save_session(session_cfg)
 
-        if not hasattr(args, 'hardwareLoop'):
-            services.hardware_manager.start(args)
+        services.hardware_manager.start(args)
 
         signal.signal(signal.SIGINT, signal_handler)
         while os.path.exists(tools.config.session_defaults["config_path"]):
@@ -170,6 +174,7 @@ def start(args):
 
         logging.warning("session manager stopped, stopping container and waiting...")
         stop(args)
+        services.hardware_manager.stop(args)
         start(args)
     else:
         logging.error("WayDroid container is {}".format(status))
@@ -186,24 +191,32 @@ def stop(args):
         # Networking
         command = [tools.config.tools_src +
                    "/data/scripts/waydroid-net.sh", "stop"]
-        tools.helpers.run.root(args, command, check=False)
+        tools.helpers.run.user(args, command, check=False)
 
         #TODO: remove NFC hacks
         if which("start"):
             command = ["start", "nfcd"]
-            tools.helpers.run.root(args, command, check=False)
+            tools.helpers.run.user(args, command, check=False)
 
         # Sensors
         if which("waydroid-sensord"):
             command = ["pidof", "waydroid-sensord"]
-            pid = tools.helpers.run.root(args, command, check=False, output_return=True)
+            pid = tools.helpers.run.user(args, command, check=False, output_return=True)
             if pid:
-                command = ["killall", pid]
-                tools.helpers.run.root(args, command, check=False)
+                command = ["kill", "-9", pid]
+                tools.helpers.run.user(args, command, check=False)
 
     else:
         logging.error("WayDroid container is {}".format(status))
 
+def restart(args):
+    status = helpers.lxc.status(args)
+    if status == "RUNNING":
+        helpers.lxc.stop(args)
+        helpers.lxc.start(args)
+    else:
+        logging.error("WayDroid container is {}".format(status))
+
 def freeze(args):
     status = helpers.lxc.status(args)
     if status == "RUNNING":