1
1
#! /bin/bash
2
2
3
- echo " "
4
- echo " ***********************************************************"
5
- echo " Starting LARAVEL PHP-FPM Container "
6
- echo " ***********************************************************"
7
-
8
3
set -e
9
- info () {
4
+
5
+ # Logging functions
6
+ log () {
7
+ local level=$1
8
+ shift
10
9
{ set +x; } 2> /dev/null
11
- echo ' [INFO] ' " $@ "
10
+ echo " [$level ] $@ "
11
+ }
12
+
13
+ info () {
14
+ log " INFO" " $@ "
12
15
}
16
+
13
17
warning () {
14
- { set +x; } 2> /dev/null
15
- echo ' [WARNING] ' " $@ "
18
+ log " WARNING" " $@ "
16
19
}
20
+
17
21
fatal () {
18
- { set +x; } 2> /dev/null
19
- echo ' [ERROR] ' " $@ " >&2
22
+ log " ERROR" " $@ " >&2
20
23
exit 1
21
24
}
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
48
59
EOF
49
- info " Laravel supervisor config created"
60
+
61
+ info " Laravel supervisor config created at $SUPERVISOR_TASK "
50
62
else
51
- info " artisan file not found"
63
+ info " Artisan file not found at $ARTISAN_PATH "
52
64
fi
53
65
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 "
58
73
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 "
61
76
fi
62
77
63
- supervisord -c /etc/supervisor/supervisord.conf
78
+ # Start Supervisor
79
+ supervisord -c /etc/supervisor/supervisord.conf
0 commit comments