mirror of
https://github.com/jkaninda/laravel-php-fpm.git
synced 2025-12-06 00:49:39 +01:00
Optimization of entrypoint (#85)
* Optimization of entrypoint * Add version file
This commit is contained in:
@@ -1,63 +1,79 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Logging functions
|
||||
log() {
|
||||
local level=$1
|
||||
shift
|
||||
{ set +x; } 2> /dev/null
|
||||
echo "[$level] $@"
|
||||
}
|
||||
|
||||
info() {
|
||||
log "INFO" "$@"
|
||||
}
|
||||
|
||||
warning() {
|
||||
log "WARNING" "$@"
|
||||
}
|
||||
|
||||
fatal() {
|
||||
log "ERROR" "$@" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Banner
|
||||
echo ""
|
||||
echo "***********************************************************"
|
||||
echo " Starting LARAVEL PHP-FPM Container "
|
||||
echo "***********************************************************"
|
||||
|
||||
set -e
|
||||
info() {
|
||||
{ set +x; } 2> /dev/null
|
||||
echo '[INFO] ' "$@"
|
||||
}
|
||||
warning() {
|
||||
{ set +x; } 2> /dev/null
|
||||
echo '[WARNING] ' "$@"
|
||||
}
|
||||
fatal() {
|
||||
{ set +x; } 2> /dev/null
|
||||
echo '[ERROR] ' "$@" >&2
|
||||
exit 1
|
||||
}
|
||||
## Check if the artisan file exists
|
||||
if [ -f /var/www/html/artisan ]; then
|
||||
info "Artisan file found, creating laravel supervisor config..."
|
||||
##Create Laravel Scheduler process
|
||||
TASK=/etc/supervisor/conf.d/laravel-worker.conf
|
||||
touch $TASK
|
||||
cat > "$TASK" <<EOF
|
||||
[program:Laravel-scheduler]
|
||||
process_name=%(program_name)s_%(process_num)02d
|
||||
command=/bin/sh -c "while [ true ]; do (php /var/www/html/artisan 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 /var/www/html/artisan 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
|
||||
# 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
|
||||
EOF
|
||||
info "Laravel supervisor config created"
|
||||
|
||||
info "Laravel supervisor config created at $SUPERVISOR_TASK"
|
||||
else
|
||||
info "artisan file not found"
|
||||
info "Artisan file not found at $ARTISAN_PATH"
|
||||
fi
|
||||
|
||||
## Check if php.ini file exists
|
||||
if [ -f /var/www/html/conf/php/php.ini ]; then
|
||||
cp /var/www/html/conf/php/php.ini $PHP_INI_DIR/conf.d/
|
||||
info "Custom php.ini file found and copied in $PHP_INI_DIR/conf.d/"
|
||||
# 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"
|
||||
else
|
||||
info "Custom php.ini file not found"
|
||||
info "If you want to add a custom php.ini file, you add it in /var/www/html/conf/php/php.ini"
|
||||
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"
|
||||
fi
|
||||
|
||||
supervisord -c /etc/supervisor/supervisord.conf
|
||||
# Start Supervisor
|
||||
supervisord -c /etc/supervisor/supervisord.conf
|
||||
Reference in New Issue
Block a user