#!/usr/bin/env python
################################################################################
# TmsRestart Restart TMS Daemon's
# T.Barnaby, BEAM Ltd, 2007-06-19
################################################################################
#
import os
import sys
import signal
import time
import getopt
import telnetlib
import socket
def alarmHandler(signum, frame):
raise IOError, "Couldn't connect"
def tmsModRestart(hostName):
tn = telnetlib.Telnet();
print "Restart tmsPuServer on:", hostName;
# Set the signal handler and a 5-second alarm
signal.signal(signal.SIGALRM, alarmHandler)
signal.alarm(2);
try:
r = tn.open(hostName);
except IOError:
print "Timeout while attempting telnet to:", hostName;
return 1;
except socket.error:
print "Timeout error while attempting telnet to:", hostName;
return 1;
signal.alarm(0) # Disable the alarm
r = tn.read_until("login: ", 1);
tn.write("root\n");
# Restart TmsPuServer process
tn.write("killall -9 tmsPuServer\n");
time.sleep(1);
tn.write("/usr/tms/bin/tmsPuServer\n");