Refactoring

This commit is contained in:
2022-08-14 14:43:00 +02:00
parent d45a6dea78
commit 43fe96b0cb
5 changed files with 52 additions and 63 deletions

View File

@@ -8,25 +8,11 @@ echo "***********************************************************"
set -e
## Create PHP-FPM worker process
TASK=/etc/supervisor/conf.d/php-fpm.conf
touch $TASK
cat > "$TASK" <<EOF
[program:php-fpm]
command=/usr/local/sbin/php-fpm
numprocs=1
autostart=true
autorestart=true
stderr_logfile=/var/log/php-fpm_consumer.err.log
stdout_logfile=/var/log/php-fpm_consumer.out.log
user=root
priority=100
EOF
## Check if the artisan file exists
if [ -f $WORKDIR/artisan ]; then
if [ -f /var/www/html/artisan ]; then
echo "${Green} artisan file found, creating laravel supervisor config"
# Set DocumentRoot to the Laravel project directory
export DOCUMENT_ROOT=$WORKDIR/public
export DOCUMENT_ROOT=/var/www/html/public
##Create Laravel Scheduler process
TASK=/etc/supervisor/conf.d/laravel-worker.conf
touch $TASK
@@ -36,7 +22,7 @@ if [ -f $WORKDIR/artisan ]; then
user=root
[program:Laravel-scheduler]
process_name=%(program_name)s_%(process_num)02d
command=/bin/sh -c "while [ true ]; do (php $WORKDIR/artisan schedule:run --verbose --no-interaction &); sleep 60; done"
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
@@ -46,7 +32,7 @@ if [ -f $WORKDIR/artisan ]; then
[program:Laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php $WORKDIR/artisan queue:work --sleep=3 --tries=3
command=php /var/www/html/artisan queue:work --sleep=3 --tries=3
autostart=true
autorestart=true
numprocs=$LARAVEL_PROCS_NUMBER
@@ -58,17 +44,6 @@ echo "${Green} Laravel supervisor config created"
else
echo "${Red} artisan file not found"
fi
#check if storage directory exists
echo "Checking if storage directory exists"
if [ -d "$STORAGE_DIR" ]; then
echo "Directory $STORAGE_DIR exist. Fixing permissions..."
chown -R www-data:www-data $STORAGE_DIR
chmod -R 775 $STORAGE_DIR
echo "${Green}Permissions fixed"
else
echo "${Red} Directory $STORAGE_DIR does not exist"
fi
# Enable custom nginx config files if they exist
if [ -f /var/www/html/conf/nginx/nginx.conf ]; then
@@ -94,7 +69,8 @@ if [ -f /var/www/html/conf/nginx/nginx-site.conf ]; then
listen [::]:80 default_server;
server_name $DOMAIN;
# Add index.php to setup Nginx, PHP & PHP-FPM config
index index.php index.html index.htm index.nginx-debian.html; error_log /var/log/nginx/error.log;
index index.php index.html index.htm index.nginx-debian.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root $DOCUMENT_ROOT;
# pass PHP scripts on Nginx to FastCGI (PHP-FPM) server
@@ -146,19 +122,8 @@ if [ -f /var/www/html/conf/worker/supervisor.conf ]; then
echo "${Green} If you want to add more supervisor configs, create config file in /var/www/html/conf/worker/supervisor.conf"
echo "${Green} Start supervisor with default config..."
fi
## Add nginx process to supervisor
TASK=/etc/supervisor/conf.d/nginx.conf
touch $TASK
cat > "$TASK" <<EOF
[program:nginx]
command=/usr/sbin/nginx -g "daemon off;"
numprocs=1
autostart=true
autorestart=true
stderr_logfile=/var/log/ngnix.err.log
stdout_logfile=/var/log/ngnix.out.log
user=root
EOF
echo ""
echo "**********************************"