Commit d7a0af70 authored by Jondy Zhao's avatar Jondy Zhao

Refine the process of create slapos-webrunner instance

parent af65d002
...@@ -102,7 +102,7 @@ Then waiting for configure script finished. Be sure the configure scrip report s ...@@ -102,7 +102,7 @@ Then waiting for configure script finished. Be sure the configure scrip report s
</section> </section>
<section><title>SlapOS Node</title> <section><title>SlapOS Node</title>
<para>It's used to format slapos node, release software and create instance, you an run it at any time.</para> <para>It's used to create instance of slapos webrunner, format slapos node, release software and create instance, you an run it at any time.</para>
<para>Click Start -> SlapOS -> SlapOS Node, if the current user isn't Administrator, Right click SlapOS Node, then Run As Administrator.</para> <para>Click Start -> SlapOS -> SlapOS Node, if the current user isn't Administrator, Right click SlapOS Node, then Run As Administrator.</para>
<para>Be sure the scrip reports successfully, otherwise fix the problem and run it again.</para> <para>Be sure the scrip reports successfully, otherwise fix the problem and run it again.</para>
</section> </section>
......
...@@ -381,66 +381,20 @@ function create_template_configure_file() ...@@ -381,66 +381,20 @@ function create_template_configure_file()
} # === create_template_configure_file() === # } # === create_template_configure_file() === #
# ====================================================================== # ======================================================================
# Routine: create_slapos_webrunner_instance # Routine: get_slapos_webrunner_instance
# Create one instance of slapos webrunner in local computer # Get instance connection information and create slaprunner startup file
# ====================================================================== # ======================================================================
function create_slapos_webrunner_instance() function get_slapos_webrunner_instance()
{ {
local _title local _guid=$1
local _guid local _title=$2
local _feature_code="#-*- SlapOS Web Runner JavaScript Boot Code -*-#" local _feature_code="#-*- SlapOS Web Runner JavaScript Boot Code -*-#"
local _re6stnet_ipv6
local _patch_file=/etc/slapos/patches/slapos-cookbook-inotifyx.patch
local _url local _url
local _ret=0
echo Checking SlapOS Webruner ... csih_inform "Trying to get connection information of SlapOS WebRunner instance ..."
if grep -q -F "${_feature_code}" ${slaprunner_startup_file} ; then /opt/slapos/bin/slapos request ${client_configure_file} \
${_title} slaposwebrunner --node computer_guid=${_guid} || return 1
echo "Find feature code ${_feature_code} in the ${slaprunner_startup_file}"
echo "Check SlapOS Webrunner OK."
else
echo Installing SlapOS Webrunner ...
_guid=$(grep "CN=COMP" $node_certificate_file | \
sed -e "s/^.*, CN=//g" | sed -e "s%/emailAddress.*\$%%g")
[[ "${_guid}" == COMP-+([0-9]) ]] ||
csih_error "Invalid computer id '${_guid}' specified."
echo Got computer guid: ${_guid}
_title="SlapOS-Node-Runner-In-${_guid}"
if [[ -r $re6stnet_configure_file ]] ; then
_re6stnet_ipv6=$(grep "Your subnet" $re6stnet_configure_file| \
sed -e "s/^.*subnet: //g" -e "s/\/80 (CN.*\$/1/g")
if [[ -n "${_re6stnet_ipv6}" ]] ; then
echo "Re6stnet address in this computer: ${_re6stnet_ipv6}"
netsh interface ipv6 show addr $slapos_ifname level=normal | \
grep -q "${_re6stnet_ipv6}\$" || \
netsh interface ipv6 add addr $slapos_ifname ${_re6stnet_ipv6}
fi
fi
/opt/slapos/bin/slapos node format -cv --now || \
csih_error "Failed to run slapos format."
echo "Supply slapwebrunner in the computer ${_guid}"
/opt/slapos/bin/slapos supply slaposwebrunner ${_guid}
echo "Request an instance ${_title} ..."
while true ; do
/opt/slapos/bin/slapos node software --verbose
# Apply patches to slapos.cookbook for inotifix
if [[ -r ${_patch_file} ]] ; then
for x in $(find /opt/slapgrid/ -name slapos.cookbook-*.egg) ; do
echo Apply patch ${_patch_file} at $x
cd $x
patch -f --dry-run -p1 < ${_patch_file} > /dev/null && \
patch -p1 < ${_patch_file}
done
fi
/opt/slapos/bin/slapos node instance --verbose
/opt/slapos/bin/slapos node report --verbose
# Connection parameters of instance are: # Connection parameters of instance are:
# {'backend_url': 'http://[2001:67c:1254:45::c5d5]:50000', # {'backend_url': 'http://[2001:67c:1254:45::c5d5]:50000',
...@@ -451,10 +405,15 @@ function create_slapos_webrunner_instance() ...@@ -451,10 +405,15 @@ function create_slapos_webrunner_instance()
_url=$(/opt/slapos/bin/slapos request ${client_configure_file} \ _url=$(/opt/slapos/bin/slapos request ${client_configure_file} \
${_title} slaposwebrunner --node computer_guid=${_guid} | \ ${_title} slaposwebrunner --node computer_guid=${_guid} | \
grep backend_url | sed -e "s/^.*': '//g" -e "s/',.*$//g") grep backend_url | sed -e "s/^.*': '//g" -e "s/',.*$//g")
[[ -n "${_url}" ]] && echo "SlapOS Web Runner URL: ${_url}" && break
done
cat <<EOF > $slaprunner_startup_file if [[ -n "${_url}" ]] ; then
csih_inform "SlapOS WebRunner URL: ${_url}"
if grep -q -F "${_feature_code}" ${slaprunner_startup_file} ; then
csih_inform "Find feature code ${_feature_code} in the ${slaprunner_startup_file}"
echo "Check SlapOS Webrunner OK."
else
csih_inform "Generate SlapOS WebRunner startup file ${slaprunner_startup_file}"
cat <<EOF > ${slaprunner_startup_file}
<html> <html>
<head><title>SlapOS Web Runner</title> <head><title>SlapOS Web Runner</title>
<script LANGUAGE="JavaScript"> <script LANGUAGE="JavaScript">
...@@ -469,8 +428,10 @@ function openwin() { ...@@ -469,8 +428,10 @@ function openwin() {
<!-- $feature_code --> <!-- $feature_code -->
</html> </html>
EOF EOF
echo SlapOS Webrunner boot file $slaprunner_startup_file generated.
echo Install Web Runner OK.
echo
fi fi
} # === create_slapos_webrunner_instance() === # else
csih_error_multi "Request return true, but I can't find connection information," \
"something is wrong with slapos webrunner software."
fi
return ${_ret}
} # === get_slapos_webrunner_instance() === #
#! /bin/bash #! /bin/bash
source $(/usr/bin/dirname $0)/slapos-include.sh source $(/usr/bin/dirname $0)/slapos-include.sh
echo echo ""
echo "Start slapos-node script ..." csih_inform "Start slapos-node script ..."
echo echo ""
declare computer_guid
# ----------------------------------------------------------- # -----------------------------------------------------------
# Check all the configure files # Check all the configure files
# ----------------------------------------------------------- # -----------------------------------------------------------
check_network_configure || exit 1 check_network_configure
check_node_configure || exit 1 check_node_configure
check_client_configure || exit 1 check_client_configure
check_cron_configure check_cron_configure
check_re6stnet_configure check_re6stnet_configure
# ----------------------------------------------------------- # -----------------------------------------------------------
# Check cygwin services used by slapos # Check cygwin services used by slapos
# ----------------------------------------------------------- # -----------------------------------------------------------
check_cygwin_service cygserver || exit 1 check_cygwin_service cygserver
check_cygwin_service syslog-ng || exit 1 check_cygwin_service syslog-ng
check_cygwin_service sshd check_cygwin_service sshd
check_cygwin_service cron check_cygwin_service cron
check_re6stnet_needed && check_cygwin_service re6stnet check_re6stnet_needed && check_cygwin_service re6stnet
# ----------------------------------------------------------- # -----------------------------------------------------------
# Create instance of slap web runner # Get computer reference and re6stnet network
# ----------------------------------------------------------- # -----------------------------------------------------------
create_slapos_webrunner_instance || exit 1 computer_guid=$(grep "CN=COMP" ${node_certificate_file} | \
sed -e "s/^.*, CN=//g" | sed -e "s%/emailAddress.*\$%%g")
[[ "${computer_guid}" == COMP-+([0-9]) ]] ||
csih_error_multi "${computer_guid} is invalid computer guid." \
"It should like 'COMP-XXXX', edit ${node_certificate_file}" \
"to fix it."
csih_inform "Got computer reference id: ${computer_guid}"
# ----------------------------------------------------------- # -----------------------------------------------------------
# Format slapos node # Get re6stnet network
# ----------------------------------------------------------- # -----------------------------------------------------------
echo "Formating SlapOS Node ..." if [[ -r ${re6stnet_configure_file} ]] ; then
/opt/slapos/bin/slapos node format -cv --now || exit 1 _addr6=$(grep "Your subnet" ${re6stnet_configure_file} | \
sed -e "s/^.*subnet: //g" -e "s/\/80 (CN.*\$/1/g")
if [[ -n "${_addr6}" ]] ; then
csih_inform "Re6stnet address in this computer: ${_addr6}"
netsh interface ipv6 show addr ${slapos_ifname} level=normal | \
grep -q " ${_addr6}\$" || \
netsh interface ipv6 add addr ${slapos_ifname} ${_addr6}
fi
fi
# ----------------------------------------------------------- # -----------------------------------------------------------
# Release software # Format slapos node
# ----------------------------------------------------------- # -----------------------------------------------------------
echo "Releasing software ..." csih_inform "Formating SlapOS Node ..."
/opt/slapos/bin/slapos node software --verbose /opt/slapos/bin/slapos node format -cv --now ||
csih_error "Run slapos node format failed. "
# ----------------------------------------------------------- # -----------------------------------------------------------
# Instance software # Request an instance of slapos webrunner
# ----------------------------------------------------------- # -----------------------------------------------------------
echo "Creating instance ..." csih_inform "Supply slaposwebrunner in the computer ${computer_guid}"
/opt/slapos/bin/slapos node instance --verbose /opt/slapos/bin/slapos supply slaposwebrunner ${computer_guid}
_title="SlapOS-WebRunner-In-${computer_guid}"
csih_inform "Request slaposwebrunner instance as ${_title}"
/opt/slapos/bin/slapos request ${client_configure_file} \
${_title} slaposwebrunner --node computer_guid=${computer_guid}
# ----------------------------------------------------------- # -----------------------------------------------------------
# Send report # Enter loop to release software, create instance, report
# ----------------------------------------------------------- # -----------------------------------------------------------
echo "Sending report ..." _patch_file=/etc/slapos/patches/slapos-cookbook-inotifyx.patch
/opt/slapos/bin/slapos node report --verbose while true ; do
csih_inform "Releasing software ..."
/opt/slapos/bin/slapos node software --verbose || continue
if [[ -r ${_patch_file} ]] ; then
for _x in $(find /opt/slapgrid/ -name slapos.cookbook-*.egg) ; do
patch -d ${_x} -f --dry-run -p1 < ${_patch_file} > /dev/null &&
csih_inform "Apply patch ${_patch_file} on ${_x}" &&
patch -d ${_x} -p1 < ${_patch_file})
done
fi
csih_inform "Creating instance ..."
/opt/slapos/bin/slapos node instance --verbose || continue
csih_inform "Sending report ..."
/opt/slapos/bin/slapos node report --verbose || continue
get_slapos_webrunner_instance ${computer_guid} ${_title} && break
done
echo ""
csih_inform "Run slapos-node script successfully."
echo ""
echo
echo "Run slapos-node script successfully."
echo
read -n 1 -t 60 -p "Press any key to exit..." read -n 1 -t 60 -p "Press any key to exit..."
exit 0 exit 0
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