midrange.com code scratchpad |
Name:
revproxy_check_internal_host
|
Scriptlanguage:
Plain Text
|
Tabwidth:
4
|
Date:
01/05/2022 08:17:46 pm
|
IP:
Logged
|
|
Description:
This snippet uses netcat to look if port 8081 on my internal host nibbler.pocnet.net is available. Dependent on the return value of netcat, the proxy or local configuration is linked to the current directory. If a change has been made (derived by the file command), apache is reloaded. So, multiple blocks of "if echo" do trigger a reload only once in any case.
The path to cd to in line 3 is dependent on the Linux distribution used. The example is for debian based systems.
|
Code:
- #!/bin/sh
-
- cd /etc/apache2/sites-enabled || exit 1
-
- CHANGED=0
-
- if echo "GET /" |nc -w 3 nibbler.pocnet.net 8081 &> /dev/null; then
- if ! file -b www.pocnet.net.conf |fgrep -q nibbler; then
- ln -sf ../sites-available/www.pocnet.net-nibbler.conf www.pocnet.net.conf
- CHANGED=1
- fi
- else
- if ! file -b www.pocnet.net.conf |fgrep -q local; then
- ln -sf ../sites-available/www.pocnet.net-local.conf www.pocnet.net.conf
- CHANGED=1
- fi
- fi
-
- # Reload config if appropriate
- if [ ${CHANGED} -eq 1 ]; then
- if /usr/sbin/apache2ctl configtest 2>/dev/null; then
- /etc/init.d/apache2 reload >/dev/null
- else
- echo "$0 has not reloaded Apache due to config errors. Please fix."
- exit 1
- fi
- fi
-
- # -EOF-
-
|
|
|