Files
smallwebwaf/script/run
clawbot 83525b5e73
check / check (push) Waiting to run
Caches of outside APIs live in /var/cache/sww (closes #314)
Every cache of answers from an outside service has its own file in `SWW_CACHE_DIR` (default `/var/cache/sww`): `lookups.json` (GeoJS), `lists.json` (lists fetched by URL, CrowdSec's decisions included), `dnsbl.json`, `abuseipdb-scores.json` and `routewatch.json` (at most 100,000 answers, each kept an hour). `reputation.json` is gone; the AbuseIPDB checks spent today stay in `SWW_STATE_DIR` as `abuseipdb-checks-spent.json`, since losing them would spend the daily budget twice.

A cache file never stops the start: one that does not parse is set aside as `<name>.bad` with a `file_error` alert. An unwritable `SWW_CACHE_DIR` stops the start. The `run` script creates the cache directory and gives it to `sww`. The cache directory needs no volume and can be left out of backups.

Model: opus-5-5
2026-11-11 10:56:43 +01:00

59 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
# script/run: build bin/sww with script/build and run waf and
# rproxy on the host, with the settings in the environment, until rproxy
# exits or the script is told to stop. rproxy listens on port 8080 unless
# SWRP_LISTEN_ADDR says otherwise, in front of the app at SWRP_UPSTREAM_URL.
# waf listens on port 8090 unless SWW_LISTEN_ADDR says otherwise, and
# rproxy asks it there unless SWRP_WAF_BACKEND says otherwise. Unless
# SWW_STATE_DIR is set, the state files go in bin/state, beside the binary,
# and unless SWW_CACHE_DIR is set, the cache files go in bin/cache. Unless
# SWW_RULES_DIR is set, the rule files are those of share/rules.d, which the
# image ships.
set -eu
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
WAF=""
RPROXY=""
# stop_both: stop what runs, and wait for it, so that waf writes its state
# files.
stop_both() {
trap '' HUP INT TERM
kill $WAF $RPROXY 2>/dev/null || true
wait || true
}
main() {
"$SCRIPT_DIR/build"
if [ -z "${SWW_STATE_DIR+set}" ]; then
SWW_STATE_DIR="$ROOT/bin/state"
export SWW_STATE_DIR
mkdir -p "$SWW_STATE_DIR"
fi
if [ -z "${SWW_CACHE_DIR+set}" ]; then
SWW_CACHE_DIR="$ROOT/bin/cache"
export SWW_CACHE_DIR
mkdir -p "$SWW_CACHE_DIR"
fi
if [ -z "${SWW_RULES_DIR+set}" ]; then
SWW_RULES_DIR="$ROOT/share/rules.d"
export SWW_RULES_DIR
fi
SWW_LISTEN_ADDR="${SWW_LISTEN_ADDR:-:8090}"
SWRP_WAF_BACKEND="${SWRP_WAF_BACKEND:-http://127.0.0.1:${SWW_LISTEN_ADDR##*:}}"
export SWW_LISTEN_ADDR SWRP_WAF_BACKEND
trap stop_both EXIT
trap 'exit 1' HUP INT TERM
"$ROOT/bin/sww" waf &
WAF=$!
"$ROOT/bin/sww" rproxy &
RPROXY=$!
wait "$RPROXY"
}
main "$@"