Adding remote command execution for linux boxes
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Fri, 9 Nov 2012 16:49:01 +0000 (17:49 +0100)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Fri, 9 Nov 2012 16:49:01 +0000 (17:49 +0100)
src/neco/resources/base/application.py
src/neco/resources/base/linux_node.py
src/neco/util/sshfuncs.py

index 40e07ff..8c91ab9 100644 (file)
@@ -42,7 +42,7 @@ class Application(Resource):
         self.kill()
 
     def run(self):
-        dst = os.path.join(self.app_home, "app.ssh")
+        dst = os.path.join(self.app_home, "app.sh")
         
         # Create shell script with the command
         # This way, complex commands and scripts can be ran seamlessly
@@ -56,8 +56,9 @@ class Application(Resource):
         cmd += self.command
         self.node.upload(cmd, dst)
 
-        cmd = "bash ./app.sh",
-        self.node.run(cmd, self.app_home)
+        command = 'bash ./app.sh'
+        stdin = 'stdin' if self.stdin else None
+        self.node.run(command, self.app_home, stdin = stdin)
         self.pid, self.ppid = self.node.checkpid(self.app_home)
 
     def status(self):
index b7d10cc..e0ec18b 100644 (file)
@@ -1,5 +1,5 @@
 from neco.execution.resource import Resource
-from neco.util.sshfuncs import eintr_retry, shell_escape, rexec, rcopy, \
+from neco.util.sshfuncs import eintr_retry, rexec, rcopy, \
         rspawn, rcheck_pid, rstatus, rkill, RUNNING 
 
 import cStringIO
@@ -131,19 +131,19 @@ class LinuxNode(Resource):
     def mkdir(self, path, clean = True):
         if clean:
             self.execute(
-                "rm -f %s" % shell_escape(path),
+                "rm -rf %s" % path,
                 timeout = 120,
                 retry = 3
                 )
 
         self.execute(
-            "mkdir -p %s" % shell_escape(path),
+            "mkdir -p %s" % path,
             timeout = 120,
             retry = 3
             )
 
     def run(self, command, home, 
-            stdin = 'stdin'
+            stdin = None
             stdout = 'stdout', 
             stderr = 'stderr', 
             sudo = False):
index 77698ca..347056f 100644 (file)
@@ -160,8 +160,6 @@ def rexec(command, host, user,
         command = "sudo " + command
     args.append(command)
 
-    print " ".join(args)
-
     for x in xrange(retry or 3):
         # connects to the remote host and starts a remote connection
         proc = subprocess.Popen(args, 
@@ -250,9 +248,9 @@ def rcopy(source, dest, host, user,
             args.extend(('-i', identity_file))
         
         if isinstance(source, file) or hasattr(source, 'read'):
-            args.append('cat > %s' % (shell_escape(dest),))
+            args.append('cat > %s' % dest)
         elif isinstance(dest, file) or hasattr(dest, 'write'):
-            args.append('cat %s' % (shell_escape(dest),))
+            args.append('cat %s' % dest)
         else:
             raise AssertionError, "Unreachable code reached! :-Q"
         
@@ -436,21 +434,21 @@ def rspawn(command, pidfile,
     
     daemon_command = '{ { %(command)s  > %(stdout)s 2>%(stderr)s < %(stdin)s & } ; echo $! 1 > %(pidfile)s ; }' % {
         'command' : command,
-        'pidfile' : shell_escape(pidfile),
+        'pidfile' : pidfile,
         
         'stdout' : stdout,
         'stderr' : stderr,
         'stdin' : stdin,
     }
     
-    cmd = "%(create)s%(gohome)s rm -f %(pidfile)s ; %(sudo)s nohup bash -c %(command)s " % {
-            'command' : shell_escape(daemon_command),
+    cmd = "%(create)s%(gohome)s rm -f %(pidfile)s ; %(sudo)s nohup bash -c '%(command)s' " % {
+            'command' : daemon_command,
             
             'sudo' : 'sudo -S' if sudo else '',
             
-            'pidfile' : shell_escape(pidfile),
-            'gohome' : 'cd %s ; ' % (shell_escape(home),) if home else '',
-            'create' : 'mkdir -p %s ; ' % (shell_escape,) if create_home else '',
+            'pidfile' : pidfile,
+            'gohome' : 'cd %s ; ' % home if home else '',
+            'create' : 'mkdir -p %s ; ' % home if create_home else '',
         }
 
     (out,err), proc = rexec(