mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-20 21:43:08 +00:00
193b357a0c
When I first bring up the container, I want to know I'm approving the join request for the right node. I can get the node's ZT address by manually executing `zerotier-cli info` in the node (e.g. with `docker-compose exec zerotier zerotier-cli info`) but just having it in the logs to start with is very convenient.
87 lines
1.6 KiB
Bash
87 lines
1.6 KiB
Bash
#!/bin/sh
|
|
|
|
grepzt() {
|
|
[ -f /var/lib/zerotier-one/zerotier-one.pid -a -n "$(cat /var/lib/zerotier-one/zerotier-one.pid)" -a -d "/proc/$(cat /var/lib/zerotier-one/zerotier-one.pid)" ]
|
|
return $?
|
|
}
|
|
|
|
mkztfile() {
|
|
file=$1
|
|
mode=$2
|
|
content=$3
|
|
|
|
mkdir -p /var/lib/zerotier-one
|
|
echo "$content" > "/var/lib/zerotier-one/$file"
|
|
chmod "$mode" "/var/lib/zerotier-one/$file"
|
|
}
|
|
|
|
if [ "x$ZEROTIER_API_SECRET" != "x" ]
|
|
then
|
|
mkztfile authtoken.secret 0600 "$ZEROTIER_API_SECRET"
|
|
fi
|
|
|
|
if [ "x$ZEROTIER_IDENTITY_PUBLIC" != "x" ]
|
|
then
|
|
mkztfile identity.public 0644 "$ZEROTIER_IDENTITY_PUBLIC"
|
|
fi
|
|
|
|
if [ "x$ZEROTIER_IDENTITY_SECRET" != "x" ]
|
|
then
|
|
mkztfile identity.secret 0600 "$ZEROTIER_IDENTITY_SECRET"
|
|
fi
|
|
|
|
mkztfile zerotier-one.port 0600 "9993"
|
|
|
|
killzerotier() {
|
|
echo "Killing zerotier"
|
|
kill $(cat /var/lib/zerotier-one/zerotier-one.pid)
|
|
exit 0
|
|
}
|
|
|
|
trap killzerotier INT TERM
|
|
|
|
echo "Configuring networks to join"
|
|
mkdir -p /var/lib/zerotier-one/networks.d
|
|
|
|
echo "joining networks: $@"
|
|
for i in "$@"
|
|
do
|
|
echo "Configuring join for $i"
|
|
touch "/var/lib/zerotier-one/networks.d/${i}.conf"
|
|
done
|
|
|
|
echo "starting zerotier"
|
|
nohup /usr/sbin/zerotier-one &
|
|
|
|
while ! grepzt
|
|
do
|
|
echo "zerotier hasn't started, waiting a second"
|
|
|
|
if [ -f nohup.out ]
|
|
then
|
|
tail -n 10 nohup.out
|
|
fi
|
|
|
|
sleep 1
|
|
done
|
|
|
|
echo "Writing healthcheck for networks: $@"
|
|
|
|
cat >/healthcheck.sh <<EOF
|
|
#!/bin/bash
|
|
for i in $@
|
|
do
|
|
[ "\$(zerotier-cli get \$i status)" = "OK" ] || exit 1
|
|
done
|
|
EOF
|
|
|
|
chmod +x /healthcheck.sh
|
|
|
|
echo "zerotier-cli info: $(zerotier-cli info)"
|
|
|
|
echo "Sleeping infinitely"
|
|
while true
|
|
do
|
|
sleep 1
|
|
done
|