A social knowledge tool for researchers built on ATProto
1#!/bin/bash
2
3# Check if Docker daemon is running
4if ! docker info > /dev/null 2>&1; then
5 echo "Error: Docker daemon is not running. Please start Docker and try again."
6 exit 1
7fi
8
9# Check if the Postgres container is running
10if [ "$(docker ps -q -f name=annos-postgres)" ]; then
11 echo "Postgres container is already running."
12 export DB_RUNNING=true
13else
14 echo "Starting Postgres container..."
15 npm run db:start
16 export DB_RUNNING=false
17fi
18
19# Trap SIGINT and SIGTERM to stop containers on exit, only if we started them
20function cleanup_postgres {
21 if [ "$DB_RUNNING" = false ]; then
22 if [ "$(docker ps -q -f name=annos-postgres)" ]; then
23 echo "Stopping Postgres container..."
24 npm run db:stop
25 npm run db:remove
26 fi
27 fi
28}
29
30# Export the cleanup function so it can be called from other scripts
31export -f cleanup_postgres