Skip to content

Commit 86b7f96

Browse files
authored
Optimization of entrypoint (#85)
* Optimization of entrypoint * Add version file
1 parent 619f66f commit 86b7f96

File tree

2 files changed

+63
-46
lines changed

2 files changed

+63
-46
lines changed

src/entrypoint.sh

Lines changed: 62 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,79 @@
11
#!/bin/bash
22

3-
echo ""
4-
echo "***********************************************************"
5-
echo " Starting LARAVEL PHP-FPM Container "
6-
echo "***********************************************************"
7-
83
set -e
9-
info() {
4+
5+
# Logging functions
6+
log() {
7+
local level=$1
8+
shift
109
{ set +x; } 2> /dev/null
11-
echo '[INFO] ' "$@"
10+
echo "[$level] $@"
11+
}
12+
13+
info() {
14+
log "INFO" "$@"
1215
}
16+
1317
warning() {
14-
{ set +x; } 2> /dev/null
15-
echo '[WARNING] ' "$@"
18+
log "WARNING" "$@"
1619
}
20+
1721
fatal() {
18-
{ set +x; } 2> /dev/null
19-
echo '[ERROR] ' "$@" >&2
22+
log "ERROR" "$@" >&2
2023
exit 1
2124
}
22-
## Check if the artisan file exists
23-
if [ -f /var/www/html/artisan ]; then
24-
info "Artisan file found, creating laravel supervisor config..."
25-
##Create Laravel Scheduler process
26-
TASK=/etc/supervisor/conf.d/laravel-worker.conf
27-
touch $TASK
28-
cat > "$TASK" <<EOF
29-
[program:Laravel-scheduler]
30-
process_name=%(program_name)s_%(process_num)02d
31-
command=/bin/sh -c "while [ true ]; do (php /var/www/html/artisan schedule:run --verbose --no-interaction &); sleep 60; done"
32-
autostart=true
33-
autorestart=true
34-
numprocs=1
35-
user=$USER_NAME
36-
stdout_logfile=/var/log/laravel_scheduler.out.log
37-
redirect_stderr=true
38-
39-
[program:Laravel-worker]
40-
process_name=%(program_name)s_%(process_num)02d
41-
command=php /var/www/html/artisan queue:work --sleep=3 --tries=3
42-
autostart=true
43-
autorestart=true
44-
numprocs=$LARAVEL_PROCS_NUMBER
45-
user=$USER_NAME
46-
redirect_stderr=true
47-
stdout_logfile=/var/log/laravel_worker.log
25+
26+
# Banner
27+
echo ""
28+
echo "***********************************************************"
29+
echo " Starting LARAVEL PHP-FPM Container "
30+
echo "***********************************************************"
31+
32+
# Check if the artisan file exists
33+
ARTISAN_PATH="/var/www/html/artisan"
34+
if [[ -f "$ARTISAN_PATH" ]]; then
35+
info "Artisan file found, creating Laravel supervisor config..."
36+
37+
# Create Laravel Supervisor config
38+
SUPERVISOR_TASK="/etc/supervisor/conf.d/laravel-worker.conf"
39+
cat > "$SUPERVISOR_TASK" <<EOF
40+
[program:Laravel-scheduler]
41+
process_name=%(program_name)s_%(process_num)02d
42+
command=/bin/sh -c "while true; do php $ARTISAN_PATH schedule:run --verbose --no-interaction & sleep 60; done"
43+
autostart=true
44+
autorestart=true
45+
numprocs=1
46+
user=$USER_NAME
47+
stdout_logfile=/var/log/laravel_scheduler.out.log
48+
redirect_stderr=true
49+
50+
[program:Laravel-worker]
51+
process_name=%(program_name)s_%(process_num)02d
52+
command=php $ARTISAN_PATH queue:work --sleep=3 --tries=3
53+
autostart=true
54+
autorestart=true
55+
numprocs=$LARAVEL_PROCS_NUMBER
56+
user=$USER_NAME
57+
redirect_stderr=true
58+
stdout_logfile=/var/log/laravel_worker.log
4859
EOF
49-
info "Laravel supervisor config created"
60+
61+
info "Laravel supervisor config created at $SUPERVISOR_TASK"
5062
else
51-
info "artisan file not found"
63+
info "Artisan file not found at $ARTISAN_PATH"
5264
fi
5365

54-
## Check if php.ini file exists
55-
if [ -f /var/www/html/conf/php/php.ini ]; then
56-
cp /var/www/html/conf/php/php.ini $PHP_INI_DIR/conf.d/
57-
info "Custom php.ini file found and copied in $PHP_INI_DIR/conf.d/"
66+
# Check if custom php.ini file exists
67+
PHP_INI_SOURCE="/var/www/html/conf/php/php.ini"
68+
PHP_INI_TARGET="$PHP_INI_DIR/conf.d/php.ini"
69+
70+
if [[ -f "$PHP_INI_SOURCE" ]]; then
71+
cp "$PHP_INI_SOURCE" "$PHP_INI_TARGET"
72+
info "Custom php.ini file found and copied to $PHP_INI_TARGET"
5873
else
59-
info "Custom php.ini file not found"
60-
info "If you want to add a custom php.ini file, you add it in /var/www/html/conf/php/php.ini"
74+
info "Custom php.ini file not found at $PHP_INI_SOURCE"
75+
info "To use a custom php.ini file, place it at $PHP_INI_SOURCE"
6176
fi
6277

63-
supervisord -c /etc/supervisor/supervisord.conf
78+
# Start Supervisor
79+
supervisord -c /etc/supervisor/supervisord.conf

version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8.4.7

0 commit comments

Comments
 (0)