From 57a86372217ebe5d23954d901c966bc54b8476f8 Mon Sep 17 00:00:00 2001
From: Planet-Lab Support <support@planet-lab.org>
Date: Thu, 17 Aug 2006 20:21:11 +0000
Subject: [PATCH] This commit was manufactured by cvs2svn to create branch
 'planetlab-3_3-branch'.

---
 nm_mom.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)
 create mode 100755 nm_mom.py

diff --git a/nm_mom.py b/nm_mom.py
new file mode 100755
index 0000000..dc18817
--- /dev/null
+++ b/nm_mom.py
@@ -0,0 +1,63 @@
+#!/usr/bin/python
+# 
+# Restarts NM if NM does not respond to periodic probes.
+#
+# Faiyaz Ahmed <faiyaza@cs.princeton.edu>
+# Copyright (C) 2006 The Trustees of Princeton University
+#
+# $Id: nm_mom.py,v 1.2 2006/08/17 20:12:09 faiyaza Exp $
+# 
+
+import syslog
+import os
+import sys
+import time
+
+import socket
+import xmlrpclib
+import bwlimit
+
+from sets import Set
+
+# Utility functions
+from pl_mom import *
+
+
+def restartNM():
+	try:
+		pid = os.fork()
+                if pid == 0:
+			bwlimit.run("/etc/init.d/pl_nm stop")
+			time.sleep(10)
+			try:
+				nmpid = bwlimit.run("/bin/ps -e -o pid,cmd | grep nm.py")[0].split(" ")[0]
+				os.kill(int(nmpid), 9)
+				time.sleep(3)
+				print "NM  %s forcefully killed." %nmpid
+			except:
+				print "NM %s killed." %nmpid
+			bwlimit.run("/etc/init.d/pl_nm restart")
+			print "NM restarted."
+                	os._exit(0)
+                else:
+                        os.waitpid(pid,0)
+        except Exception, err:
+                print "Warning: Exception received while restarting NM:  %s" % err
+
+
+def main():
+        syslog.openlog("nm_mom")
+        sys.stdout = sys.stderr = Logger()
+	
+	nm = NM()
+	last_maxrate = 0 
+	try:
+		# Query something.  If it doesnt come back...
+                vals = nm.query("pl_netflow", [('nm_net_max_rate', last_maxrate)])
+
+        except Exception, err:
+                print "Warning: Exception received while querying NM:", err
+		restartNM()
+
+if __name__ == '__main__':
+    main()
-- 
2.47.0