86 lines
2.3 KiB

  1. #!/bin/bash
  2. ## Init is run on host
  3. ## For now it is run every time the script is launched, but
  4. ## it should be launched only once after build.
  5. ## Accessible variables are:
  6. ## - SERVICE_NAME Name of current service
  7. ## - DOCKER_BASE_IMAGE Base image from which this service might be built if any
  8. ## - SERVICE_DATASTORE Location on host of the DATASTORE of this service
  9. ## - SERVICE_CONFIGSTORE Location on host of the CONFIGSTORE of this service
  10. set -e
  11. peertube_uid=$(docker_get_uid "$SERVICE_NAME" "peertube")
  12. PEERTUBE_APP_DIR=/opt/apps/peertube
  13. PEERTUBE_DATA_DIR=/var/lib/peertube
  14. PEERTUBE_LOG_DIR=/var/log/peertube
  15. PEERTUBE_CACHE_DIR=/var/cache/peertube
  16. PEERTUBE_CONFIG_DIR=/etc/peertube
  17. HOST_CONFIG_DIR=$SERVICE_CONFIGSTORE/$PEERTUBE_CONFIG_DIR
  18. HOST_DATA_DIR=$SERVICE_DATASTORE/$PEERTUBE_DATA_DIR
  19. mkdir -p "$HOST_CONFIG_DIR"
  20. ## Always copy default and custom env configuration file, in cases where new keys were added
  21. ln -sf "$PEERTUBE_APP_DIR"/config/default.yaml "$HOST_CONFIG_DIR"
  22. cat <<EOF > "$HOST_CONFIG_DIR/local.yaml"
  23. listen:
  24. hostname: '0.0.0.0'
  25. port: 9000
  26. storage:
  27. avatars: '$PEERTUBE_DATA_DIR/avatars/'
  28. videos: '$PEERTUBE_DATA_DIR/videos/'
  29. redundancy: '$PEERTUBE_DATA_DIR/redundancy/'
  30. previews: '$PEERTUBE_DATA_DIR/previews/'
  31. thumbnails: '$PEERTUBE_DATA_DIR/thumbnails/'
  32. torrents: '$PEERTUBE_DATA_DIR/torrents/'
  33. captions: '$PEERTUBE_DATA_DIR/captions/'
  34. logs: '/var/log/peertube/'
  35. cache: '/var/cache/peertube/'
  36. tmp: '/var/tmp/peertube/'
  37. EOF
  38. VALID_SECTION=(
  39. instance services import transcoding
  40. user signup admin cache redundancy
  41. trending search log
  42. )
  43. for section in "${VALID_SECTION[@]}"; do
  44. if val=$(options-get "$section" 2>/dev/null); then
  45. yaml_key_val_str "$section" "$val"
  46. fi
  47. done >> "$HOST_CONFIG_DIR/local.yaml"
  48. if ! [ -e "$HOST_DATA_DIR/config.json" ]; then
  49. touch "$HOST_DATA_DIR/config.json"
  50. fi
  51. ln -sf "$PEERTUBE_DATA_DIR"/config.json "$HOST_CONFIG_DIR/local-prod.json"
  52. dirs=(/var/tmp/peertube /var/cache/peertube
  53. "$PEERTUBE_CACHE_DIR" "$PEERTUBE_LOG_DIR" "$PEERTUBE_DATA_DIR")
  54. host_dirs=()
  55. for dir in "${dirs[@]}"; do
  56. host_dirs+=("$SERVICE_DATASTORE$dir")
  57. done
  58. mkdir -p "${host_dirs[@]}"
  59. find "${host_dirs[@]}" \! -user "$peertube_uid" \
  60. -exec chown -v "$peertube_uid" {} + || true
  61. true