From: Alina Quereilhac Date: Fri, 9 Nov 2012 16:49:01 +0000 (+0100) Subject: Adding remote command execution for linux boxes X-Git-Tag: nepi-3.0.0~122^2~39 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=c4e35df2348178c635e73c89a4b6a700bcb84932;p=nepi.git Adding remote command execution for linux boxes --- diff --git a/src/neco/resources/base/application.py b/src/neco/resources/base/application.py index 40e07ff5..8c91ab97 100644 --- a/src/neco/resources/base/application.py +++ b/src/neco/resources/base/application.py @@ -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): diff --git a/src/neco/resources/base/linux_node.py b/src/neco/resources/base/linux_node.py index b7d10cc6..e0ec18b6 100644 --- a/src/neco/resources/base/linux_node.py +++ b/src/neco/resources/base/linux_node.py @@ -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): diff --git a/src/neco/util/sshfuncs.py b/src/neco/util/sshfuncs.py index 77698ca2..347056f2 100644 --- a/src/neco/util/sshfuncs.py +++ b/src/neco/util/sshfuncs.py @@ -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(