00001
00002
00003 import roslib; roslib.load_manifest('mongodb')
00004 import rospy
00005 import subprocess
00006 import sys
00007 import os
00008 from os import path
00009 import shutil
00010
00011 if __name__ == '__main__':
00012 rospy.init_node('mongodb')
00013 dbpath = rospy.get_param('~database_path' , '/tmp/db')
00014 port = rospy.get_param('~port', 27017)
00015 overwrite = rospy.get_param('~overwrite', False)
00016
00017 rospy.loginfo('Starting mongodb with db location {0}'.\
00018 format(dbpath))
00019
00020 if overwrite and path.exists(dbpath):
00021 shutil.rmtree(dbpath)
00022 rospy.loginfo('Removed existing db at %s', dbpath)
00023
00024 if not path.exists(dbpath):
00025 rospy.loginfo('{0} did not exist; creating it.'.format(dbpath))
00026 os.makedirs(dbpath)
00027
00028 try:
00029 retcode = subprocess.call("rosrun mongodb mongod --dbpath {0} --port {1}".\
00030 format(dbpath, port).split())
00031 if retcode < 0:
00032 rospy.logerr("Child was terminated by signal %s", -retcode)
00033 else:
00034 rospy.loginfo("Child returned")
00035 except OSError, e:
00036 rospy.logerr("Execution failed: %s", e)
00037