lazystarter.sh 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. case "$selfname" in
  20. lazyserver.sh)
  21. starter_cmd=paster;
  22. ini_prefix=paste
  23. ;;
  24. lazycelery.sh)
  25. starter_cmd=celeryd
  26. ini_prefix=mediagoblin
  27. ;;
  28. *)
  29. echo "Start this script with the name lazyserver.sh or lazycelery.sh">&2
  30. exit 1
  31. ;;
  32. esac
  33. if [ "$1" = "-h" ]; then
  34. echo "$0 [-h] [-c filename.ini] [ARGS_to_${starter_cmd} ...]"
  35. echo ""
  36. echo " For example:"
  37. echo " $0 -c fcgi.ini port_number=23371"
  38. echo " or: $0 --server-name=fcgi --log-file=paste.log"
  39. echo ""
  40. echo " The configfile defaults to ${ini_prefix}_local.ini,"
  41. echo " if that is readable, otherwise ${ini_prefix}.ini."
  42. exit 1
  43. fi
  44. if [ "$1" = "-c" ]; then
  45. ini_file=$2
  46. shift; shift
  47. elif [ -r "${ini_prefix}_local.ini" ]; then
  48. ini_file="${ini_prefix}_local.ini"
  49. else
  50. ini_file="${ini_prefix}.ini"
  51. fi
  52. echo "Using ${starter_cmd} config: ${ini_file}"
  53. if [ -f "${local_bin}/${starter_cmd}" ]; then
  54. echo "Using ${local_bin}/${starter_cmd}"
  55. starter="${local_bin}/${starter_cmd}"
  56. elif which "${starter_cmd}" > /dev/null; then
  57. echo "Using ${starter_cmd} from \$PATH"
  58. starter=$starter_cmd
  59. else
  60. echo "No ${starter_cmd} found, exiting! X_X"
  61. exit 1
  62. fi
  63. # If the user somehow doesn't have a mediagoblin.ini
  64. # (maybe they aren't using make) give them one
  65. # ... this doesn't fulfill all conditions maybe, but is a stopgap
  66. # that doesn't have noticable race conditions
  67. if [ -f mediagoblin.example.ini ] && \
  68. [ ! -f mediagoblin.ini ]; then
  69. echo "No mediagoblin.ini found, making one";
  70. cp --no-clobber mediagoblin.example.ini mediagoblin.ini;
  71. fi
  72. set -x
  73. export CELERY_ALWAYS_EAGER=true
  74. case "$selfname" in
  75. lazyserver.sh)
  76. $starter serve "$ini_file" "$@" --reload;
  77. ;;
  78. lazycelery.sh)
  79. MEDIAGOBLIN_CONFIG="${ini_file}" \
  80. CELERY_CONFIG_MODULE=mediagoblin.init.celery.from_celery \
  81. $starter -B "$@"
  82. ;;
  83. *) exit 1 ;;
  84. esac