blob: 771a7d7ec0d510ce2564d4477e55fad57897f13c [file] [log] [blame]
Sean Daguee263c822014-12-05 14:25:28 -05001#!/bin/bash
2#
zhang-hared98a5d02013-06-21 18:18:02 +08003# lib/apache
4# Functions to control configuration and operation of apache web server
5
6# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01007#
8# - ``functions`` file
Dean Troyerd8864fe2014-02-17 11:00:42 -06009# - ``STACK_USER`` must be defined
10#
Stephan Renatuse578eff2013-11-19 13:31:04 +010011# lib/apache exports the following functions:
12#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010013# - install_apache_wsgi
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +000014# - apache_site_config_for
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010015# - enable_apache_site
16# - disable_apache_site
17# - start_apache_server
18# - stop_apache_server
19# - restart_apache_server
zhang-hared98a5d02013-06-21 18:18:02 +080020
21# Save trace setting
Ian Wienand523f4882015-10-13 11:03:03 +110022_XTRACE_LIB_APACHE=$(set +o | grep xtrace)
zhang-hared98a5d02013-06-21 18:18:02 +080023set +o xtrace
24
25# Allow overriding the default Apache user and group, default to
26# current user and his default group.
Stephan Renatuse578eff2013-11-19 13:31:04 +010027APACHE_USER=${APACHE_USER:-$STACK_USER}
zhang-hared98a5d02013-06-21 18:18:02 +080028APACHE_GROUP=${APACHE_GROUP:-$(id -gn $APACHE_USER)}
29
Brian Haley7943a922022-03-14 13:53:41 -040030APACHE_LOCAL_HOST=$SERVICE_LOCAL_HOST
31if [[ "$SERVICE_IP_VERSION" == 6 ]]; then
32 APACHE_LOCAL_HOST=[$APACHE_LOCAL_HOST]
33fi
34
zhang-hared98a5d02013-06-21 18:18:02 +080035
36# Set up apache name and configuration directory
Clark Boylancfb9f052016-11-29 10:43:05 -080037# Note that APACHE_CONF_DIR is really more accurately apache's vhost
38# configuration dir but we can't just change this because public interfaces.
zhang-hared98a5d02013-06-21 18:18:02 +080039if is_ubuntu; then
40 APACHE_NAME=apache2
Dean Troyer444a8d52014-06-06 16:36:52 -050041 APACHE_CONF_DIR=${APACHE_CONF_DIR:-/etc/$APACHE_NAME/sites-available}
Clark Boylancfb9f052016-11-29 10:43:05 -080042 APACHE_SETTINGS_DIR=${APACHE_SETTINGS_DIR:-/etc/$APACHE_NAME/conf-enabled}
zhang-hared98a5d02013-06-21 18:18:02 +080043elif is_fedora; then
44 APACHE_NAME=httpd
Dean Troyer444a8d52014-06-06 16:36:52 -050045 APACHE_CONF_DIR=${APACHE_CONF_DIR:-/etc/$APACHE_NAME/conf.d}
Clark Boylancfb9f052016-11-29 10:43:05 -080046 APACHE_SETTINGS_DIR=${APACHE_SETTINGS_DIR:-/etc/$APACHE_NAME/conf.d}
zhang-hared98a5d02013-06-21 18:18:02 +080047elif is_suse; then
48 APACHE_NAME=apache2
Dean Troyer444a8d52014-06-06 16:36:52 -050049 APACHE_CONF_DIR=${APACHE_CONF_DIR:-/etc/$APACHE_NAME/vhosts.d}
Clark Boylancfb9f052016-11-29 10:43:05 -080050 APACHE_SETTINGS_DIR=${APACHE_SETTINGS_DIR:-/etc/$APACHE_NAME/conf.d}
zhang-hared98a5d02013-06-21 18:18:02 +080051fi
Clark Boylan66ce5c22016-10-05 12:11:05 -070052APACHE_LOG_DIR="/var/log/${APACHE_NAME}"
zhang-hared98a5d02013-06-21 18:18:02 +080053
54# Functions
55# ---------
Gregory Haynes4b49e402016-08-31 18:19:51 -070056
57# Enable apache mod and restart apache if it isn't already enabled.
58function enable_apache_mod {
59 local mod=$1
60 # Apache installation, because we mark it NOPRIME
Clark Boylan35649ae2017-05-27 17:52:55 -070061 if is_ubuntu; then
62 # Skip mod_version as it is not a valid mod to enable
63 # on debuntu, instead it is built in.
64 if [[ "$mod" != "version" ]] && ! a2query -m $mod ; then
65 sudo a2enmod $mod
66 restart_apache_server
67 fi
68 elif is_suse; then
69 if ! a2enmod -q $mod ; then
Gregory Haynes4b49e402016-08-31 18:19:51 -070070 sudo a2enmod $mod
71 restart_apache_server
72 fi
73 elif is_fedora; then
74 # pass
75 true
76 else
77 exit_distro_not_supported "apache enable mod"
78 fi
79}
80
Sean Dague604e5982017-04-13 13:28:12 -040081# NOTE(sdague): Install uwsgi including apache module, we need to get
82# to 2.0.6+ to get a working mod_proxy_uwsgi. We can probably build a
83# check for that and do it differently for different platforms.
84function install_apache_uwsgi {
85 local apxs="apxs2"
86 if is_fedora; then
87 apxs="apxs"
88 fi
89
Ian Wienand2d903562018-05-03 10:51:30 +100090 if is_ubuntu; then
Dr. Jens Harbott34800932020-02-13 09:38:35 +000091 local pkg_list="uwsgi uwsgi-plugin-python3 libapache2-mod-proxy-uwsgi"
Dr. Jens Harbott34800932020-02-13 09:38:35 +000092 install_package ${pkg_list}
Ian Wienand343e3512022-02-03 11:19:08 +110093 # NOTE(ianw) 2022-02-03 : Fedora 35 needs to skip this and fall
94 # into the install-from-source because the upstream packages
95 # didn't fix Python 3.10 compatibility before release. Should be
96 # fixed in uwsgi 4.9.0; can remove this when packages available
97 # or we drop this release
wangxiyuan6440c6d2022-08-05 14:18:13 +080098 elif is_fedora && ! is_openeuler && ! [[ $DISTRO =~ f36 ]]; then
Ian Wienand2d903562018-05-03 10:51:30 +100099 # Note httpd comes with mod_proxy_uwsgi and it is loaded by
100 # default; the mod_proxy_uwsgi package actually conflicts now.
101 # See:
102 # https://bugzilla.redhat.com/show_bug.cgi?id=1574335
103 #
104 # Thus there is nothing else to do after this install
105 install_package uwsgi \
106 uwsgi-plugin-python3
Andreas Jaeger10c3ffd2020-06-15 10:03:42 +0200107 elif [[ $os_VENDOR =~ openSUSE ]]; then
108 install_package uwsgi \
109 uwsgi-python3 \
110 apache2-mod_uwsgi
Ian Wienand2d903562018-05-03 10:51:30 +1000111 else
Federico Ressic2c2b6b2020-06-15 12:48:38 +0200112 # Compile uwsgi from source.
Ian Wienand2d903562018-05-03 10:51:30 +1000113 local dir
114 dir=$(mktemp -d)
115 pushd $dir
116 pip_install uwsgi
117 pip download uwsgi -c $REQUIREMENTS_DIR/upper-constraints.txt
118 local uwsgi
119 uwsgi=$(ls uwsgi*)
120 tar xvf $uwsgi
121 cd uwsgi*/apache2
122 sudo $apxs -i -c mod_proxy_uwsgi.c
123 popd
124 # delete the temp directory
125 sudo rm -rf $dir
Ian Wienand2d903562018-05-03 10:51:30 +1000126 fi
Sean Dague604e5982017-04-13 13:28:12 -0400127
Clark Boylan35649ae2017-05-27 17:52:55 -0700128 if is_ubuntu || is_suse ; then
Sean Dague604e5982017-04-13 13:28:12 -0400129 # we've got to enable proxy and proxy_uwsgi for this to work
130 sudo a2enmod proxy
131 sudo a2enmod proxy_uwsgi
132 elif is_fedora; then
133 # redhat is missing a nice way to turn on/off modules
134 echo "LoadModule proxy_uwsgi_module modules/mod_proxy_uwsgi.so" \
135 | sudo tee /etc/httpd/conf.modules.d/02-proxy-uwsgi.conf
136 fi
137 restart_apache_server
138}
139
zhang-hared98a5d02013-06-21 18:18:02 +0800140# install_apache_wsgi() - Install Apache server and wsgi module
Ian Wienandaee18c72014-02-21 15:35:08 +1100141function install_apache_wsgi {
zhang-hared98a5d02013-06-21 18:18:02 +0800142 # Apache installation, because we mark it NOPRIME
143 if is_ubuntu; then
144 # Install apache2, which is NOPRIME'd
Davanum Srinivasafa8a002016-12-19 09:51:01 -0500145 install_package apache2
Jens Harbottd7a82f42020-06-23 10:21:09 +0200146 if is_package_installed libapache2-mod-wsgi; then
147 uninstall_package libapache2-mod-wsgi
Davanum Srinivasafa8a002016-12-19 09:51:01 -0500148 fi
Jens Harbottd7a82f42020-06-23 10:21:09 +0200149 install_package libapache2-mod-wsgi-py3
zhang-hared98a5d02013-06-21 18:18:02 +0800150 elif is_fedora; then
151 sudo rm -f /etc/httpd/conf.d/000-*
Hirotaka Wakabayashi1e265082020-07-02 06:19:21 +0000152 install_package httpd python3-mod_wsgi
Sean Mooney80c3ffe2023-03-27 20:56:20 +0000153 # rpm distros dont enable httpd by default so enable it to support reboots.
154 sudo systemctl enable httpd
Ian Wienand41e6e122017-08-08 15:06:26 +1000155 # For consistency with Ubuntu, switch to the worker mpm, as
Attila Fazekas9fd38e72017-12-11 12:20:25 +0100156 # the default is event
Ian Wienand41e6e122017-08-08 15:06:26 +1000157 sudo sed -i '/mod_mpm_prefork.so/s/^/#/g' /etc/httpd/conf.modules.d/00-mpm.conf
Attila Fazekas9fd38e72017-12-11 12:20:25 +0100158 sudo sed -i '/mod_mpm_event.so/s/^/#/g' /etc/httpd/conf.modules.d/00-mpm.conf
Ian Wienand41e6e122017-08-08 15:06:26 +1000159 sudo sed -i '/mod_mpm_worker.so/s/^#//g' /etc/httpd/conf.modules.d/00-mpm.conf
zhang-hared98a5d02013-06-21 18:18:02 +0800160 elif is_suse; then
161 install_package apache2 apache2-mod_wsgi
162 else
Gregory Haynes4b49e402016-08-31 18:19:51 -0700163 exit_distro_not_supported "apache wsgi installation"
zhang-hared98a5d02013-06-21 18:18:02 +0800164 fi
Gregory Haynes4b49e402016-08-31 18:19:51 -0700165 # WSGI isn't enabled by default, enable it
166 enable_apache_mod wsgi
Morgan Fainbergd074dc72014-06-24 21:33:39 -0700167}
168
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000169# apache_site_config_for() - The filename of the site's configuration file.
170# This function uses the global variables APACHE_NAME and APACHE_CONF_DIR.
171#
Sean Dague8f8b2742017-04-13 09:34:12 -0400172# On Ubuntu 14.04+, the site configuration file must have a .conf suffix for a2ensite and a2dissite to
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000173# recognise it. a2ensite and a2dissite ignore the .conf suffix used as parameter. The default sites'
174# files are 000-default.conf and default-ssl.conf.
175#
Ralf Haferkamp633a1292014-06-16 14:10:05 +0200176# On Fedora and openSUSE, any file in /etc/httpd/conf.d/ whose name ends with .conf is enabled.
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000177#
178# On RHEL and CentOS, things should hopefully work as in Fedora.
179#
180# The table below summarizes what should happen on each distribution:
181# +----------------------+--------------------+--------------------------+--------------------------+
182# | Distribution | File name | Site enabling command | Site disabling command |
183# +----------------------+--------------------+--------------------------+--------------------------+
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000184# | Ubuntu 14.04 | site.conf | a2ensite site | a2dissite site |
185# | Fedora, RHEL, CentOS | site.conf.disabled | mv site.conf{.disabled,} | mv site.conf{,.disabled} |
186# +----------------------+--------------------+--------------------------+--------------------------+
187function apache_site_config_for {
188 local site=$@
189 if is_ubuntu; then
Sean Dague8f8b2742017-04-13 09:34:12 -0400190 # Ubuntu 14.04 - Apache 2.4
191 echo $APACHE_CONF_DIR/${site}.conf
Ralf Haferkamp633a1292014-06-16 14:10:05 +0200192 elif is_fedora || is_suse; then
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000193 # fedora conf.d is only imported if it ends with .conf so this is approx the same
Dean Troyer444a8d52014-06-06 16:36:52 -0500194 local enabled_site_file="$APACHE_CONF_DIR/${site}.conf"
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000195 if [ -f $enabled_site_file ]; then
196 echo ${enabled_site_file}
197 else
198 echo ${enabled_site_file}.disabled
199 fi
200 fi
201}
202
Jamie Lennox54707012013-09-17 12:07:48 +1000203# enable_apache_site() - Enable a particular apache site
Ian Wienandaee18c72014-02-21 15:35:08 +1100204function enable_apache_site {
Jamie Lennox54707012013-09-17 12:07:48 +1000205 local site=$@
Clark Boylan35649ae2017-05-27 17:52:55 -0700206 # Many of our sites use mod version. Just enable it.
207 enable_apache_mod version
Jamie Lennox54707012013-09-17 12:07:48 +1000208 if is_ubuntu; then
209 sudo a2ensite ${site}
Ralf Haferkamp633a1292014-06-16 14:10:05 +0200210 elif is_fedora || is_suse; then
Dean Troyer444a8d52014-06-06 16:36:52 -0500211 local enabled_site_file="$APACHE_CONF_DIR/${site}.conf"
212 # Do nothing if site already enabled or no site config exists
213 if [[ -f ${enabled_site_file}.disabled ]] && [[ ! -f ${enabled_site_file} ]]; then
214 sudo mv ${enabled_site_file}.disabled ${enabled_site_file}
215 fi
Jamie Lennox54707012013-09-17 12:07:48 +1000216 fi
217}
218
219# disable_apache_site() - Disable a particular apache site
Ian Wienandaee18c72014-02-21 15:35:08 +1100220function disable_apache_site {
Jamie Lennox54707012013-09-17 12:07:48 +1000221 local site=$@
222 if is_ubuntu; then
Chris Dent2fcdaac2017-04-18 16:54:12 +0100223 sudo a2dissite ${site} || true
Ralf Haferkamp633a1292014-06-16 14:10:05 +0200224 elif is_fedora || is_suse; then
Dean Troyer444a8d52014-06-06 16:36:52 -0500225 local enabled_site_file="$APACHE_CONF_DIR/${site}.conf"
226 # Do nothing if no site config exists
227 if [[ -f ${enabled_site_file} ]]; then
228 sudo mv ${enabled_site_file} ${enabled_site_file}.disabled
229 fi
Jamie Lennox54707012013-09-17 12:07:48 +1000230 fi
231}
232
zhang-hared98a5d02013-06-21 18:18:02 +0800233# start_apache_server() - Start running apache server
Ian Wienandaee18c72014-02-21 15:35:08 +1100234function start_apache_server {
zhang-hared98a5d02013-06-21 18:18:02 +0800235 start_service $APACHE_NAME
236}
237
238# stop_apache_server() - Stop running apache server
Ian Wienandaee18c72014-02-21 15:35:08 +1100239function stop_apache_server {
zhang-hared98a5d02013-06-21 18:18:02 +0800240 if [ -n "$APACHE_NAME" ]; then
241 stop_service $APACHE_NAME
242 else
243 exit_distro_not_supported "apache configuration"
244 fi
245}
246
247# restart_apache_server
Ian Wienandaee18c72014-02-21 15:35:08 +1100248function restart_apache_server {
Morgan Fainberg2df00462014-07-15 11:06:36 -0700249 # Apache can be slow to stop, doing an explicit stop, sleep, start helps
250 # to mitigate issues where apache will claim a port it's listening on is
251 # still in use and fail to start.
Sean Dague2b85cf02017-04-13 09:02:14 -0400252 restart_service $APACHE_NAME
zhang-hared98a5d02013-06-21 18:18:02 +0800253}
254
Sean Dague2f8c88e2017-04-13 09:08:39 -0400255function write_uwsgi_config {
256 local file=$1
257 local wsgi=$2
258 local url=$3
259 local http=$4
260 local name=""
261 name=$(basename $wsgi)
rabiaa26baa2017-04-20 10:55:16 +0530262
263 # create a home for the sockets; note don't use /tmp -- apache has
264 # a private view of it on some platforms.
265 local socket_dir='/var/run/uwsgi'
Kirill Zaitsevd0db62a2017-05-26 19:02:52 +0300266
267 # /var/run will be empty on ubuntu after reboot, so we can use systemd-temptiles
268 # to automatically create $socket_dir.
269 sudo mkdir -p /etc/tmpfiles.d/
270 echo "d $socket_dir 0755 $STACK_USER root" | sudo tee /etc/tmpfiles.d/uwsgi.conf
271 sudo systemd-tmpfiles --create /etc/tmpfiles.d/uwsgi.conf
272
rabiaa26baa2017-04-20 10:55:16 +0530273 local socket="$socket_dir/${name}.socket"
Sean Dague2f8c88e2017-04-13 09:08:39 -0400274
275 # always cleanup given that we are using iniset here
276 rm -rf $file
277 iniset "$file" uwsgi wsgi-file "$wsgi"
Sean Dague2f8c88e2017-04-13 09:08:39 -0400278 iniset "$file" uwsgi processes $API_WORKERS
279 # This is running standalone
280 iniset "$file" uwsgi master true
281 # Set die-on-term & exit-on-reload so that uwsgi shuts down
282 iniset "$file" uwsgi die-on-term true
Dinesh Bhoref60f2b2017-09-05 14:40:32 +0530283 iniset "$file" uwsgi exit-on-reload false
Matthew Treinish477a9622017-08-04 11:09:26 -0400284 # Set worker-reload-mercy so that worker will not exit till the time
285 # configured after graceful shutdown
286 iniset "$file" uwsgi worker-reload-mercy $WORKER_TIMEOUT
Sean Dague2f8c88e2017-04-13 09:08:39 -0400287 iniset "$file" uwsgi enable-threads true
Kevin Zhao7880ba62021-03-31 04:58:28 +0000288 iniset "$file" uwsgi plugins http,python3
Sean Dague2f8c88e2017-04-13 09:08:39 -0400289 # uwsgi recommends this to prevent thundering herd on accept.
290 iniset "$file" uwsgi thunder-lock true
Matthew Treinish477a9622017-08-04 11:09:26 -0400291 # Set hook to trigger graceful shutdown on SIGTERM
292 iniset "$file" uwsgi hook-master-start "unix_signal:15 gracefully_kill_them_all"
Sean Dague2f8c88e2017-04-13 09:08:39 -0400293 # Override the default size for headers from the 4k default.
294 iniset "$file" uwsgi buffer-size 65535
295 # Make sure the client doesn't try to re-use the connection.
296 iniset "$file" uwsgi add-header "Connection: close"
297 # This ensures that file descriptors aren't shared between processes.
298 iniset "$file" uwsgi lazy-apps true
Sean Dague2f8c88e2017-04-13 09:08:39 -0400299
300 # If we said bind directly to http, then do that and don't start the apache proxy
301 if [[ -n "$http" ]]; then
302 iniset "$file" uwsgi http $http
303 else
304 local apache_conf=""
305 apache_conf=$(apache_site_config_for $name)
Chris Dentb90bb1a2017-04-18 16:30:14 +0000306 iniset "$file" uwsgi socket "$socket"
307 iniset "$file" uwsgi chmod-socket 666
Jens Harbott56e75e42021-09-28 20:02:34 +0200308 echo "ProxyPass \"${url}\" \"unix:${socket}|uwsgi://uwsgi-uds-${name}\" retry=0 " | sudo tee -a $apache_conf
Sean Dague2f8c88e2017-04-13 09:08:39 -0400309 enable_apache_site $name
Ian Wienandf6a2d2c2017-04-26 10:50:29 +1000310 restart_apache_server
Sean Dague2f8c88e2017-04-13 09:08:39 -0400311 fi
312}
313
Matthew Treinish1fa65362017-06-23 22:32:37 +0000314# For services using chunked encoding, the only services known to use this
315# currently are Glance and Swift, we need to use an http proxy instead of
316# mod_proxy_uwsgi because the chunked encoding gets dropped. See:
317# https://github.com/unbit/uwsgi/issues/1540 You can workaround this on python2
318# but that involves having apache buffer the request before sending it to
Jeremy Liu2f7df512017-07-12 10:09:48 +0800319# uwsgi.
Matthew Treinish1fa65362017-06-23 22:32:37 +0000320function write_local_uwsgi_http_config {
321 local file=$1
322 local wsgi=$2
323 local url=$3
324 name=$(basename $wsgi)
325
326 # create a home for the sockets; note don't use /tmp -- apache has
327 # a private view of it on some platforms.
328
329 # always cleanup given that we are using iniset here
330 rm -rf $file
331 iniset "$file" uwsgi wsgi-file "$wsgi"
332 port=$(get_random_port)
Brian Haley7943a922022-03-14 13:53:41 -0400333 iniset "$file" uwsgi http-socket "$APACHE_LOCAL_HOST:$port"
Matthew Treinish1fa65362017-06-23 22:32:37 +0000334 iniset "$file" uwsgi processes $API_WORKERS
335 # This is running standalone
336 iniset "$file" uwsgi master true
337 # Set die-on-term & exit-on-reload so that uwsgi shuts down
338 iniset "$file" uwsgi die-on-term true
Dinesh Bhoref60f2b2017-09-05 14:40:32 +0530339 iniset "$file" uwsgi exit-on-reload false
Matthew Treinish1fa65362017-06-23 22:32:37 +0000340 iniset "$file" uwsgi enable-threads true
Kevin Zhao7880ba62021-03-31 04:58:28 +0000341 iniset "$file" uwsgi plugins http,python3
Matthew Treinish1fa65362017-06-23 22:32:37 +0000342 # uwsgi recommends this to prevent thundering herd on accept.
343 iniset "$file" uwsgi thunder-lock true
Matthew Treinish477a9622017-08-04 11:09:26 -0400344 # Set hook to trigger graceful shutdown on SIGTERM
345 iniset "$file" uwsgi hook-master-start "unix_signal:15 gracefully_kill_them_all"
346 # Set worker-reload-mercy so that worker will not exit till the time
347 # configured after graceful shutdown
348 iniset "$file" uwsgi worker-reload-mercy $WORKER_TIMEOUT
Matthew Treinish1fa65362017-06-23 22:32:37 +0000349 # Override the default size for headers from the 4k default.
350 iniset "$file" uwsgi buffer-size 65535
351 # Make sure the client doesn't try to re-use the connection.
352 iniset "$file" uwsgi add-header "Connection: close"
353 # This ensures that file descriptors aren't shared between processes.
354 iniset "$file" uwsgi lazy-apps true
355 iniset "$file" uwsgi chmod-socket 666
356 iniset "$file" uwsgi http-raw-body true
357 iniset "$file" uwsgi http-chunked-input true
358 iniset "$file" uwsgi http-auto-chunked true
Matthew Treinish82d06102017-06-28 17:42:31 -0400359 iniset "$file" uwsgi http-keepalive false
Matthew Treinishb79531a2017-06-30 12:10:06 -0400360 # Increase socket timeout for slow chunked uploads
361 iniset "$file" uwsgi socket-timeout 30
Matthew Treinish1fa65362017-06-23 22:32:37 +0000362
363 enable_apache_mod proxy
364 enable_apache_mod proxy_http
365 local apache_conf=""
366 apache_conf=$(apache_site_config_for $name)
367 echo "KeepAlive Off" | sudo tee $apache_conf
Matthew Treinisha3488d52017-08-10 14:55:15 -0400368 echo "SetEnv proxy-sendchunked 1" | sudo tee -a $apache_conf
Brian Haley7943a922022-03-14 13:53:41 -0400369 echo "ProxyPass \"${url}\" \"http://$APACHE_LOCAL_HOST:$port\" retry=0 " | sudo tee -a $apache_conf
Matthew Treinish1fa65362017-06-23 22:32:37 +0000370 enable_apache_site $name
371 restart_apache_server
372}
373
Dan Smith09eea0b2020-07-09 08:31:51 -0700374# Write a straight-through proxy for a service that runs locally and just needs
375# to be reachable via the main http proxy at $loc
376function write_local_proxy_http_config {
377 local name=$1
378 local url=$2
379 local loc=$3
380 local apache_conf
381 apache_conf=$(apache_site_config_for $name)
382
383 enable_apache_mod proxy
384 enable_apache_mod proxy_http
385
386 echo "KeepAlive Off" | sudo tee $apache_conf
387 echo "SetEnv proxy-sendchunked 1" | sudo tee -a $apache_conf
388 echo "ProxyPass \"${loc}\" \"$url\" retry=0 " | sudo tee -a $apache_conf
389 enable_apache_site $name
390 restart_apache_server
391}
392
Sean Dague2f8c88e2017-04-13 09:08:39 -0400393function remove_uwsgi_config {
394 local file=$1
395 local wsgi=$2
396 local name=""
397 name=$(basename $wsgi)
398
399 rm -rf $file
400 disable_apache_site $name
401}
402
zhang-hared98a5d02013-06-21 18:18:02 +0800403# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +1100404$_XTRACE_LIB_APACHE
zhang-hared98a5d02013-06-21 18:18:02 +0800405
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100406# Tell emacs to use shell-script-mode
407## Local variables:
408## mode: shell-script
409## End: