Bootstrap config upgrade

- only IPVS for access, no docker's portforwarding
- generate random password
- generate config for collectd's curl_json
This commit is contained in:
Peter Šurda 2024-02-28 22:46:37 +08:00
parent d4c6db4997
commit 17d1e901c0
Signed by: PeterSurda
GPG Key ID: 3E47497CF67ABB95
2 changed files with 55 additions and 14 deletions

View File

@ -4,7 +4,6 @@ services:
bootstrap:
image: pybitmessage/bootstrap:latest
build: ..
ports:
- 127.0.0.1::8444
env_file: .env
deploy:
replicas: $THREADS

View File

@ -1,10 +1,19 @@
#!/bin/bash
apt -y install curl jq ipvsadm
apt -y install curl jq ipvsadm libyajl2
EXTIP=$(curl -s telnetmyip.com|jq -r .ip)
THREADS=$(nproc --all)
echo "THREADS=$THREADS" > .env
if [ ! -e .env ]; then
THREADS=$(nproc --all)
PASSWORD=$(tr -dc a-zA-Z0-9 < /dev/urandom | head -c32 && echo)
cat > .env << EOF
THREADS=$THREADS
USER=pybitmessage
PASSWORD=$PASSWORD
EOF
else
. .env
fi
ipvsadm -C
ipvsadm -A -t ${EXTIP}:8444 -s rr
@ -12,13 +21,46 @@ ipvsadm -A -t ${EXTIP}:8080 -s rr
docker compose up -d
for i in `seq 1 $THREADS`; do
cont="pybitmessage-bootstrap-${i}"
IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $cont 2>/dev/null)
[ -z "$IP" ] && continue
echo "Adding $IP"
ipvsadm -a -t ${EXTIP}:8444 -r ${IP}:8444 -m
ipvsadm -a -t ${EXTIP}:8080 -r ${IP}:8444 -m
done
CF=/etc/collectd/collectd.conf.d/curl_json.conf
ipvsadm -l
echo "LoadPlugin curl_json" > $CF
echo "<Plugin curl_json>" >> $CF
for i in `seq 1 $THREADS`; do
cont="pybitmessage-bootstrap-${i}"
IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $cont 2>/dev/null)
[ -z "$IP" ] && continue
echo "Adding $IP"
ipvsadm -a -t ${EXTIP}:8444 -r ${IP}:8444 -m
ipvsadm -a -t ${EXTIP}:8080 -r ${IP}:8444 -m
INSTANCE=$(echo $cont|tr - _)
cat >> $CF << EOF
<URL "http://$IP:8442/">
Plugin "pybitmessagestatus"
Instance "$INSTANCE"
User "pybitmessage"
Password "$PASSWORD"
Post "{\"jsonrpc\":\"2.0\",\"id\":\"id\",\"method\":\"clientStatus\",\"params\":[]}"
<Key "result/networkConnections">
Type "gauge"
Instance "networkconnections"
</Key>
<Key "result/numberOfPubkeysProcessed">
Type "counter"
Instance "numberofpubkeysprocessed"
</Key>
<Key "result/numberOfMessagesProcessed">
Type "counter"
Instance "numberofmessagesprocessed"
</Key>
<Key "result/numberOfBroadcastsProcessed">
Type "counter"
Instance "numberofbroadcastsprocessed"
</Key>
</URL>
EOF
done
echo "</Plugin>" >> $CF
systemctl restart collectd
ipvsadm -l -n