develop_server.sh 2.0 KB

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