lazystarter.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #!/bin/sh
  2. # GNU MediaGoblin -- federated, autonomous media hosting
  3. # Copyright (C) 2011 Free Software Foundation, Inc
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. selfname=$(basename "$0")
  18. local_bin="./bin"
  19. # Test whether or not gunicorn is installed
  20. # -----------------------------------------
  21. if [ -f "${local_bin}/python" ]; then
  22. our_python="${local_bin}/python";
  23. else
  24. our_python="python";
  25. fi
  26. if $our_python -c "import sys
  27. try:
  28. import gunicorn
  29. sys.exit(0)
  30. except ImportError:
  31. sys.exit(1)
  32. "; then
  33. use_gunicorn=true;
  34. else
  35. use_gunicorn=false;
  36. fi
  37. # -----------------------------------------
  38. case "$selfname" in
  39. lazyserver.sh)
  40. if $use_gunicorn; then
  41. starter_cmd=gunicorn;
  42. else
  43. starter_cmd=paster;
  44. fi
  45. ini_prefix=paste
  46. ;;
  47. lazycelery.sh)
  48. starter_cmd=celeryd
  49. ini_prefix=mediagoblin
  50. ;;
  51. *)
  52. echo "Start this script with the name lazyserver.sh or lazycelery.sh">&2
  53. exit 1
  54. ;;
  55. esac
  56. if [ "$1" = "-h" ]; then
  57. echo "$0 [-h] [-c filename.ini] [ARGS_to_${starter_cmd} ...]"
  58. echo ""
  59. if $use_gunicorn; then
  60. echo " For Gunicorn settings, see at:"
  61. echo " http://docs.gunicorn.org/en/19.0/settings.html"
  62. else
  63. echo " For example:"
  64. echo " $0 -c fcgi.ini port_number=23371"
  65. echo " or: $0 --server-name=fcgi --log-file=paste.log"
  66. fi
  67. echo ""
  68. echo " The configfile defaults to ${ini_prefix}_local.ini,"
  69. echo " if that is readable, otherwise ${ini_prefix}.ini."
  70. exit 1
  71. fi
  72. if [ "$1" = "-c" ]; then
  73. ini_file=$2
  74. shift; shift
  75. elif [ -r "${ini_prefix}_local.ini" ]; then
  76. ini_file="${ini_prefix}_local.ini"
  77. else
  78. ini_file="${ini_prefix}.ini"
  79. fi
  80. echo "Using ${starter_cmd} config: ${ini_file}"
  81. if [ -f "${local_bin}/${starter_cmd}" ]; then
  82. echo "Using ${local_bin}/${starter_cmd}"
  83. starter="${local_bin}/${starter_cmd}"
  84. elif which "${starter_cmd}" > /dev/null; then
  85. echo "Using ${starter_cmd} from \$PATH"
  86. starter=$starter_cmd
  87. else
  88. echo "No ${starter_cmd} found, exiting! X_X"
  89. exit 1
  90. fi
  91. # If the user somehow doesn't have a mediagoblin.ini
  92. # (maybe they aren't using make) give them one
  93. # ... this doesn't fulfill all conditions maybe, but is a stopgap
  94. # that doesn't have noticable race conditions
  95. if [ -f mediagoblin.example.ini ] && \
  96. [ ! -f mediagoblin.ini ]; then
  97. echo "No mediagoblin.ini found, making one";
  98. cp --no-clobber mediagoblin.example.ini mediagoblin.ini;
  99. fi
  100. set -x
  101. export CELERY_ALWAYS_EAGER=true
  102. case "$selfname" in
  103. lazyserver.sh)
  104. if $use_gunicorn; then
  105. $starter --paste "$ini_file" --log-file=- $@;
  106. else
  107. $starter serve "$ini_file" "$@" --reload;
  108. fi
  109. ;;
  110. lazycelery.sh)
  111. MEDIAGOBLIN_CONFIG="${ini_file}" \
  112. CELERY_CONFIG_MODULE=mediagoblin.init.celery.from_celery \
  113. $starter -B "$@"
  114. ;;
  115. *) exit 1 ;;
  116. esac