lazystarter.sh 2.7 KB

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