Skip to content

Commit

Permalink
♻️ REFACTOR: generation of php-fpm.conf for #156
Browse files Browse the repository at this point in the history
  • Loading branch information
apolopena committed Jan 23, 2022
1 parent 6a4f300 commit 59682aa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
5 changes: 3 additions & 2 deletions .gp/bash/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,9 @@ laravel_ui_version() {
fi
}

# Dynamically Configures php-fpm based on currently used bersion of PHP
# NOTE: If you want to configure this further do it elsewhere or open a PR
# php_fpm_conf
# Configures the php-fpm.conf depending on PHP version ($1) and the output file ($2)
# NOTE: If you want to configure this further parse the result of this from elsewhere.
php_fpm_conf() {
[[ -z $1 || -z $2 ]] && 2>&1 echo " ERROR: utils.sh --> php_fpm_conf(): Bad args. Script aborted" && exit 1
echo "\
Expand Down
39 changes: 29 additions & 10 deletions .gp/bash/php.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,29 @@ configure_php() {
fi
}

configure_apache() {
local loc=/var/log/apache2
mv /tmp/apache2.conf /etc/apache2/apache2.conf
sudo chown gitpod:gitpod "$loc/access.log" "$loc/error.log" "$loc/other_vhosts_access.log"
return $?
}

generate_php_fpm_conf() {
local php_fpm_conf_path="$GITPOD_REPO_ROOT/.gp/conf/php-fpm/php-fpm.conf"
local active_php_version=
active_php_version="$(. /tmp/utils.sh php_version)"
local msg="Autogenerating php-fpm configuration file for PHP $active_php_version in $php_fpm_conf_path"
echo " $msg" | tee -a $log
bash /tmp/helpers.sh php_fpm_conf "$active_php_version" "$php_fpm_conf_path"
local ec=$?
if [[ $ec -eq 0 ]]; then
echo " SUCCESS: $msg" | tee -a $log
else
2>&1 echo " ERROR: $msg" | tee -a $log
return 1
fi
}

keep_existing_php() {
local msg1 msg2=
[[ $1 == 'fallback' ]] &&
Expand All @@ -125,15 +148,6 @@ keep_existing_php() {
exit 0
}

configure_apache() {
local loc=/var/log/apache2
mv /tmp/apache2.conf /etc/apache2/apache2.conf
sudo chown gitpod:gitpod "$loc/access.log" "$loc/error.log" "$loc/other_vhosts_access.log"
return $?
}



# BEGIN: MAIN
echo "BEGIN: php.sh" | tee -a $log
php_version=$(. /tmp/utils.sh parse_ini_value /tmp/starter.ini PHP version)
Expand Down Expand Up @@ -170,9 +184,14 @@ if ! configure_php; then
2>&1 echo " php.sh was aborted: Optional php installation failed to be configured!" | tee -a $log && exit 1
fi

# Generate php-fpm.conf
if ! generate_php_fpm_conf; then
2>&1 echo " WARNING: php-fpm.conf was not autogenerated. PHP for nginx may not work properly." | tee -a $log
fi

# Configure Apache
if ! configure_apache; then
2>&1 echo " WARNING: Apache configuration failed. Apache may not work properly." | tee -a $log && exit 1
2>&1 echo " WARNING: Apache configuration failed. Apache may not work properly." | tee -a $log
fi

echo "END: php.sh" | tee -a $log
Expand Down

0 comments on commit 59682aa

Please sign in to comment.