Skip to content

Commit

Permalink
chore: have two apache servers (#10766)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgarel and stephanegigandet authored Jan 10, 2025
1 parent 4f596ad commit b720f67
Show file tree
Hide file tree
Showing 34 changed files with 294 additions and 109 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,17 @@ jobs:
run: make livecheck || ( tail -n 300 logs/apache2/*error*log; docker compose logs; false )
- name: test clean
run: make hdown

test_deployment:
name: 🦾 Some test of deployment tools
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: verify apache2 envvars is correct
run: |
env/setenv.sh off;
sh -c ". conf/apache-2.4/off-envvars"
sh -c "APACHE_CONFDIR=/etc/apache2-priority; . conf/apache-2.4/off-envvars"
3 changes: 2 additions & 1 deletion conf/apache-2.4/modperl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ PerlPassEnv CROWDIN_PROJECT_KEY
PerlPassEnv GEOLITE2_PATH
PerlPassEnv POSTGRES_USER
PerlPassEnv POSTGRES_PASSWORD
PerlPassEnv LOG4PERL_CONF
PerlPassEnv LOG_LEVEL_ROOT
PerlPassEnv LOG_LEVEL_MONGODB
PerlPassEnv LOG_LEVEL_RATE_LIMITER
Expand All @@ -31,4 +32,4 @@ PerlPassEnv RATE_LIMITER_BLOCKING_ENABLED
PerlPassEnv ODOO_CRM_URL
PerlPassEnv ODOO_CRM_DB
PerlPassEnv ODOO_CRM_USER
PerlPassEnv ODOO_CRM_PASSWORD
PerlPassEnv ODOO_CRM_PASSWORD
12 changes: 12 additions & 0 deletions conf/apache-2.4/mpm_prefork.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# prefork MPM

<IfModule mpm_prefork_module>
StartServers ${APACHE_MPM_START_SERVERS}
MinSpareServers ${APACHE_MPM_MIN_SPARSE_SERVERS}
MaxSpareServers ${APACHE_MPM_MAX_SPARSE_SERVERS}
MaxRequestWorkers ${APACHE_MPM_MAX_REQUEST_WORKERS}
ServerLimit ${APACHE_MPM_SERVER_LIMIT}
MaxConnectionsPerChild ${APACHE_MPM_MAX_CONN_PER_CHILD}
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
75 changes: 75 additions & 0 deletions conf/apache-2.4/off-envvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# This file override the envvars of apache2
# It is an important place to tweak apache2 through environment variables
# and put some logic in them

# It will use variables
# that are set in env.<server name>
# And also the instance name

# SUFFIX can be used to tweak settings according to the instance name
if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then
SUFFIX="-${APACHE_CONFDIR##/etc/apache2-}"
APACHE_INSTANCE=${APACHE_CONFDIR##/etc/apache2-}
else
SUFFIX=
APACHE_INSTANCE=
fi

# we will first source the standard envvars file (if it exists)
if [ -f /etc/apache2${SUFFIX}/envvars ];
then
. /etc/apache2/envvars
fi

# now we can set our specific settings

# we use off user instead of www-data
export APACHE_RUN_USER=off
export APACHE_RUN_GROUP=off

# port - standard or priority
export APACHE2_PORT=8001
if [ "$APACHE_INSTANCE" = "priority" ]
then
export APACHE2_PORT=8002
fi

APP_DIR=/srv/$PRODUCT_OPENER_FLAVOR_SHORT

LOG4PERL_CONF=$APP_DIR/conf/$PRODUCT_OPENER_FLAVOR_SHORT-log.conf
if [ -n "$APACHE_INSTANCE" ]
then
export LOG4PERL_CONF=$APP_DIR/conf/$PRODUCT_OPENER_FLAVOR_SHORT-$APACHE_INSTANCE-log.conf
fi

# MPM settings -----------

# StartServers: number of server processes to start
export APACHE_MPM_START_SERVERS=2
# MaxRequestWorkers: maximum number of server processes allowed to start
export APACHE_MPM_MAX_REQUEST_WORKERS=20
# MaxConnectionsPerChild: maximum number of requests a server process serves
# keep this a bit low to avoid memory issues
export APACHE_MPM_MAX_CONN_PER_CHILD=100
# specific MPM settings
if [ "$PRODUCT_OPENER_FLAVOR_SHORT" = "off" ]
then
export APACHE_MPM_START_SERVERS=5
export APACHE_MPM_MAX_REQUEST_WORKERS=25
if [ "$INSTANCE_NAME" = "priority" ]
then
export APACHE_MPM_MAX_REQUEST_WORKERS=50
fi
fi
if [ "$PRODUCT_OPENER_FLAVOR_SHORT" = "off-pro" ]
then
export APACHE_MPM_MAX_REQUEST_WORKERS=10
fi
# MinSpareServers: minimum number of server processes which are kept spare
# we use StartServers value
export APACHE_MPM_MIN_SPARSE_SERVERS=${APACHE_MPM_START_SERVERS}
# MaxSpareServers: maximum number of server processes which are kept spare
# we use MinSpareServers * 2
export APACHE_MPM_MAX_SPARSE_SERVERS=$((APACHE_MPM_MIN_SPARSE_SERVERS * 2))
# corresponds to max request workers + sparse servers
export APACHE_MPM_SERVER_LIMIT=$((APACHE_MPM_MAX_REQUEST_WORKERS + APACHE_MPM_MAX_SPARSE_SERVERS))
17 changes: 0 additions & 17 deletions conf/apache-2.4/off-mpm_prefork.conf

This file was deleted.

7 changes: 0 additions & 7 deletions conf/apache-2.4/off-ports.conf

This file was deleted.

16 changes: 0 additions & 16 deletions conf/apache-2.4/off-pro-mpm_prefork.conf

This file was deleted.

7 changes: 0 additions & 7 deletions conf/apache-2.4/off-pro-ports.conf

This file was deleted.

7 changes: 0 additions & 7 deletions conf/apache-2.4/opf-ports.conf

This file was deleted.

7 changes: 0 additions & 7 deletions conf/apache-2.4/opff-ports.conf

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 8002
# APACHE2_PORT has to be passed using -D directive in systemd/apache2.service.d/override.conf
Listen ${APACHE2_PORT}

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
4 changes: 2 additions & 2 deletions conf/apache-2.4/sites-available/obf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Require all granted
<VirtualHost *>
DocumentRoot /srv/obf/html
ServerName openbeautyfacts.org
ErrorLog /srv/obf/logs/error_log
CustomLog /srv/obf/logs/access_log proxy
ErrorLog /srv/obf/logs/error_log_${APACHE2_PORT}
CustomLog /srv/obf/logs/access_log_${APACHE2_PORT} proxy
LogLevel warn
ScriptAlias /cgi/ "/srv/obf/cgi/"

Expand Down
4 changes: 2 additions & 2 deletions conf/apache-2.4/sites-available/off-pro.conf
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Require all granted
<VirtualHost *>
DocumentRoot /srv/off-pro/html
ServerName pro.openfoodfacts.org
ErrorLog /srv/off-pro/logs/error_log
CustomLog /srv/off-pro/logs/access_log proxy
ErrorLog /srv/off-pro/logs/error_log_${APACHE2_PORT}
CustomLog /srv/off-pro/logs/access_log_${APACHE2_PORT} proxy
LogLevel warn
ScriptAlias /cgi/ "/srv/off-pro/cgi/"

Expand Down
4 changes: 2 additions & 2 deletions conf/apache-2.4/sites-available/off.conf
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Require all granted
<VirtualHost *>
DocumentRoot /srv/off/html
ServerName openfoodfacts.org
ErrorLog /srv/off/logs/error_log
CustomLog /srv/off/logs/access_log proxy
ErrorLog /srv/off/logs/error_log_${APACHE2_PORT}
CustomLog /srv/off/logs/access_log_${APACHE2_PORT} proxy
LogLevel warn
ScriptAlias /cgi/ "/srv/off/cgi/"

Expand Down
4 changes: 2 additions & 2 deletions conf/apache-2.4/sites-available/opf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Require all granted
<VirtualHost *>
DocumentRoot /srv/opf/html
ServerName openproductsfacts.org
ErrorLog /srv/opf/logs/error_log
CustomLog /srv/opf/logs/access_log proxy
ErrorLog /srv/opf/logs/error_log_${APACHE2_PORT}
CustomLog /srv/opf/logs/access_log_${APACHE2_PORT} proxy
LogLevel warn
ScriptAlias /cgi/ "/srv/opf/cgi/"

Expand Down
4 changes: 2 additions & 2 deletions conf/apache-2.4/sites-available/opff.conf
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Require all granted
<VirtualHost *>
DocumentRoot /srv/opff/html
ServerName openpetfoodfacts.org
ErrorLog /srv/opff/logs/error_log
CustomLog /srv/opff/logs/access_log combined
ErrorLog /srv/opff/logs/error_log_${APACHE2_PORT}
CustomLog /srv/opff/logs/access_log_${APACHE2_PORT} combined
LogLevel warn
ScriptAlias /cgi/ "/srv/opff/cgi/"

Expand Down
2 changes: 1 addition & 1 deletion conf/etc-default/prometheus-apache-exporter
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Set the command-line arguments to pass to the server.
ARGS='-scrape_uri http://127.0.0.1:8004/server-status/?auto'
ARGS='-scrape_uri http://127.0.0.1:8001/server-status/?auto'

#Usage of prometheus-apache-exporter:
# -host_override string
Expand Down
16 changes: 16 additions & 0 deletions conf/etc-default/prometheus-apache-priority-exporter
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Set the command-line arguments to pass to the server.
# we use a different port than the standard exporter
ARGS='-telemetry.address :9118 -scrape_uri http://127.0.0.1:8002/server-status/?auto'

#Usage of prometheus-apache-exporter:
# -host_override string
# Override for HTTP Host header; empty string for no override.
# -insecure
# Ignore server certificate if using https.
# -scrape_uri string
# URI to apache stub status page. (default
# "http://localhost/server-status/?auto")
# -telemetry.address string
# Address on which to expose metrics. (default ":9117")
# -telemetry.endpoint string
# Path under which to expose metrics. (default "/metrics")
2 changes: 1 addition & 1 deletion conf/nginx/sites-available/howmuchsugar
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Site-Name $howmuchsugar_name;
proxy_set_header X-Site-Lang $howmuchsugar_lang;
proxy_pass http://127.0.0.1:8004;
proxy_pass http://127.0.0.1:8001;
}
}
4 changes: 2 additions & 2 deletions conf/nginx/sites-available/obf
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ server {
access_log /var/log/nginx/proxy-obf-access.log proxied_requests buffer=256K flush=1s;
error_log /var/log/nginx/proxy-obf-error.log;

proxy_pass http://127.0.0.1:8002/cgi/display.pl?;
proxy_pass http://127.0.0.1:8001/cgi/display.pl?;
}

location /cgi/ {
Expand All @@ -137,7 +137,7 @@ server {
access_log /var/log/nginx/proxy-obf-access.log proxied_requests buffer=256K flush=1s;
error_log /var/log/nginx/proxy-obf-error.log;

proxy_pass http://127.0.0.1:8002;
proxy_pass http://127.0.0.1:8001;
}
}

17 changes: 15 additions & 2 deletions conf/nginx/sites-available/off
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ server {
}
}

# map to decide if we go to the priority (8002) or standard service (8001)
map $uri $apache_port {
default 8001;

# home pages
"~*/$" 8002;
# product read / write (note that nginx does not support direct utf-8)
"~*/(mountaj|m\xc9\x99hsul|\xd0\xbf\xd1\x80\xd0\xbe\xd0\xb4\xd1\x83\xd0\xba\xd1\x82|gynnyrch|produkt|product|product|product|produkto|producto|toode|produkto|produit|produto|term\xc3\xa9k|produk|\xe8\xa3\xbd\xe5\x93\x81|afaris|\xd3\xa9\xd0\xbd\xd1\x96\xd0\xbc|\xec\x83\x9d\xec\x84\xb1\xeb\xac\xbc|berhem|\xe0\xa4\x89\xe0\xa4\xa4\xe0\xa5\x8d\xe0\xa4\xaa\xe0\xa4\xbe\xe0\xa4\xa6\xe0\xa4\xa8|produk|produkt|\xe0\xa4\x89\xe0\xa4\xa4\xe0\xa5\x8d\xe0\xa4\xaa\xe0\xa4\xbe\xe0\xa4\xa6\xe0\xa4\xa8|product|product|product|produkt|produkt|produit|produto|produto|produto|\xd0\xbf\xd1\x80\xd0\xbe\xd0\xb4\xd1\x83\xd0\xba\xd1\x82|product|proizvod|produkto|\xc3\xbcr\xc3\xbcn|\xd0\xbf\xd1\x80\xd0\xbe\xd0\xb4\xd1\x83\xd0\xba\xd1\x82|\xe4\xba\xa7\xe5\x93\x81|\xe7\x94\xa2\xe5\x93\x81|\xe7\x94\xa2\xe5\x93\x81)/" 8002;
"~*/cgi/product.pl" 8002;
# product API read / write
"~*/api/v./product/" 8002;
}

# variables definitions for expiry headers are loaded from /etc/nginx/conf.d/expires-no-json-xml.conf

server {
Expand Down Expand Up @@ -148,7 +161,7 @@ server {
access_log /var/log/nginx/proxy-off-access.log proxied_requests buffer=256K flush=1s;
error_log /var/log/nginx/proxy-off-error.log;

proxy_pass http://127.0.0.1:8004/cgi/display.pl?;
proxy_pass http://127.0.0.1:$apache_port/cgi/display.pl?;
}

location /cgi/ {
Expand All @@ -159,7 +172,7 @@ server {
access_log /var/log/nginx/proxy-off-access.log proxied_requests buffer=256K flush=1s;
error_log /var/log/nginx/proxy-off-error.log;

proxy_pass http://127.0.0.1:8004;
proxy_pass http://127.0.0.1:$apache_port;
}
}

4 changes: 2 additions & 2 deletions conf/nginx/sites-available/off-pro
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ server {
access_log /var/log/nginx/proxy-off-access.log proxied_requests buffer=256K flush=1s;
error_log /var/log/nginx/proxy-off-error.log;

proxy_pass http://127.0.0.1:8014/cgi/display.pl?;
proxy_pass http://127.0.0.1:8001/cgi/display.pl?;
}

location /cgi/ {
Expand All @@ -105,7 +105,7 @@ server {
access_log /var/log/nginx/proxy-off-access.log proxied_requests buffer=256K flush=1s;
error_log /var/log/nginx/proxy-off-error.log;

proxy_pass http://127.0.0.1:8014;
proxy_pass http://127.0.0.1:8001;
}

}
Expand Down
4 changes: 2 additions & 2 deletions conf/nginx/sites-available/opf
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ server {
access_log /var/log/nginx/proxy-opf-access.log proxied_requests buffer=256K flush=1s;
error_log /var/log/nginx/proxy-opf-error.log;

proxy_pass http://127.0.0.1:8003/cgi/display.pl?;
proxy_pass http://127.0.0.1:8001/cgi/display.pl?;
}

location /cgi/ {
Expand All @@ -136,7 +136,7 @@ server {
access_log /var/log/nginx/proxy-opf-access.log proxied_requests buffer=256K flush=1s;
error_log /var/log/nginx/proxy-opf-error.log;

proxy_pass http://127.0.0.1:8003;
proxy_pass http://127.0.0.1:8001;
}
}

Loading

0 comments on commit b720f67

Please sign in to comment.