user = self.node.slicename,
agent = None,
ident_key = self.node.ident_path,
- server_key = self.node.server_key
+ server_key = self.node.server_key,
+ hostip = self.node.hostip,
)
if proc.wait():
user = self.node.slicename,
agent = None,
ident_key = self.node.ident_path,
- server_key = self.node.server_key
+ server_key = self.node.server_key,
+ hostip = self.node.hostip
)
if pidtuple:
user = self.node.slicename,
agent = None,
ident_key = self.node.ident_path,
- server_key = self.node.server_key
+ server_key = self.node.server_key,
+ hostip = self.node.hostip
)
if status is rspawn.FINISHED:
self._build_pid = self._build_ppid = None
break
elif status is not rspawn.RUNNING:
+ self._logger.warn("Busted waiting for %s to finish building at %s %s", self, self.node.hostname,
+ "(build slave)" if self._master is not None else "(build master)")
bustspin += 1
time.sleep(delay*(5.5+random.random()))
if bustspin > 12:
port = None,
user = self.node.slicename,
agent = None,
- ident_key = self.node.ident_path
+ ident_key = self.node.ident_path,
+ hostip = self.node.hostip
)
# Utility library for spawning remote asynchronous tasks
from nepi.util import server
import getpass
+import logging
class STDOUT:
"""
def remote_spawn(command, pidfile, stdout='/dev/null', stderr=STDOUT, stdin='/dev/null', home=None, create_home=False, sudo=False,
host = None, port = None, user = None, agent = None,
ident_key = None, server_key = None,
- tty = False):
+ tty = False, hostip = None):
"""
Spawn a remote command such that it will continue working asynchronously.
agent = agent,
ident_key = ident_key,
server_key = server_key,
- tty = tty
+ tty = tty ,
+ hostip = hostip
)
if proc.wait():
@server.eintr_retry
def remote_check_pid(pidfile,
host = None, port = None, user = None, agent = None,
- ident_key = None, server_key = None):
+ ident_key = None, server_key = None, hostip = None):
"""
Check the pidfile of a process spawned with remote_spawn.
user = user,
agent = agent,
ident_key = ident_key,
- server_key = server_key
+ server_key = server_key,
+ hostip = hostip
)
if proc.wait():
@server.eintr_retry
def remote_status(pid, ppid,
host = None, port = None, user = None, agent = None,
- ident_key = None, server_key = None):
+ ident_key = None, server_key = None, hostip = None):
"""
Check the status of a process spawned with remote_spawn.
"""
(out,err),proc = server.popen_ssh_command(
- "ps --ppid %(ppid)d -o pid | grep -c %(pid)d ; true" % {
+ "ps --pid %(pid)d -o pid | grep -c %(pid)d ; true" % {
'ppid' : ppid,
'pid' : pid,
},
user = user,
agent = agent,
ident_key = ident_key,
- server_key = server_key
+ server_key = server_key,
+ hostip = hostip
)
if proc.wait():
try:
status = bool(int(out.strip()))
except:
+ if out or err:
+ logging.warn("Error checking remote status:\n%s%s\n", out, err)
# Ignore, many ways to fail that don't matter that much
return NOT_STARTED
return RUNNING if status else FINISHED
@server.eintr_retry
def remote_kill(pid, ppid, sudo = False,
host = None, port = None, user = None, agent = None,
- ident_key = None, server_key = None,
+ ident_key = None, server_key = None, hostip = None,
nowait = False):
"""
Kill a process spawned with remote_spawn.
Nothing, should have killed the process
"""
+ if sudo:
+ subkill = "$(ps --ppid %(pid)d -o pid h)" % { 'pid' : pid }
+ else:
+ subkill = ""
cmd = """
-%(sudo)s kill -- -%(pid)d || /bin/true
-%(sudo)s kill %(pid)d || /bin/true
+SUBKILL="%(subkill)s" ;
+%(sudo)s kill -- -%(pid)d $SUBKILL || /bin/true
+%(sudo)s kill %(pid)d $SUBKILL || /bin/true
for x in 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 ; do
sleep 0.2
- if [ `ps --ppid %(ppid)d -o pid | grep -c %(pid)d` == '0' ]; then
+ if [ `ps --pid %(pid)d -o pid | grep -c %(pid)d` == '0' ]; then
break
else
- %(sudo)s kill -- -%(pid)d || /bin/true
- %(sudo)s kill %(pid)d || /bin/true
+ %(sudo)s kill -- -%(pid)d $SUBKILL || /bin/true
+ %(sudo)s kill %(pid)d $SUBKILL || /bin/true
fi
sleep 1.8
done
-if [ `ps --ppid %(ppid)d -o pid | grep -c %(pid)d` != '0' ]; then
- %(sudo)s kill -9 -- -%(pid)d || /bin/true
- %(sudo)s kill -9 %(pid)d || /bin/true
+if [ `ps --pid %(pid)d -o pid | grep -c %(pid)d` != '0' ]; then
+ %(sudo)s kill -9 -- -%(pid)d $SUBKILL || /bin/true
+ %(sudo)s kill -9 %(pid)d $SUBKILL || /bin/true
fi
"""
if nowait:
cmd % {
'ppid' : ppid,
'pid' : pid,
- 'sudo' : 'sudo -S' if sudo else ''
+ 'sudo' : 'sudo -S' if sudo else '',
+ 'subkill' : subkill,
},
host = host,
port = port,
user = user,
agent = agent,
ident_key = ident_key,
- server_key = server_key
+ server_key = server_key,
+ hostip = hostip
)
# wait, don't leave zombies around
retry = 0,
err_on_timeout = True,
connect_timeout = 30,
- persistent = True):
+ persistent = True,
+ hostip = None):
"""
Executes a remote commands, returns ((stdout,stderr),process)
"""
'-o', 'ConnectionAttempts=3',
'-o', 'ServerAliveInterval=30',
'-o', 'TCPKeepAlive=yes',
- '-l', user, host]
+ '-l', user, hostip or host]
if persistent and openssh_has_persist():
args.extend([
'-o', 'ControlMaster=auto',
try:
out, err = _communicate(proc, stdin, timeout, err_on_timeout)
if proc.poll():
- if err.strip().startswith('ssh: '):
+ if err.strip().startswith('ssh: ') or err.strip().startswith('mux_client_hello_exchange: '):
# SSH error, can safely retry
continue
elif retry: