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

chore: have two apache servers #10766

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -30,4 +31,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
7 changes: 0 additions & 7 deletions conf/apache-2.4/off-ports.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
19 changes: 17 additions & 2 deletions conf/nginx/sites-available/off
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ server {
}
}

# map to decide if we go to the main (8004) or secondary service (8805)
stephanegigandet marked this conversation as resolved.
Show resolved Hide resolved
map $request_method$uri $apache_port {
default 8005;

# home pages
"~*GET/$" 8004;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should handle also the HEAD and OPTIONS methods (used by browsers for CORS)

# product read / write
"~*GET/(mountaj|məhsul|продукт|gynnyrch|produkt|product|product|product|produkto|producto|toode|produkto|produit|produto|termék|produk|製品|afaris|өнім|생성물|berhem|उत्पादन|produk|produkt|उत्पादन|product|product|product|produkt|produkt|produit|produto|produto|produto|продукт|product|proizvod|produkto|ürün|продукт|产品|產品|產品)/" 8004;
"~*GET/cgi/product.pl" 8004;
"~*POST/cgi/product.pl" 8004;
# product API read / write
"~*GET/api/v./product/" 8004;
"~*POST/api/v./product/" 8004;
Copy link
Contributor

Choose a reason for hiding this comment

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

For API v3, we use the PATCH method too

}

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

server {
Expand Down Expand Up @@ -118,7 +133,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 @@ -129,7 +144,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;
}
}

36 changes: 36 additions & 0 deletions conf/off-secondary-log.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
log4perl.rootLogger=ERROR, LOGFILE
log4perl.logger.mongodb=INFO, MONGODB_LOGFILE
log4perl.logger.ratelimiter=INFO, RATELIMITER_LOGFILE
log4perl.logger.requeststats=INFO, REQUESTSTATS_LOGFILE

log4perl.PatternLayout.cspec.S = sub { my $context = Log::Log4perl::MDC->get_context; use Data::Dumper (); local $Data::Dumper::Indent = 0; local $Data::Dumper::Terse = 1; local $Data::Dumper::Sortkeys = 1; local $Data::Dumper::Quotekeys = 0; local $Data::Dumper::Deparse = 1; my $str = Data::Dumper::Dumper($context); $str =~ s/[\n\r]/ /g; return $str; }
log4perl.PatternLayout.cspec.J = sub { my $context = Log::Log4perl::MDC->get_context; use JSON::MaybeXS; my $json_utf8 = JSON::MaybeXS->new->utf8(1)->allow_nonref->canonical; my $str = $json_utf8->encode($context); return $str; }

log4perl.appender.LOGFILE=Log::Log4perl::Appender::File
log4perl.appender.LOGFILE.filename=/srv/off/logs/log4perl-2.log
log4perl.appender.LOGFILE.mode=append
# note: autoflush=0 results in multiple log entries being mixed (probably because there are several Apache processes writing to the same file)
log4perl.appender.LOGFILE.autoflush=1
log4perl.appender.LOGFILE.layout=PatternLayout
log4perl.appender.LOGFILE.layout.ConversionPattern=[%d] %F %L %c %S %m{chomp}%n

log4perl.appender.MONGODB_LOGFILE=Log::Log4perl::Appender::File
log4perl.appender.MONGODB_LOGFILE.filename=/srv/off/logs/mongodb_log4perl-2.log
log4perl.appender.MONGODB_LOGFILE.mode=append
log4perl.appender.MONGODB_LOGFILE.autoflush=1
log4perl.appender.MONGODB_LOGFILE.layout=PatternLayout
log4perl.appender.MONGODB_LOGFILE.layout.ConversionPattern=[%d] %F %L %c %S %m{chomp}%n

log4perl.appender.RATELIMITER_LOGFILE=Log::Log4perl::Appender::File
log4perl.appender.RATELIMITER_LOGFILE.filename=/srv/off/logs/ratelimiter_log4perl-2.log
log4perl.appender.RATELIMITER_LOGFILE.mode=append
log4perl.appender.RATELIMITER_LOGFILE.autoflush=1
log4perl.appender.RATELIMITER_LOGFILE.layout=PatternLayout
log4perl.appender.RATELIMITER_LOGFILE.layout.ConversionPattern=[%d] %F %L %c %S %m{chomp}%n

log4perl.appender.REQUESTSTATS_LOGFILE=Log::Log4perl::Appender::File
log4perl.appender.REQUESTSTATS_LOGFILE.filename=/srv/off/logs/requeststats_log4perl-2.log
log4perl.appender.REQUESTSTATS_LOGFILE.mode=append
log4perl.appender.REQUESTSTATS_LOGFILE.autoflush=1
log4perl.appender.REQUESTSTATS_LOGFILE.layout=PatternLayout
log4perl.appender.REQUESTSTATS_LOGFILE.layout.ConversionPattern=%J %n
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ JobRunningTimeoutSec=600
# Apache needs some environment variables like PRODUCT_OPENER_FLAVOR_SHORT
# %l is the short host name (e.g. off, obf, off-pro)
EnvironmentFile=/srv/%l/env/env.%l
# we also have a variation on startup option (like setting port number) by instance type
# it can override variables from the previous file
EnvironmentFile=-/srv/%l/env/env.%l.%i
TimeoutStartSec=600
Restart=always
3 changes: 3 additions & 0 deletions env/env.obf.main
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This is used by ports.conf in apache2
APACHE_ARGUMENTS=-D APACHE2_PORT=8002
Copy link
Contributor

Choose a reason for hiding this comment

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

While we are changing those files, could we use the same port numbers for all flavors? We don't run them in the same server anymore, so we could just use 8001 (and 8002 if there's a fast track Apache) for all flavors.

LOG4PERL_CONF=/srv/obf/conf/obf-log.conf
3 changes: 3 additions & 0 deletions env/env.off-pro.main
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This is used by ports.conf in apache2
APACHE_ARGUMENTS=-D APACHE2_PORT=8014
LOG4PERL_CONF=/srv/off-pro/conf/off-pro-log.conf
3 changes: 3 additions & 0 deletions env/env.off.main
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This is used by ports.conf in apache2
APACHE_ARGUMENTS=-D APACHE2_PORT=8004
LOG4PERL_CONF=/srv/off/conf/off-log.conf
3 changes: 3 additions & 0 deletions env/env.off.secondary
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This is used by ports.conf in apache2
APACHE_ARGUMENTS=-D APACHE2_PORT=8005
LOG4PERL_CONF=/srv/off/conf/off-secondary-log.conf
3 changes: 3 additions & 0 deletions env/env.opf.main
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This is used by ports.conf in apache2
APACHE_ARGUMENTS=-D APACHE2_PORT=8003
LOG4PERL_CONF=/srv/opf/conf/opf-log.conf
3 changes: 3 additions & 0 deletions env/env.opff.main
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This is used by ports.conf in apache2
APACHE_ARGUMENTS=-D APACHE2_PORT=8001
LOG4PERL_CONF=/srv/opff/conf/opff-log.conf
3 changes: 2 additions & 1 deletion lib/startup_apache2.pl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@

use Log::Any qw($log);
use Log::Log4perl;
Log::Log4perl->init("$conf_root/log.conf"); # Init log4perl from a config file.
# Init log4perl from a config file
Log::Log4perl->init(ENV{LOG4PERL_CONF} // "$conf_root/log.conf");
use Log::Any::Adapter;
Log::Any::Adapter->set('Log4perl'); # Send all logs to Log::Log4perl

Expand Down
Loading