Răsfoiți Sursa

(fix) restore sudo-capability after recent changes (#3964)

tobitege 1 an în urmă
părinte
comite
45066f19dc
2 a modificat fișierele cu 7 adăugiri și 10 ștergeri
  1. 5 10
      openhands/runtime/client/client.py
  2. 2 0
      openhands/runtime/client/runtime.py

+ 5 - 10
openhands/runtime/client/client.py

@@ -184,16 +184,11 @@ class RuntimeClient:
                 raise
 
         # Add sudoer
-        sudoer_line = r'%sudo ALL=(ALL) NOPASSWD:ALL\n'
-        sudoers_path = '/etc/sudoers.d/99_sudo'
-        if not Path(sudoers_path).exists():
-            with open(sudoers_path, 'w') as f:
-                f.write(sudoer_line)
-            output = subprocess.run(['chmod', '0440', sudoers_path])
-            if output.returncode != 0:
-                logger.error('Failed to chmod 99_sudo file!')
-            else:
-                logger.debug('Added sudoer successfully.')
+        sudoer_line = r"echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers"
+        output = subprocess.run(sudoer_line, shell=True, capture_output=True)
+        if output.returncode != 0:
+            raise RuntimeError(f'Failed to add sudoer: {output.stderr.decode()}')
+        logger.debug(f'Added sudoer successfully. Output: [{output.stdout.decode()}]')
 
         command = (
             f'useradd -rm -d /home/{username} -s /bin/bash '

+ 2 - 0
openhands/runtime/client/runtime.py

@@ -171,6 +171,8 @@ class EventStreamRuntime(Runtime):
         # will initialize both the event stream and the env vars
         super().__init__(config, event_stream, sid, plugins, env_vars)
 
+        self._wait_until_alive()
+
         logger.info(
             f'Container initialized with plugins: {[plugin.name for plugin in self.plugins]}'
         )