entrypoint.sh 1.2 KB

1234567891011121314151617181920212223
  1. #!/bin/bash
  2. # No systemd in the container, so the services run directly. The DB must be
  3. # accepting connections before vectorapi starts, or vectorapi exits - so the
  4. # port is waited on rather than slept past. A copied data directory can take
  5. # minutes to recover, which is why the wait is generous and reports how long it
  6. # took: that number is the cold-boot cost and is worth reading.
  7. set -e
  8. mkdir -p /var/lib/smartbotic-database
  9. chown -R smartbotic-db:smartbotic-db /var/lib/smartbotic-database 2>/dev/null || true
  10. su -s /bin/bash smartbotic-db -c '/usr/bin/smartbotic-database --config /etc/smartbotic-database/config.json' 2>&1 | sed 's/^/[db] /' &
  11. for i in $(seq 1 600); do
  12. (exec 3<>/dev/tcp/127.0.0.1/9004) 2>/dev/null && break
  13. sleep 1
  14. done
  15. echo "[entrypoint] database accepting connections after ${i}s"
  16. sed -i 's/"bind_address": *"[^"]*"/"bind_address": "0.0.0.0"/' /etc/smartbotic-vectorapi/config.json || true
  17. /usr/bin/smartbotic-vectorapi --config /etc/smartbotic-vectorapi/config.json 2>&1 | sed 's/^/[api] /' &
  18. for i in $(seq 1 120); do
  19. (exec 3<>/dev/tcp/127.0.0.1/8080) 2>/dev/null && break
  20. sleep 1
  21. done
  22. echo "[entrypoint] READY: api up after ${i}s"
  23. wait -n