mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-19 21:17:52 +00:00
f41372680d
- Resolve issue with join not being checked properly for success without using external tools - Resolve issue where initial boot was not being checked properly - Now output errors when zerotier fails to start closes #1581 cc @altano for inspiration for this patch Signed-off-by: Erik Hollensbe <git@hollensbe.org>
69 lines
1.3 KiB
Bash
69 lines
1.3 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 "starting zerotier"
|
|
nohup /usr/sbin/zerotier-one &
|
|
|
|
while ! grepzt
|
|
do
|
|
echo "zerotier hasn't started, waiting a second"
|
|
tail -n 10 nohup.out
|
|
sleep 1
|
|
done
|
|
|
|
echo "joining networks: $@"
|
|
|
|
for i in "$@"
|
|
do
|
|
echo "joining $i"
|
|
|
|
zerotier-cli join "$i"
|
|
|
|
while [ "$(zerotier-cli get $i status)" != "OK" ]
|
|
do
|
|
echo "joining $i failed (are they added in central?); trying again in 1s"
|
|
sleep 1
|
|
done
|
|
done
|
|
|
|
sleep infinity
|