fix: improve run script (#4609)
Co-authored-by: Meier Lukas <meierschlumpf@gmail.com>
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Create sub directories in volume
|
# Create sub directories in volume
|
||||||
mkdir -p /appdata/db
|
mkdir -p /appdata/db
|
||||||
mkdir -p /appdata/redis
|
mkdir -p /appdata/redis
|
||||||
mkdir -p /appdata/trusted-certificates
|
mkdir -p /appdata/trusted-certificates
|
||||||
|
|
||||||
# Run migrations
|
# Run migrations
|
||||||
if [ $DB_MIGRATIONS_DISABLED = "true" ]; then
|
if [ "$DB_MIGRATIONS_DISABLED" = "true" ]; then
|
||||||
echo "DB migrations are disabled, skipping"
|
echo "DB migrations are disabled, skipping"
|
||||||
else
|
else
|
||||||
echo "Running DB migrations"
|
echo "Running DB migrations"
|
||||||
@@ -20,13 +22,15 @@ export CRON_JOB_API_KEY=$(openssl rand -base64 32)
|
|||||||
# 1. Replace the HOSTNAME in the nginx template file
|
# 1. Replace the HOSTNAME in the nginx template file
|
||||||
# 2. Create the nginx configuration file from the template
|
# 2. Create the nginx configuration file from the template
|
||||||
# 3. Start the nginx server
|
# 3. Start the nginx server
|
||||||
|
export HOSTNAME
|
||||||
envsubst '${HOSTNAME}' < /etc/nginx/templates/nginx.conf > /etc/nginx/nginx.conf
|
envsubst '${HOSTNAME}' < /etc/nginx/templates/nginx.conf > /etc/nginx/nginx.conf
|
||||||
# Start services in the background and store their PIDs
|
# Start services in the background and store their PIDs
|
||||||
nginx -g 'daemon off;' &
|
nginx -g 'daemon off;' &
|
||||||
NGINX_PID=$!
|
NGINX_PID=$!
|
||||||
|
|
||||||
if [ $REDIS_IS_EXTERNAL = "true" ]; then
|
if [ "$REDIS_IS_EXTERNAL" = "true" ]; then
|
||||||
echo "Using external Redis server at redis://$REDIS_HOST:$REDIS_PORT"
|
echo "Using external Redis server at redis://$REDIS_HOST:$REDIS_PORT"
|
||||||
|
REDIS_PID=""
|
||||||
else
|
else
|
||||||
echo "Starting internal Redis server"
|
echo "Starting internal Redis server"
|
||||||
redis-server /app/redis.conf &
|
redis-server /app/redis.conf &
|
||||||
@@ -49,9 +53,11 @@ terminate() {
|
|||||||
echo "Received SIGTERM. Shutting down..."
|
echo "Received SIGTERM. Shutting down..."
|
||||||
kill -TERM $NGINX_PID $TASKS_PID $WSS_PID $NEXTJS_PID 2>/dev/null
|
kill -TERM $NGINX_PID $TASKS_PID $WSS_PID $NEXTJS_PID 2>/dev/null
|
||||||
wait
|
wait
|
||||||
# kill redis-server last because of logging of other services
|
# kill redis-server last because of logging of other services and only if $REDIS_PID is set
|
||||||
kill -TERM $REDIS_PID 2>/dev/null
|
if [ -n "$REDIS_PID" ]; then
|
||||||
wait
|
kill -TERM $REDIS_PID 2>/dev/null
|
||||||
|
wait
|
||||||
|
fi
|
||||||
echo "Shutdown complete."
|
echo "Shutdown complete."
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
@@ -61,4 +67,4 @@ trap terminate TERM INT
|
|||||||
|
|
||||||
# Wait for all processes
|
# Wait for all processes
|
||||||
wait $NEXTJS_PID
|
wait $NEXTJS_PID
|
||||||
terminate
|
terminate
|
||||||
|
|||||||
Reference in New Issue
Block a user