2019-08-16 19:38:26 +03:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
set -e
|
|
|
|
|
2021-12-07 21:14:56 +03:00
|
|
|
# If SHELL_VERBOSITY was not explicitly provided, run commands in quite mode (-q)
|
|
|
|
[ $SHELL_VERBOSITY ] && flags="" || flags="-q"
|
|
|
|
|
2019-08-16 19:38:26 +03:00
|
|
|
cd /etc/shlink
|
|
|
|
|
|
|
|
echo "Creating fresh database if needed..."
|
2021-12-07 21:14:56 +03:00
|
|
|
php bin/cli db:create -n ${flags}
|
2019-08-16 19:38:26 +03:00
|
|
|
|
|
|
|
echo "Updating database..."
|
2021-12-07 21:14:56 +03:00
|
|
|
php bin/cli db:migrate -n ${flags}
|
2019-08-16 19:38:26 +03:00
|
|
|
|
|
|
|
echo "Generating proxies..."
|
2022-09-08 15:10:09 +03:00
|
|
|
php bin/doctrine orm:generate-proxies -n ${flags}
|
2019-08-16 19:38:26 +03:00
|
|
|
|
2020-04-06 21:52:33 +03:00
|
|
|
echo "Clearing entities cache..."
|
2022-09-08 15:10:09 +03:00
|
|
|
php bin/doctrine orm:clear-cache:metadata -n ${flags}
|
2020-04-06 21:52:33 +03:00
|
|
|
|
2022-09-18 18:00:03 +03:00
|
|
|
# Try to download GeoLite2 db file only if the license key env var was defined and skipping was not explicitly set
|
|
|
|
if [ ! -z "${GEOLITE_LICENSE_KEY}" ] && [ "${SKIP_INITIAL_GEOLITE_DOWNLOAD}" != "true" ]; then
|
2021-04-08 15:32:19 +03:00
|
|
|
echo "Downloading GeoLite2 db file..."
|
2021-12-07 21:14:56 +03:00
|
|
|
php bin/cli visit:download-db -n ${flags}
|
2021-04-08 15:32:19 +03:00
|
|
|
fi
|
|
|
|
|
2022-01-03 20:48:08 +03:00
|
|
|
# Periodically run visit:locate every hour, if ENABLE_PERIODIC_VISIT_LOCATE=true was provided
|
2022-09-18 18:00:03 +03:00
|
|
|
if [ "${ENABLE_PERIODIC_VISIT_LOCATE}" = "true" ]; then
|
2022-01-03 20:48:08 +03:00
|
|
|
echo "Configuring periodic visit location..."
|
2021-05-30 18:41:00 +03:00
|
|
|
echo "0 * * * * php /etc/shlink/bin/cli visit:locate -q" > /etc/crontabs/root
|
2021-05-26 16:45:24 +03:00
|
|
|
/usr/sbin/crond &
|
|
|
|
fi
|
|
|
|
|
2022-08-27 18:17:37 +03:00
|
|
|
# RoadRunner config needs these to have been set, so falling back to default values if not set yet
|
2022-09-03 18:02:57 +03:00
|
|
|
if [ "$SHLINK_RUNTIME" == 'rr' ]; then
|
|
|
|
export PORT="${PORT:-"8080"}"
|
|
|
|
# Default to 0 so that RoadRunner decides the number of workers based on the amount of logical CPUs
|
|
|
|
export WEB_WORKER_NUM="${WEB_WORKER_NUM:-"0"}"
|
|
|
|
export TASK_WORKER_NUM="${TASK_WORKER_NUM:-"0"}"
|
|
|
|
fi
|
2022-08-27 18:17:37 +03:00
|
|
|
|
2022-08-27 14:01:38 +03:00
|
|
|
if [ "$SHLINK_RUNTIME" == 'openswoole' ]; then
|
|
|
|
# When restarting the container, openswoole might think it is already in execution
|
|
|
|
# This forces the app to be started every second until the exit code is 0
|
|
|
|
until php vendor/bin/laminas mezzio:swoole:start; do sleep 1 ; done
|
|
|
|
elif [ "$SHLINK_RUNTIME" == 'rr' ]; then
|
|
|
|
./bin/rr serve -c config/roadrunner/.rr.yml
|
|
|
|
fi
|