fix: Improve service startup and Hex installation
- Check if PostgreSQL/Redis already running before starting - Install Hex and Rebar3 non-interactively on shell entry - Only run migrations if deps directory exists - Better error messages with log file locations This fixes issues when: - Port 5432 is already in use (existing PostgreSQL) - Port 6379 is already in use (existing Redis) - Mix prompts for Hex installation interactively
This commit is contained in:
parent
38347eb571
commit
dfa334650f
1 changed files with 52 additions and 37 deletions
|
|
@ -66,21 +66,28 @@ let
|
|||
EOF
|
||||
fi
|
||||
|
||||
# Start PostgreSQL
|
||||
echo "🐘 Starting PostgreSQL on port ${pgPort}..."
|
||||
${postgresql_16}/bin/pg_ctl -D ${pgDataDir} -l ${pgDataDir}/logfile -o "-p ${pgPort}" start
|
||||
# Check if PostgreSQL is already running on this port
|
||||
if ${postgresql_16}/bin/pg_isready -h ${pgHost} -p ${pgPort} > /dev/null 2>&1; then
|
||||
echo "✓ PostgreSQL already running on port ${pgPort}"
|
||||
else
|
||||
# Start PostgreSQL
|
||||
echo "🐘 Starting PostgreSQL on port ${pgPort}..."
|
||||
${postgresql_16}/bin/pg_ctl -D ${pgDataDir} -l ${pgDataDir}/logfile -o "-p ${pgPort}" start
|
||||
|
||||
# Wait for PostgreSQL to be ready
|
||||
for i in {1..30}; do
|
||||
if ${postgresql_16}/bin/pg_isready -h ${pgHost} -p ${pgPort} > /dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
if [ $i -eq 30 ]; then
|
||||
echo "❌ PostgreSQL failed to start within 30 seconds"
|
||||
exit 1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
# Wait for PostgreSQL to be ready
|
||||
for i in {1..30}; do
|
||||
if ${postgresql_16}/bin/pg_isready -h ${pgHost} -p ${pgPort} > /dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
if [ $i -eq 30 ]; then
|
||||
echo "❌ PostgreSQL failed to start within 30 seconds"
|
||||
echo " Check ${pgDataDir}/logfile for details"
|
||||
exit 1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
echo "✓ PostgreSQL started successfully"
|
||||
fi
|
||||
|
||||
# Create postgres role if it doesn't exist (needed by some tools)
|
||||
${postgresql_16}/bin/psql -h ${pgHost} -p ${pgPort} -U $USER -d postgres -tc \
|
||||
|
|
@ -102,28 +109,32 @@ let
|
|||
|
||||
echo "✓ PostgreSQL started successfully"
|
||||
|
||||
# Start Redis
|
||||
echo "📮 Starting Redis on port ${redisPort}..."
|
||||
mkdir -p ${redisDataDir}
|
||||
${redis}/bin/redis-server --daemonize yes \
|
||||
--port ${redisPort} \
|
||||
--dir ${redisDataDir} \
|
||||
--save "" \
|
||||
--appendonly no
|
||||
# Check if Redis is already running on this port
|
||||
if ${redis}/bin/redis-cli -p ${redisPort} ping > /dev/null 2>&1; then
|
||||
echo "✓ Redis already running on port ${redisPort}"
|
||||
else
|
||||
# Start Redis
|
||||
echo "📮 Starting Redis on port ${redisPort}..."
|
||||
mkdir -p ${redisDataDir}
|
||||
${redis}/bin/redis-server --daemonize yes \
|
||||
--port ${redisPort} \
|
||||
--dir ${redisDataDir} \
|
||||
--save "" \
|
||||
--appendonly no
|
||||
|
||||
# Wait for Redis to be ready
|
||||
for i in {1..10}; do
|
||||
if ${redis}/bin/redis-cli -p ${redisPort} ping > /dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
if [ $i -eq 10 ]; then
|
||||
echo "❌ Redis failed to start within 10 seconds"
|
||||
exit 1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo "✓ Redis started successfully"
|
||||
# Wait for Redis to be ready
|
||||
for i in {1..10}; do
|
||||
if ${redis}/bin/redis-cli -p ${redisPort} ping > /dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
if [ $i -eq 10 ]; then
|
||||
echo "❌ Redis failed to start within 10 seconds"
|
||||
exit 1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
echo "✓ Redis started successfully"
|
||||
fi
|
||||
|
||||
# Mark services as started
|
||||
touch ${servicesFlag}
|
||||
|
|
@ -262,12 +273,16 @@ mkShell {
|
|||
# Ensure Erlang can find NIF libraries
|
||||
export ERL_AFLAGS="-kernel shell_history enabled"
|
||||
|
||||
# Install Hex and Rebar3 if not already installed
|
||||
mix local.hex --force --if-missing > /dev/null 2>&1
|
||||
mix local.rebar --force --if-missing > /dev/null 2>&1
|
||||
|
||||
# Auto-start services on first shell entry
|
||||
if [ ! -f "${servicesFlag}" ]; then
|
||||
${startServices}/bin/start-services
|
||||
|
||||
# Run migrations if databases exist
|
||||
if mix ecto.migrate 2>/dev/null; then
|
||||
# Run migrations if databases exist and Mix deps are available
|
||||
if [ -d "deps" ] && mix ecto.migrate 2>/dev/null; then
|
||||
echo "✓ Database migrations applied"
|
||||
fi
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue