88 lines
2.8 KiB
Bash
88 lines
2.8 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$BASH_SOURCE")" && pwd)"
|
|
FIXTURE_ROOT=""
|
|
CASE_NAME="baseline-v1"
|
|
RRDP_PORT="$(printenv RRDP_PORT 2>/dev/null || true)"
|
|
RSYNC_PORT="$(printenv RSYNC_PORT 2>/dev/null || true)"
|
|
PID_ROOT=""
|
|
|
|
[[ -n "$RRDP_PORT" ]] || RRDP_PORT=18443
|
|
[[ -n "$RSYNC_PORT" ]] || RSYNC_PORT=1873
|
|
|
|
usage() {
|
|
cat <<'USAGE'
|
|
Usage:
|
|
./start_fixed_services.sh --fixture-root <generated-fixtures> [--case NAME]
|
|
|
|
Cases: baseline-v1, sync-hash-mismatch, baseline-v2, validation-expired,
|
|
validation-max-length, validation-max-length-invalid,
|
|
validation-roa-prefix-outside, validation-out-of-resource,
|
|
validation-ca-over-resource, validation-nonstandard
|
|
Environment: RRDP_PORT (default 18443), RSYNC_PORT (default 1873)
|
|
USAGE
|
|
}
|
|
|
|
die() {
|
|
echo "error: $*" >&2
|
|
exit 2
|
|
}
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--fixture-root) FIXTURE_ROOT="$2"; shift 2 ;;
|
|
--case) CASE_NAME="$2"; shift 2 ;;
|
|
--pid-root) PID_ROOT="$2"; shift 2 ;;
|
|
-h|--help) usage; exit 0 ;;
|
|
*) die "unknown option: $1" ;;
|
|
esac
|
|
done
|
|
|
|
[[ -n "$FIXTURE_ROOT" ]] || die "--fixture-root is required"
|
|
FIXTURE_ROOT="$(cd "$FIXTURE_ROOT" 2>/dev/null && pwd)" || die "fixture root not found"
|
|
CASE_ROOT="$FIXTURE_ROOT/cases/$CASE_NAME"
|
|
[[ -d "$CASE_ROOT/repository" && -d "$CASE_ROOT/http" ]] || die "fixture case not found: $CASE_NAME"
|
|
if [[ -z "$PID_ROOT" ]]; then
|
|
PID_ROOT="$FIXTURE_ROOT/services/$CASE_NAME"
|
|
fi
|
|
mkdir -p "$PID_ROOT"
|
|
[[ ! -f "$PID_ROOT/pids.env" ]] || die "services already appear to be running: $PID_ROOT/pids.env"
|
|
rm -f "$PID_ROOT/rsyncd.pid" "$PID_ROOT/rsyncd.lock"
|
|
|
|
RSYNCD_CONF="$PID_ROOT/rsyncd.conf"
|
|
RSYNC_UID="$(id -un)"
|
|
RSYNC_GID="$(id -gn)"
|
|
cat > "$RSYNCD_CONF" <<EOF
|
|
uid = $RSYNC_UID
|
|
gid = $RSYNC_GID
|
|
use chroot = no
|
|
read only = yes
|
|
port = $RSYNC_PORT
|
|
pid file = $PID_ROOT/rsyncd.pid
|
|
lock file = $PID_ROOT/rsyncd.lock
|
|
log file = $PID_ROOT/rsyncd.log
|
|
|
|
[custom]
|
|
path = $CASE_ROOT/repository
|
|
comment = #142 fixed custom RPKI repository
|
|
read only = yes
|
|
EOF
|
|
|
|
rsync --daemon --no-detach --config="$RSYNCD_CONF" >"$PID_ROOT/rsyncd.stdout.log" 2>&1 &
|
|
RSYNC_PID=$!
|
|
python3 "$SCRIPT_DIR/serve_https.py" \
|
|
--directory "$CASE_ROOT/http" \
|
|
--certfile "$FIXTURE_ROOT/certs/rrdp-server.pem" \
|
|
--keyfile "$FIXTURE_ROOT/certs/rrdp-server.key" \
|
|
--port "$RRDP_PORT" \
|
|
>"$PID_ROOT/https.log" 2>&1 &
|
|
HTTPS_PID=$!
|
|
|
|
printf 'case=%s\nrrdp_pid=%s\nrsync_pid=%s\nrrdp_port=%s\nrsync_port=%s\n' \
|
|
"$CASE_NAME" "$HTTPS_PID" "$RSYNC_PID" "$RRDP_PORT" "$RSYNC_PORT" > "$PID_ROOT/pids.env"
|
|
sleep 1
|
|
kill -0 "$HTTPS_PID" 2>/dev/null || die "HTTPS fixture server exited; see $PID_ROOT/https.log"
|
|
kill -0 "$RSYNC_PID" 2>/dev/null || die "rsync fixture server exited; see $PID_ROOT/rsyncd.stdout.log"
|
|
echo "fixed RRDP/rsync services started case=$CASE_NAME rrdp=$RRDP_PORT rsync=$RSYNC_PORT pid_root=$PID_ROOT"
|