Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

104 wiersze
2.2KB

  1. #!/usr/bin/env bash
  2. ##
  3. # This section should match your Makefile
  4. ##
  5. PY=${PY:-python}
  6. PELICAN=${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) [port]"
  19. echo "This starts Pelican in debug and reload mode and then launches"
  20. echo "an HTTP server to help site development. It doesn't read"
  21. echo "your Pelican settings, so if you edit any paths in your Makefile"
  22. echo "you will need to edit your settings 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 "Stopping HTTP server"
  33. kill $PID
  34. else
  35. echo "Stale PID, deleting"
  36. fi
  37. rm $SRV_PID
  38. else
  39. echo "HTTP 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. local port=$1
  56. echo "Starting up Pelican and HTTP server"
  57. shift
  58. $PELICAN --debug --autoreload -r $INPUTDIR -o $OUTPUTDIR -s $CONFFILE $PELICANOPTS &
  59. pelican_pid=$!
  60. echo $pelican_pid > $PELICAN_PID
  61. mkdir -p $OUTPUTDIR && cd $OUTPUTDIR
  62. $PY -m pelican.server $port &
  63. srv_pid=$!
  64. echo $srv_pid > $SRV_PID
  65. cd $BASEDIR
  66. sleep 1
  67. if ! alive $pelican_pid ; then
  68. echo "Pelican didn't start. Is the Pelican package installed?"
  69. return 1
  70. elif ! alive $srv_pid ; then
  71. echo "The HTTP server didn't start. Is there another service using port" $port "?"
  72. return 1
  73. fi
  74. echo 'Pelican and HTTP server processes now running in background.'
  75. }
  76. ###
  77. # MAIN
  78. ###
  79. [[ ($# -eq 0) || ($# -gt 2) ]] && usage
  80. port=''
  81. [[ $# -eq 2 ]] && port=$2
  82. if [[ $1 == "stop" ]]; then
  83. shut_down
  84. elif [[ $1 == "restart" ]]; then
  85. shut_down
  86. start_up $port
  87. elif [[ $1 == "start" ]]; then
  88. if ! start_up $port; then
  89. shut_down
  90. fi
  91. else
  92. usage
  93. fi