Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- #######################################################################################################
- ## ##
- ## WHAT IS THIS? ##
- ## ##
- #######################################################################################################
- ## Bash script to help Parlameter front-end developers. It launches mongo, parlasite, parlanode, ##
- ## has option to reload/reboot and/or stop. Download, edit config part then `chmod +x parladev.sh`. ##
- ## Use like so: `./parladev.sh` to run, `./parladev.sh -r` to reload and `./parladev.sh -s` to stop. ##
- #######################################################################################################
- #########################
- ## CONFIG HAPPENS HERE ##
- #########################
- ## global folders
- DEV_ROOT="/home/muki/code/djnd"
- DB_ROOT="/home/muki/db/parlanode"
- ## mongo passwords
- MONGO_USERNAME="parladaddy"
- MONGO_PASSWORD="parlapassword"
- ######################
- ## CONFIG ENDS HERE ##
- ######################
- ## flags
- REBOOT="false"
- STOP="false"
- while getopts 'rs' flag; do
- case "${flag}" in
- r) REBOOT="true" && echo "$REBOOT $STOP" ;;
- s) STOP="true" && echo "$REBOOT $STOP" ;;
- *) echo "Unexpected option ${flag}. I don't know what to do. Valid options are -r for reboot and -s to stop." 1>&2 && exit 11 ;;
- esac
- done
- ## if both flags are true, something will break. error now.
- if [ $REBOOT == "true" ] && [ $STOP == "true" ] ; then
- echo "You can't reboot and stop at the same time." 1>&2
- exit 12
- fi
- ## if not rebooting or stopping start everything
- if [ $REBOOT == "false" ] && [ $STOP == "false" ] ; then
- mongod --dbpath $DB_ROOT --fork --logpath $DB_ROOT/parlanode.log
- cd "$DEV_ROOT/parlanode"
- NODE_ENV=development MONGO_USERNAME=$MONGO_USERNAME MONGO_PASSWORD=$MONGO_PASSWORD pm2 start run.js -n parlanode
- cd "$DEV_ROOT/parlasite"
- NODE_ENV=development MONGO_USERNAME=$MONGO_USERNAME MONGO_PASSWORD=$MONGO_PASSWORD pm2 start run.js -n parlasite
- fi
- ## if rebooting or stopping kill pm2
- if [ $REBOOT == "true" ] ; then
- cd "$DEV_ROOT/parlanode"
- pm2 restart parlanode
- cd "$DEV_ROOT/parlasite"
- pm2 restart parlasite
- fi
- if [ $STOP == "true" ] ; then
- pm2 kill
- mongod --shutdown
- fi
- ## notes
- ## you want "" around the variable in a test because if it's empty you get a syntax error because of [ == "true ]
- ## however, since we define them in the beginning of the file, we'll ignore that for better readability
Add Comment
Please, Sign In to add comment