Skip to content

Commit

Permalink
Add watchdog for wireproxy
Browse files Browse the repository at this point in the history
  • Loading branch information
waybackarchiver committed Jun 9, 2023
1 parent 4d380f4 commit 636427b
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
# vendor/

/bin

*.conf
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ RUN set -o pipefail && \
supervisor \
ca-certificates \
py3-setuptools \
curl \
libcap \
you-get \
rtmpdump \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ reduce the cost of running the `wayback` service, and providing additional anony

#### WAYBACK_ARGS

wayback command-line arguments.
wayback command-line arguments, e.g. `-d web -d telegram`.

#### WAYBACK_CONFIGURATIONS

Expand Down
4 changes: 4 additions & 0 deletions render.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ services:
# see https://github.com/wabarc/wayback/blob/main/wayback.conf for more details.
- key: WAYBACK_CONFIGURATIONS
sync: false
- key: PORT
value: '8964'
- key: PROXY_SERVER
value: ''
- key: WIREPROXY_CONF
value: ''
54 changes: 47 additions & 7 deletions wireproxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,53 @@
#
# Perform wireproxy

# check dependency
command -v wireproxy > /dev/null || { echo "wireproxy is not installed in this system" 1>&2; exit 0; }
printenv WIREPROXY_CONF > /dev/null || { echo "environment variable WIREPROXY_CONF is not found in this system" 1>&2; exit 0; }
interval=60
workdir=/wayback
debug="${DEBUG:-}"
if [ "$debug" = "true" ]; then
set -x
workdir=.
fi
config="${workdir}/wg0.conf"

homedir=/wayback
config="${homedir}/wireproxy.conf"
restart() {
pkill wireproxy

printenv WIREPROXY_CONF > "${config}"
# Run wireproxy with silent mode in backgound
wireproxy --daemon --silent --config $config
sleep 3
}

wireproxy -c "${config}"
watch() {
endpoint='https://cp.cloudflare.com'
proxy="${PROXY_SERVER}"
code=204
timeout=5
while :; do
if [ -n "${PROXY_SERVER}" ]; then
echo 'Running wireproxy watchdog...'
resp=$(curl -sf --write-out '%{http_code}' --max-time $timeout --proxy "${proxy}" "${endpoint}")
if [ "${resp}" != "${code}" ]; then
echo 'Restarting wireproxy...'
restart
fi
fi
sleep $interval
done
}

main() {
# check dependency
command -v wireproxy > /dev/null || { echo "wireproxy is not installed in this system" 1>&2; exit 0; }

if [ "${debug}" != "true" ]; then
printenv WIREPROXY_CONF > /dev/null || { echo "environment variable WIREPROXY_CONF is not found in this system" 1>&2; exit 0; }
printenv WIREPROXY_CONF > "${config}"
fi

restart

watch
}

main

0 comments on commit 636427b

Please sign in to comment.