| 1 | #!/bin/sh |
| 2 | # The node keeps no state: every boot pulls the shards the API published to S3, then keeps following them. |
| 3 | set -eu |
| 4 | |
| 5 | export RCLONE_CONFIG_S3_TYPE=s3 |
| 6 | export RCLONE_CONFIG_S3_PROVIDER=Other |
| 7 | export RCLONE_CONFIG_S3_REGION=auto |
| 8 | export RCLONE_CONFIG_S3_FORCE_PATH_STYLE=true |
| 9 | export RCLONE_CONFIG_S3_ENDPOINT="$S3_ENDPOINT |
| 10 | export RCLONE_CONFIG_S3_ACCESS_KEY_ID="$S3_ACCESS_KEY_ID |
| 11 | export RCLONE_CONFIG_S3_SECRET_ACCESS_KEY="$S3_SECRET_ACCESS_KEY |
| 12 | |
| 13 | # rclone downloads to a .partial file and renames it, and zoekt only loads *.zoekt, so a half-written shard is never served. |
| 14 | sync_shards() { |
| 15 | # The remote lives in the environment above; an empty --config stops rclone looking for a file and logging that it found none on every run. |
| 16 | rclone --config "" sync |
| 17 | } |
| 18 | |
| 19 | # Syncing in the background keeps a slow or unreachable bucket from holding the webserver, and its healthcheck, hostage; zoekt loads shards as they land. |
| 20 | (while true; do sync_shards; |
| 21 | # Platforms such as Railway healthcheck the port they hand out in PORT. |
| 22 | echo "Running zoekt-webserver on ${PORT:- |
| 23 | exec zoekt-webserver -index /data/index |