develop_server.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env bash
  2. ##
  3. # This section should match your Makefile
  4. ##
  5. PELICAN=pelican
  6. PELICANOPTS=
  7. BASEDIR=$(pwd)
  8. INPUTDIR=$BASEDIR/content
  9. OUTPUTDIR=$BASEDIR/output
  10. CONFFILE=$BASEDIR/pelicanconf.py
  11. ###
  12. # Don't change stuff below here unless you are sure
  13. ###
  14. SRV_PID=$BASEDIR/srv.pid
  15. PELICAN_PID=$BASEDIR/pelican.pid
  16. function usage(){
  17. echo "usage: $0 (stop) (start) (restart)"
  18. echo "This starts pelican in debug and reload mode and then launches"
  19. echo "A SimpleHTTP server to help site development. It doesn't read"
  20. echo "your pelican options so you edit any paths in your Makefile"
  21. echo "you will need to edit it as well"
  22. exit 3
  23. }
  24. function shut_down(){
  25. if [[ -f $SRV_PID ]]; then
  26. PID=$(cat $SRV_PID)
  27. PROCESS=$(ps -p $PID | tail -n 1 | awk '{print $4}')
  28. if [[ $PROCESS != "" ]]; then
  29. echo "Killing SimpleHTTPServer"
  30. kill $PID
  31. else
  32. echo "Stale PID, deleting"
  33. fi
  34. rm $SRV_PID
  35. else
  36. echo "SimpleHTTPServer PIDFile not found"
  37. fi
  38. if [[ -f $PELICAN_PID ]]; then
  39. PID=$(cat $PELICAN_PID)
  40. PROCESS=$(ps -p $PID | tail -n 1 | awk '{print $4}')
  41. if [[ $PROCESS != "" ]]; then
  42. echo "Killing Pelican"
  43. kill $PID
  44. else
  45. echo "Stale PID, deleting"
  46. fi
  47. rm $PELICAN_PID
  48. else
  49. echo "Pelican PIDFile not found"
  50. fi
  51. }
  52. function start_up(){
  53. echo "Starting up Pelican and SimpleHTTPServer"
  54. shift
  55. $PELICAN --debug --autoreload -r $INPUTDIR -o $OUTPUTDIR -s $CONFFILE $PELICANOPTS &
  56. echo $! > $PELICAN_PID
  57. cd $OUTPUTDIR
  58. python -m SimpleHTTPServer &
  59. echo $! > $SRV_PID
  60. cd $BASEDIR
  61. sleep 1 && echo 'Pelican and SimpleHTTPServer processes now running in background.'
  62. }
  63. ###
  64. # MAIN
  65. ###
  66. [[ $# -ne 1 ]] && usage
  67. if [[ $1 == "stop" ]]; then
  68. shut_down
  69. elif [[ $1 == "restart" ]]; then
  70. shut_down
  71. start_up
  72. elif [[ $1 == "start" ]]; then
  73. start_up
  74. else
  75. usage
  76. fi