Commit f9cb2f01 authored by Jondy Zhao's avatar Jondy Zhao

Refine script init-slapos-node.sh

parent 393a4a28
#! /bin/bash #! /bin/bash
#
# It used to initialzie slapos node when the computer startup:
#
# 1. Start re6stnet,
#
# 2. Check whether IPv6 connection is availabe
#
# 3. Run slapformat to synchornize information with master
#
# 4. Start slapproxy, it will used by slapos desktop and node manager
#
# Get connection name by GUID name, for example
#
# $ guid2name {C8D7F065-AD35-4777-A768-122451282533}
#
function guid2name() function guid2name()
{ {
if [[ "$1" == "" ]] ; then if [[ "$1" == "" ]] ; then
echo echo
else else
netsh interface ipv6 show interface level=verbose | \ netsh interface ipv6 show interface level=verbose | \
grep -B 1 "{C8D7F065-AD35-4777-A768-122451282533}" | \ grep -B 1 "$1" | \
grep "^Connection" | \ grep "^Connection" | \
sed -e "s/^Connection Name\\s*:\\s*//g" sed -e "s/^Connection Name\\s*:\\s*//g"
fi fi
} }
cfilename=/etc/opt/slapos/slapos.cfg # Default node configure filename
cfilename=${1:/etc/opt/slapos/slapos.cfg}
if [[ ! -f $cfilename ]] ; then if [[ ! -f $cfilename ]] ; then
echo "Error: no found configure file $cfilename, the computer " echo "Error: no found configure file $cfilename, the computer "
...@@ -20,31 +36,33 @@ if [[ ! -f $cfilename ]] ; then ...@@ -20,31 +36,33 @@ if [[ ! -f $cfilename ]] ; then
exit 1 exit 1
fi fi
interface=$(grep "^interface_name\\s*=" $cfilename | sed -e "s/^interface_name\\s*=\\s*//g") interface=$(grep "^interface_name\\s*=" $cfilename | \
sed -e "s/^interface_name\\s*=\\s*//g")
if (( $? == 0 )) ; then if (( $? == 0 )) ; then
ifname=$(guid2name $interface) ifname=$(guid2name $interface)
else else
echo "Error: no interface found in the configure file $cfilename" echo "Error: no interface found in the configure file $cfilename"
exit 1 exit 1
fi fi
if [[ "$ifname" == "" ]]; then if [[ "$ifname" == "" ]]; then
echo "Error: no ipv6 interface found in the configure file $cfilename" echo "Error: no ipv6 interface found in the configure file $cfilename"
exit 1 exit 1
fi fi
# Run re6stnet, waiting until it works
cd /etc/re6stnet cd /etc/re6stnet
re6stnet @re6stnet.conf -I $ifname -i $ifname re6stnet @re6stnet.conf -I $ifname -i $ifname
echo Waiting Re6stent network work ... echo "Waiting re6stent network work ..."
while true ; do while true ; do
ping6 slap.vifib.com > /dev/null && break ping6 slap.vifib.com > /dev/null && break
done done
echo "re6stnet network OK."
if (( $? == 0 )) ; then # Run slapformat
echo Re6stnet network OK. /opt/slapos/bin/slapformat -c --now $cfilename || \
else ( echo "Error: initialize SlapOS Node failed."; exit 1 )
echo SlapOS Node initialize failed, no any IPv6 connection. echo "run slapformat OK."
exit 1
fi
/opt/slapos/bin/slapformat -c --now /etc/opt/slapos/slapos.cfg # Run slapproxy
/opt/slapos/bin/slapproxy || echo "Warning: start slapproxy failed"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment