Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions nix/tools/dbmate-tool.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ STAT_EXTENSION_SQL=@STAT_EXTENSION_SQL@

# Start PostgreSQL using nix
start_postgres() {
echo "Starting PostgreSQL..."
nix run "$FLAKE_URL#start-server" -- "$PSQL_VERSION" --skip-migrations --daemonize
DATDIR=$(mktemp -d)
echo "Starting PostgreSQL in directory: $DATDIR" # Create the DATDIR if it doesn't exist
nix run "$FLAKE_URL#start-server" -- "$PSQL_VERSION" --skip-migrations --daemonize --datdir "$DATDIR"
echo "PostgreSQL started."
}

Expand All @@ -31,16 +32,15 @@ cleanup() {
if pgrep -f "postgres" >/dev/null; then
echo "Stopping PostgreSQL gracefully..."

# Use a more specific signal handling approach
pkill -15 -f "postgres" # Send SIGTERM
# Use pg_ctl to stop PostgreSQL
pg_ctl -D "$DATDIR" stop

# Wait a bit for graceful shutdown
sleep 5

# If processes are still running, force kill
# Check if processes are still running
if pgrep -f "postgres" >/dev/null; then
echo "Forcing PostgreSQL processes to stop..."
pkill -9 -f "postgres" # Send SIGKILL if SIGTERM didn't work
echo "Warning: Some PostgreSQL processes could not be stopped gracefully."
fi
else
echo "PostgreSQL is not running, skipping stop."
Expand All @@ -53,9 +53,6 @@ cleanup() {
else
echo "Cleanup completed successfully"
fi

# Explicitly exit with 0 to prevent workflow failure
exit 0
}


Expand Down
14 changes: 12 additions & 2 deletions nix/tools/run-server.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ stop_postgres() {

trap 'stop_postgres' SIGINT SIGTERM

# Parse arguments
# Parse arguments
while [[ "$#" -gt 0 ]]; do
case "$1" in
Expand Down Expand Up @@ -108,6 +107,15 @@ while [[ "$#" -gt 0 ]]; do
print_help
exit 0
;;
--datdir)
if [[ -n "$2" && ! "$2" =~ ^- ]]; then
DATDIR="$2"
shift 2
else
echo "Error: --datadir requires a directory path"
exit 1
fi
;;
*)
if [[ "$1" =~ ^- ]]; then
echo "Unknown option: $1"
Expand Down Expand Up @@ -165,7 +173,9 @@ STAT_EXTENSION_SQL=@STAT_EXTENSION_SQL@
MECAB_LIB=@MECAB_LIB@

# Setup directories and locale settings
DATDIR=$(mktemp -d)
if [[ -z "$DATDIR" ]]; then
DATDIR=$(mktemp -d)
fi
LOCALE_ARCHIVE=@LOCALES@
CURRENT_SYSTEM=@CURRENT_SYSTEM@

Expand Down
Loading