Skip to content

Instantly share code, notes, and snippets.

@matinrco
Created October 27, 2017 10:20
Show Gist options
  • Save matinrco/c93bff9f9fecc19a01a553e96879567f to your computer and use it in GitHub Desktop.
Save matinrco/c93bff9f9fecc19a01a553e96879567f to your computer and use it in GitHub Desktop.
This script will run Robo 3T (robomongo) with MongoDB and then it will close MongoDB if you close robo 3t
#!/bin/zsh
#mongodb data directory - change this to your desired location - and check for write permissions
DIRECTORY=~/.local/share/mongodb
#create directories if not exist
mkdir -p "$DIRECTORY/data"
mkdir -p "$DIRECTORY/log"
#create empty log file if not exist
if [ ! -e "$DIRECTORY/log/mongodb.log" ] ; then
touch "$DIRECTORY/log/mongodb.log"
fi
#run mongo db if not running - then I close it when you close robo3t
DidIRunMongodb=false
if [[ ! $(pgrep mongo) ]] ; then
DidIRunMongodb=true
mongod --dbpath "$DIRECTORY/data" --logpath "$DIRECTORY/log/mongodb.log" &
fi
#run robo3t
/opt/Robo3T/bin/robo3t
#kill mongodb if is running by this script
if [[ $(pgrep mongo) ]] ; then
if [ "$DidIRunMongodb" = true ] ; then
kill -9 $(<"$DIRECTORY/data/mongod.lock")
fi
fi
#mongo & robo3t are now closed - bye :)
exit
@matinrco
Copy link
Author

this script is ready for execution .
don't forget to apply modification to meet your needs.
this method is great if you use MongoDB & Robo 3t on your development environment.
you can also use this script as a desktop file in your linux desktop.
I hope this helps someone else!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment