Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increment backend port also when commented #3180

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

henri-hulski
Copy link
Contributor

@henri-hulski henri-hulski commented Jan 2, 2023

This allows to grep the incremented port also for other backends then php-fpm with %backend_lsnr% in the web template.

This is an example how I use it in a wsgi app with gunicorn. It works out of the box with this patch applied.

Backend template:

;[%backend%]
;listen = 127.0.0.1:%backend_port%

Nginx web template:

server {
    listen      %ip%:%web_ssl_port% ssl http2;
    server_name %domain_idn% %alias_idn%;

    location / {
        proxy_pass          http://%backend_lsnr%/;
        proxy_redirect      off;
        proxy_set_header    Host                    $host;
        proxy_set_header    X-Real-IP               $remote_addr;
        proxy_set_header    X-Forwarded-For         $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Protocol    $scheme;
    }
}

This allows to grep the incremented port also for other backends
then php-fpm with `%backend_lsnr%` in the web template.
@jaapmarcus jaapmarcus self-requested a review January 2, 2023 21:10
Copy link
Member

@jaapmarcus jaapmarcus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments if not the default template is used it seems to fail loading properly

@@ -55,7 +55,7 @@ fi

# Allocating backend port
backend_port=9000
ports=$(grep -v '^;' $pool/* 2> /dev/null | grep listen | grep -o :[0-9].*)
ports=$(grep $pool/* 2> /dev/null | grep -o :[0-9].*)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I rebuild a domain with PHP-7_4 template for example it runs:
pool="/etc/php/7.4/fpm/pool.d"
grep $pool/* 2> /dev/null | grep -o :[0-9].*

And it freezes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange. I made the same PR to Vesta in December 2018. It was excepted in October 2021 and is still the newest change to both files.

outroll/vesta#1791

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it when I made it the first time but maybe something has changed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hestiacp/func/domain.sh

Lines 102 to 131 in 559aece

# Accept first function argument as backend template otherwise fallback to $template global variable
local backend_template=${1:-$template}
pool=$(find -L /etc/php/ -name "$domain.conf" -exec dirname {} \;)
# Check if multiple-PHP installed
regex="socket-(\d+)_(\d+)"
if [[ $backend_template =~ ^.*PHP-([0-9])\_([0-9])$ ]]; then
backend_version="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
pool=$(find -L /etc/php/$backend_version -type d \( -name "pool.d" -o -name "*fpm.d" \))
else
backend_version=$(multiphp_default_version)
if [ -z "$pool" ] || [ -z "$BACKEND" ]; then
pool=$(find -L /etc/php/$backend_version -type d \( -name "pool.d" -o -name "*fpm.d" \))
fi
fi
if [ ! -e "$pool" ]; then
check_result $E_NOTEXIST "php-fpm pool doesn't exist"
fi
backend_type="$domain"
if [ "$WEB_BACKEND_POOL" = 'user' ]; then
backend_type="$user"
fi
if [ -e "$pool/$backend_type.conf" ]; then
backend_lsnr=$(grep "listen =" $pool/$backend_type.conf)
backend_lsnr=$(echo "$backend_lsnr" | cut -f 2 -d = | sed "s/ //")
if [ -n "$(echo $backend_lsnr | grep /)" ]; then
backend_lsnr="unix:$backend_lsnr"
fi
fi

vs

https://github.com/serghey-rodin/vesta/blob/bba7400b8a01d462dae4b2f805866c2ac5efbf00/func/domain.sh#L85-L103

It looks like we have made some changes to it it might be the reason why it breaks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like as VestaCP doesn't support multiple fpm version is caused the issue

Replacing your line with

ports=$(grep listen /etc/php/*/fpm/pool.d/* | grep -o :[0-9].*)

Seems to work. But how do we provide the port number back to the user.

it would be easier to supply the user with a option to spefiy the port via web domain selection

@@ -62,7 +62,7 @@ delete_web_backend

# Allocating backend port
backend_port=9000
ports=$(grep -v '^;' $pool/* 2> /dev/null | grep listen | grep -o :[0-9].*)
ports=$(grep $pool/* 2> /dev/null | grep -o :[0-9].*)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@jaapmarcus jaapmarcus self-requested a review January 5, 2023 13:34
Copy link
Member

@jaapmarcus jaapmarcus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See last comment accidentally approved it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants