mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 10:59:59 +00:00
Tor starts its worker threads by the number of CPU cores it detects, and the cpus limit of the container does not change that number. On a host with 20 cores every node of the private chutney network ran 21 threads and grew to about 0.6 GB. The seven relays and authorities filled the 2g limit and its swap within ten minutes, the kernel killed them one by one, and no circuit could be built any more. The entrypoint now writes NumCPUs 1 into the torrc of every chutney node before it starts the network. Measured on that host over ten minutes: the nodes run 3 threads and stay at 65 to 86 MB, the container at 0.47 GB without swap, where it had filled 2 GB plus 2 GB of swap before. The CLI test of the role fails when a chutney node runs without the limit. Closes #824 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
41 lines
1.5 KiB
Bash
41 lines
1.5 KiB
Bash
#!/bin/sh
|
|
# Tor container entrypoint.
|
|
#
|
|
# public flavor: exec tor directly against the bind-mounted torrc.
|
|
# chutney flavor: first bring up a private, offline Tor test network with
|
|
# chutney inside this container (all nodes on 127.0.0.1), extract its
|
|
# authority/testing lines into the file the rendered torrc %includes, then
|
|
# exec the node tor joined to that private net. Descriptor publication and
|
|
# rendezvous then run at localhost speed instead of over the public network.
|
|
set -eu
|
|
|
|
if [ "${TOR_FLAVOR}" = "chutney" ]; then
|
|
net="hs-v3-min"
|
|
conf=/run/tor/chutney-net.conf
|
|
mkdir -p /run/tor
|
|
|
|
echo "[tor-entrypoint] bringing up chutney private network '${net}'"
|
|
# Exception: chutney creates its net/ state dir relative to the CWD, so
|
|
# every call must run from /opt/chutney or the torrc grep below misses.
|
|
cd /opt/chutney
|
|
CHUTNEY_LISTEN_ADDRESS=127.0.0.1 \
|
|
./chutney init --net "${net}"
|
|
./chutney configure
|
|
for torrc in net/nodes/*/torrc; do
|
|
echo "NumCPUs 1" >>"${torrc}"
|
|
done
|
|
./chutney start
|
|
./chutney wait_for_bootstrap
|
|
|
|
grep -hE '^(TestingTorNetwork|DirAuthority|DirServer|AlternateDirAuthority) ' \
|
|
net/nodes/*/torrc | sort -u >"${conf}"
|
|
if [ ! -s "${conf}" ]; then
|
|
echo "[tor-entrypoint] ERROR: ${conf} is empty — the node would silently join the public Tor network" >&2
|
|
exit 1
|
|
fi
|
|
echo "[tor-entrypoint] wrote ${conf} ($(wc -l <"${conf}") line(s))"
|
|
cd /
|
|
fi
|
|
|
|
exec tor "$@"
|