You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

94 lines
3.1 KiB

  1. #!/bin/bash
  2. set -exuo pipefail
  3. if [ -z ${COUCHDB_URL+x} ]; then
  4. echo "Skipping couchdb init"
  5. else
  6. timeout 300 bash -c "while [[ \"\$(curl -s -o /dev/null -w ''%{http_code}'' ${COUCHDB_URL})\" != \"200\" ]]; do sleep 5; done" || false
  7. if [ -z ${COUCHDB_USER+x} ]; then
  8. export COUCHDB_CURL_ARGS=""
  9. else
  10. export COUCHDB_CURL_ARGS="-u \"$COUCHDB_USER:$COUCHDB_PASSWORD\""
  11. fi
  12. pushd "db/design_docs"
  13. curl -s $COUCHDB_CURL_ARGS -X PUT $COUCHDB_URL/_users
  14. curl -s $COUCHDB_CURL_ARGS -X PUT $COUCHDB_URL/archivebot
  15. curl -s $COUCHDB_CURL_ARGS -X PUT $COUCHDB_URL/archivebot_logs
  16. grep -v _rev archive_urls.json > /tmp/archive_urls.json
  17. grep -v _rev ignore_patterns.json > /tmp/ignore_patterns.json
  18. grep -v _rev jobs.json > /tmp/jobs.json
  19. grep -v _rev user_agents.json > /tmp/user_agents.json
  20. curl -s $COUCHDB_CURL_ARGS -X PUT $COUCHDB_URL/archivebot/_design/archive_urls -d @/tmp/archive_urls.json
  21. curl -s $COUCHDB_CURL_ARGS -X PUT $COUCHDB_URL/archivebot/_design/ignore_patterns -d @/tmp/ignore_patterns.json
  22. curl -s $COUCHDB_CURL_ARGS -X PUT $COUCHDB_URL/archivebot/_design/jobs -d @/tmp/jobs.json
  23. curl -s $COUCHDB_CURL_ARGS -X PUT $COUCHDB_URL/archivebot/_design/user_agents -d @/tmp/user_agents.json
  24. popd
  25. fi
  26. export FINISHED_WARCS_DIR=${FINISHED_WARCS_DIR:-/data/}
  27. case "$1" in
  28. "bot")
  29. cd bot
  30. if [ -z ${COUCHDB_USER+x} ]; then
  31. export COUCHDB_ARGS=""
  32. else
  33. export COUCHDB_ARGS="--db-credentials \"$COUCHDB_USER:$COUCHDB_PASSWORD\""
  34. fi
  35. bundle exec ruby bot.rb \
  36. -s "$IRC_URL" \
  37. -r "$REDIS_URL" \
  38. -c "$IRC_CHANNEL" \
  39. -n "$IRC_NICK" \
  40. --db "$COUCHDB_URL/archivebot" $COUCHDB_ARGS
  41. ;;
  42. "cogs")
  43. if [ -z ${COUCHDB_USER+x} ]; then
  44. export COUCHDB_ARGS=""
  45. else
  46. export COUCHDB_ARGS="--db-credentials \"$COUCHDB_USER:$COUCHDB_PASSWORD\" --log-db-credentials \"$COUCHDB_USER:$COUCHDB_PASSWORD\""
  47. fi
  48. bundle exec ruby cogs/start.rb \
  49. -r "$REDIS_URL" \
  50. --db "$COUCHDB_URL/archivebot" \
  51. --log-db "$COUCHDB_URL/archivebot_logs" $COUCHDB_ARGS
  52. ;;
  53. "firehose")
  54. export UPDATES_CHANNEL=updates
  55. export FIREHOSE_SOCKET_URL=tcp://0.0.0.0:12345
  56. plumbing/updates-listener | plumbing/log-firehose
  57. ;;
  58. "dashboard")
  59. bundle exec ruby dashboard/app.rb -u http://0.0.0.0:8080 -r "$REDIS_URL"
  60. ;;
  61. "websocket")
  62. plumbing/firehose-client | python3 dashboard/websocket.py
  63. ;;
  64. "pipeline")
  65. cd pipeline
  66. export PIPELINE_NAME="${PIPELINE_NAME:-${PIPELINE_PREFIX}-$(hostname -s)}"
  67. export PIPELINE_NAME="${PIPELINE_NAME:0:30}"
  68. export NO_SCREEN=1
  69. sudo /usr/sbin/tcp-closer -4 --dport 443 --idle_time 21601000 --last_recv_limit 43200000 --interval 300 &
  70. sudo /usr/sbin/tcp-closer -6 --dport 443 --idle_time 21601000 --last_recv_limit 43200000 --interval 300 &
  71. run-pipeline3 pipeline.py --disable-web-server \
  72. --concurrent $PIPELINE_CONCURRENT $PIPELINE_NAME
  73. ;;
  74. "uploader")
  75. python ./uploader/uploader.py $FINISHED_WARCS_DIR
  76. ;;
  77. "analyzer")
  78. export UPDATES_CHANNEL=updates
  79. cd plumbing
  80. ./analyzer
  81. ;;
  82. "trimmer")
  83. export UPDATES_CHANNEL=updates
  84. cd plumbing
  85. ./trimmer > /dev/null
  86. ;;
  87. esac