2024-01-06 12:15:51 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
2022-06-18 10:31:47 +02:00
|
|
|
set -e
|
2025-05-11 09:17:02 +02:00
|
|
|
|
|
|
|
|
# Logging functions
|
|
|
|
|
log() {
|
|
|
|
|
local level=$1
|
|
|
|
|
shift
|
2024-01-06 12:15:51 +01:00
|
|
|
{ set +x; } 2> /dev/null
|
2025-05-11 09:17:02 +02:00
|
|
|
echo "[$level] $@"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info() {
|
|
|
|
|
log "INFO" "$@"
|
2024-01-06 12:15:51 +01:00
|
|
|
}
|
2025-05-11 09:17:02 +02:00
|
|
|
|
2024-01-06 12:15:51 +01:00
|
|
|
warning() {
|
2025-05-11 09:17:02 +02:00
|
|
|
log "WARNING" "$@"
|
2024-01-06 12:15:51 +01:00
|
|
|
}
|
2025-05-11 09:17:02 +02:00
|
|
|
|
2024-01-06 12:15:51 +01:00
|
|
|
fatal() {
|
2025-05-11 09:17:02 +02:00
|
|
|
log "ERROR" "$@" >&2
|
2024-01-06 12:15:51 +01:00
|
|
|
exit 1
|
|
|
|
|
}
|
2025-05-11 09:17:02 +02:00
|
|
|
|
|
|
|
|
# Banner
|
|
|
|
|
echo ""
|
|
|
|
|
echo "***********************************************************"
|
|
|
|
|
echo " Starting LARAVEL PHP-FPM Container "
|
|
|
|
|
echo "***********************************************************"
|
|
|
|
|
|
|
|
|
|
# Check if the artisan file exists
|
|
|
|
|
ARTISAN_PATH="/var/www/html/artisan"
|
|
|
|
|
if [[ -f "$ARTISAN_PATH" ]]; then
|
|
|
|
|
info "Artisan file found, creating Laravel supervisor config..."
|
|
|
|
|
|
|
|
|
|
# Create Laravel Supervisor config
|
|
|
|
|
SUPERVISOR_TASK="/etc/supervisor/conf.d/laravel-worker.conf"
|
|
|
|
|
cat > "$SUPERVISOR_TASK" <<EOF
|
|
|
|
|
[program:Laravel-scheduler]
|
|
|
|
|
process_name=%(program_name)s_%(process_num)02d
|
|
|
|
|
command=/bin/sh -c "while true; do php $ARTISAN_PATH schedule:run --verbose --no-interaction & sleep 60; done"
|
|
|
|
|
autostart=true
|
|
|
|
|
autorestart=true
|
|
|
|
|
numprocs=1
|
|
|
|
|
user=$USER_NAME
|
|
|
|
|
stdout_logfile=/var/log/laravel_scheduler.out.log
|
|
|
|
|
redirect_stderr=true
|
|
|
|
|
|
|
|
|
|
[program:Laravel-worker]
|
|
|
|
|
process_name=%(program_name)s_%(process_num)02d
|
|
|
|
|
command=php $ARTISAN_PATH queue:work --sleep=3 --tries=3
|
|
|
|
|
autostart=true
|
|
|
|
|
autorestart=true
|
|
|
|
|
numprocs=$LARAVEL_PROCS_NUMBER
|
|
|
|
|
user=$USER_NAME
|
|
|
|
|
redirect_stderr=true
|
|
|
|
|
stdout_logfile=/var/log/laravel_worker.log
|
2022-06-18 10:31:47 +02:00
|
|
|
EOF
|
2025-05-11 09:17:02 +02:00
|
|
|
|
|
|
|
|
info "Laravel supervisor config created at $SUPERVISOR_TASK"
|
2022-06-21 10:04:42 +02:00
|
|
|
else
|
2025-05-11 09:17:02 +02:00
|
|
|
info "Artisan file not found at $ARTISAN_PATH"
|
2022-06-21 10:04:42 +02:00
|
|
|
fi
|
|
|
|
|
|
2025-05-11 09:17:02 +02:00
|
|
|
# Check if custom php.ini file exists
|
|
|
|
|
PHP_INI_SOURCE="/var/www/html/conf/php/php.ini"
|
|
|
|
|
PHP_INI_TARGET="$PHP_INI_DIR/conf.d/php.ini"
|
|
|
|
|
|
|
|
|
|
if [[ -f "$PHP_INI_SOURCE" ]]; then
|
|
|
|
|
cp "$PHP_INI_SOURCE" "$PHP_INI_TARGET"
|
|
|
|
|
info "Custom php.ini file found and copied to $PHP_INI_TARGET"
|
2022-09-05 15:08:24 +02:00
|
|
|
else
|
2025-05-11 09:17:02 +02:00
|
|
|
info "Custom php.ini file not found at $PHP_INI_SOURCE"
|
|
|
|
|
info "To use a custom php.ini file, place it at $PHP_INI_SOURCE"
|
2022-09-05 15:08:24 +02:00
|
|
|
fi
|
2022-09-05 14:41:20 +02:00
|
|
|
|
2025-05-11 09:17:02 +02:00
|
|
|
# Start Supervisor
|
|
|
|
|
supervisord -c /etc/supervisor/supervisord.conf
|