Commit 594a9d10 authored by Gary Wong's avatar Gary Wong

Add a basic "top"-multiplexing daemon to allow monitoring of shared nodes.

parent 19c0e454
......@@ -396,6 +396,8 @@ xen-install: dir-install xen-udev-install xen-upstart-install
fi
$(INSTALL) -m 755 $(SRCDIR)/xen/GrubConf.py \
/usr/lib/xen-default/lib/python/grub/
$(INSTALL) -m 755 $(SRCDIR)/xen/topd $(BINDIR)/
$(INSTALL) -m 755 $(SRCDIR)/xen/topd-init $(SYSETCDIR)/init.d/topd
genirack-install:
$(INSTALL) -m 755 $(SRCDIR)/xen/restorevm.pl $(BINDIR)/restorevm.pl
......
#!/usr/bin/python
import os
import pty
import select
import socket
PIDFILE="/var/run/topd.pid"
PORT=4097
listener = socket.socket( socket.AF_INET, socket.SOCK_STREAM, 0 )
listener.setsockopt( socket.SOL_SOCKET, socket.SO_REUSEADDR, 1 )
listener.bind( ( "", PORT ) )
listener.listen( 4 )
if os.fork() > 0:
os._exit( 0 )
try:
f = open( PIDFILE, "w" )
f.write( str( os.getpid() ) )
f.close()
os.setuid( 65534 )
except:
pass
clients = []
( pid, top ) = pty.fork()
if pid == 0:
os.execl( "/usr/bin/top", "top" )
os._exit( 1 )
while True:
( r, w, x ) = select.select( [ listener, top ], [], [] )
if listener in r:
( n, addr ) = listener.accept()
n.setblocking( 0 )
clients.append( n )
os.write( top, "0" ) # Ugly hack to draw entire screen for
# new client... old clients will get refreshed too. Too bad.
if top in r:
buf = os.read( top, 1024 )
for c in clients:
try:
c.send( buf )
except Exception as e:
c.close()
clients.remove( c )
#!/bin/sh
### BEGIN INIT INFO
# Provides: topd
# Required-Start: $syslog
# Required-Stop: $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Remote top daemon
# Description: Remote top daemon
### END INIT INFO
. /lib/init/vars.sh
. /lib/lsb/init-functions
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/etc/emulab
DESC="Remote top daemon"
PIDFILE=/var/run/topd.pid
ROLE=$(cat /var/emulab/boot/role)
topd_start()
{
if [ $ROLE != "sharedhost" ]; then
return 0
fi
log_progress_msg "topd"
topd
return $?
}
topd_stop()
{
if [ $ROLE != "sharedhost" ]; then
return 0
fi
log_progress_msg "topd"
kill $(cat $PIDFILE)
return $?
}
topd_restart()
{
if [ $ROLE != "sharedhost" ]; then
return 0
fi
log_progress_msg "topd"
kill $(cat $PIDFILE)
topd
return 0
}
case "$1" in
start)
log_daemon_msg "Starting $DESC"
topd_start
log_end_msg 0
;;
stop)
log_daemon_msg "Stopping $DESC"
topd_stop
log_end_msg $ret
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC"
topd_restart
log_end_msg $ret
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
exit 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment