Created
October 27, 2017 10:20
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!