mongod_kill_watcher.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 
00004 # when this node is killed, kill mongod. 
00005 
00006 import rospy
00007 import signal
00008 import os
00009 
00010 db_path=None
00011 
00012 def kill_mongod():
00013     pid = None
00014     try:
00015         with open(os.path.join(db_path, 'mongod.lock')) as f:
00016             pid = int(f.readline())
00017     except Exception as e:
00018         rospy.logfatal('cannot find mongod.lock: %s' % e)
00019         return
00020     rospy.sleep(5.0)
00021     try:
00022         os.kill(pid, signal.SIGINT)
00023         rospy.loginfo('killed mongod: %d' % pid)
00024     except Exception as e:
00025         rospy.logwarn('escallating to send SIGTERM to mongod')
00026         os.kill(pid, signal.SIGTERM)
00027 
00028 if __name__ == '__main__':
00029     rospy.init_node('mongodb_killer')
00030     db_path = rospy.get_param('~db_path', '/var/lib/robot/mongodb_store')
00031     rospy.on_shutdown(kill_mongod)
00032     rospy.spin()


jsk_robot_startup
Author(s):
autogenerated on Sat Jul 1 2017 02:42:18