Guest User

Untitled

a guest
Jan 9th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. #######################################################################################################
  4. ## ##
  5. ## WHAT IS THIS? ##
  6. ## ##
  7. #######################################################################################################
  8. ## Bash script to help Parlameter front-end developers. It launches mongo, parlasite, parlanode, ##
  9. ## has option to reload/reboot and/or stop. Download, edit config part then `chmod +x parladev.sh`. ##
  10. ## Use like so: `./parladev.sh` to run, `./parladev.sh -r` to reload and `./parladev.sh -s` to stop. ##
  11. #######################################################################################################
  12.  
  13. #########################
  14. ## CONFIG HAPPENS HERE ##
  15. #########################
  16.  
  17. ## global folders
  18. DEV_ROOT="/home/muki/code/djnd"
  19. DB_ROOT="/home/muki/db/parlanode"
  20.  
  21. ## mongo passwords
  22. MONGO_USERNAME="parladaddy"
  23. MONGO_PASSWORD="parlapassword"
  24.  
  25. ######################
  26. ## CONFIG ENDS HERE ##
  27. ######################
  28.  
  29. ## flags
  30. REBOOT="false"
  31. STOP="false"
  32.  
  33. while getopts 'rs' flag; do
  34. case "${flag}" in
  35. r) REBOOT="true" && echo "$REBOOT $STOP" ;;
  36. s) STOP="true" && echo "$REBOOT $STOP" ;;
  37. *) 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 ;;
  38. esac
  39. done
  40. ## if both flags are true, something will break. error now.
  41. if [ $REBOOT == "true" ] && [ $STOP == "true" ] ; then
  42. echo "You can't reboot and stop at the same time." 1>&2
  43. exit 12
  44. fi
  45.  
  46. ## if not rebooting or stopping start everything
  47. if [ $REBOOT == "false" ] && [ $STOP == "false" ] ; then
  48. mongod --dbpath $DB_ROOT --fork --logpath $DB_ROOT/parlanode.log
  49.  
  50. cd "$DEV_ROOT/parlanode"
  51. NODE_ENV=development MONGO_USERNAME=$MONGO_USERNAME MONGO_PASSWORD=$MONGO_PASSWORD pm2 start run.js -n parlanode
  52.  
  53. cd "$DEV_ROOT/parlasite"
  54. NODE_ENV=development MONGO_USERNAME=$MONGO_USERNAME MONGO_PASSWORD=$MONGO_PASSWORD pm2 start run.js -n parlasite
  55. fi
  56.  
  57. ## if rebooting or stopping kill pm2
  58. if [ $REBOOT == "true" ] ; then
  59. cd "$DEV_ROOT/parlanode"
  60. pm2 restart parlanode
  61.  
  62. cd "$DEV_ROOT/parlasite"
  63. pm2 restart parlasite
  64. fi
  65.  
  66. if [ $STOP == "true" ] ; then
  67. pm2 kill
  68. mongod --shutdown
  69. fi
  70.  
  71.  
  72. ## notes
  73. ## you want "" around the variable in a test because if it's empty you get a syntax error because of [ == "true ]
  74. ## 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