Commit 2eb41cbf authored by Jondy Zhao's avatar Jondy Zhao

refine script: slapos-cygwin-bootstrap.sh

parent feda5238
......@@ -8,6 +8,13 @@
<surname>Zhao</surname>
</author>
<revhistory>
<revision>
<revnumber>0.6</revnumber>
<date>2013-09-04</date>
<authorinitials>Jondy Zhao - jondy.zhao@nexedi.com</authorinitials>
<revremark>Add chapter Inside SlapOS Cygwin Node. </revremark>
</revision>
<revision>
<revnumber>0.5</revnumber>
<date>2013-08-29</date>
......@@ -433,7 +440,7 @@ Assum SourceDir in the section "Setup" is "D:\slapos", the builder will find "D:
<para>This chapter describes how to run slapos slave node from sources in the windows.</para>
<para>First Setting Up Cygwin follow the instructions in the above chapter <xref linkend="sec_setup_cygwin"/></para>
<para>Next register to slapos community to get client and computer certificate and key files, refer to <xref linkend="sec_configure_slapos"/>.</para>
<para>Then run slapos-cygwin-bootstrap.sh, got it from slapos.package.git/windows/scripts</para>
<para>Then run slapos-cygwin-bootstrap.sh, slapos-configure.sh, slapos-node.sh in turn, got it from slapos.package.git/windows/scripts</para>
<para>If there are some errors when run both of scripts, fix them and run again, until no any error reported, and now you can run any slapos command in this terminal.</para>
</chapter>
......@@ -505,8 +512,9 @@ Then upload the source packages dist/psutil-1.0.1.tar.gz to http://www.nexedi.or
<listitem><para>Install cygwin</para></listitem>
<listitem><para>Prepare certificate, key, computer.key, computer.crt</para></listitem>
<listitem><para>Run slapos-cygwin-bootstrap.sh, got it from slapos.package.git/windows/scripts</para></listitem>
<listitem><para>Run command slapos node software/release until instance created</para></listitem>
<listitem><para>Run command slapos remove to destroy this instance</para></listitem>
<listitem><para>Run slapos-configure.sh, got it from slapos.package.git/windows/scripts</para></listitem>
<listitem><para>Go to https://www.slapos.org, install test-agent in this node</para></listitem>
<listitem><para>Run command slapos-node.sh</para></listitem>
</itemizedlist>
</para>
......@@ -516,6 +524,101 @@ Then upload the source packages dist/psutil-1.0.1.tar.gz to http://www.nexedi.or
</section>
</chapter>
<chapter><title>Inside SlapOS Cygwin Node</title>
<para>This chapter descripts the internal of slapos cygwin node:
<itemizedlist>
<listitem><para>What we will do to create SlapOS node in the Cygwin</para></listitem>
<listitem><para>Use shell scripts to do these tasks</para></listitem>
</itemizedlist>
</para>
<section><title>What we will do to create SlapOS node in the Cygwin</title>
<para>In order to install SlapOS Node in the Cgywin, the tasks include:
<variablelist>
<varlistentry>
<term>Setup cygwin</term>
<listitem><para>See setup-cygwin.bat to know the detail</para></listitem>
</varlistentry>
<varlistentry>
<term>Patch cygwin</term>
<listitem><para>See function slapos-cygwin-bootstrap.sh!slapos_patch_cygwin</para></listitem>
</varlistentry>
<varlistentry>
<term>Create cygserver and syslog-ng service</term>
<listitem><para>The service names have a prefix so that we can install multi-nodes in one machine. Both of these services is running by local system account.</para></listitem>
</varlistentry>
<varlistentry>
<term>Install slapos-cygwin package</term>
<listitem><para>Extra scripts for slapos running in the cygwin, for examples, ipwin, regpwd, ip etc.</para></listitem>
</varlistentry>
<varlistentry>
<term>Create super user</term>
<listitem><para>The super user is used to start cron and re6stnet services, it's required in Windows 7 and later.</para></listitem>
</varlistentry>
<varlistentry>
<term>Create network interface for slapos</term>
<listitem><para>Slapos use a msloop insterface as its own interface, default name is 're6stnet-lo'. If there is more than one slapos node in the same machine, each node use a prefix.</para></listitem>
</varlistentry>
<varlistentry>
<term>Install re6stnet</term>
<listitem><para>We need re6stnet application except you specify an IPv6 address by manual way.</para></listitem>
</varlistentry>
<varlistentry>
<term>Run re6st-conf</term>
<listitem><para>By this way, we get our IPv6 address assigned by re6stnet network.</para></listitem>
</varlistentry>
<varlistentry>
<term>Install OpenVPN and Copy files to cygwin</term>
<listitem><para>It's required only no native IPv6</para></listitem>
</varlistentry>
<varlistentry>
<term>Build cygwin babeld</term>
<listitem><para>It's required only no native IPv6</para></listitem>
</varlistentry>
<varlistentry>
<term>Install re6stnet service</term>
<listitem><para>It's required only no native IPv6</para></listitem>
</varlistentry>
<varlistentry>
<term>Build SlapOS</term>
<listitem><para>In the Cygwin, we need apply 2 patches: slapos-core-format.patch, supervisor-cygwin.patch</para></listitem>
</varlistentry>
<varlistentry>
<term>Configure SlapOS Node</term>
<listitem><para></para></listitem>
</varlistentry>
<varlistentry>
<term>Run slapos format</term>
<listitem><para></para></listitem>
</varlistentry>
<varlistentry>
<term>Configure SlapOS Client</term>
<listitem><para>If we don't create instance in this SlapOS node, we need not configure slapos client.</para></listitem>
</varlistentry>
<varlistentry>
<term>Create Instance of Slap-Runner</term>
<listitem><para>After this software is releasesd, we need apply the patch 'slapos-cookbook-inotifyx.patch', otherwise it will not work in Cygwin now. </para></listitem>
</varlistentry>
<varlistentry>
<term>Create Instance of Test-Agent</term>
<listitem><para></para></listitem>
</varlistentry>
</variablelist>
Most of tasks list above section could be done by shell scripts, now we have the following scripts:
<itemizedlist>
<listitem><para>setup-cygwin.bat</para></listitem>
<listitem><para>slapos-cygwin-bootstrap.sh</para></listitem>
<listitem><para>slapos-configure.sh</para></listitem>
<listitem><para>slapos-node.sh</para></listitem>
<listitem><para>slapos-cleanup.sh</para></listitem>
<listitem><para>autorebase.bat</para></listitem>
</itemizedlist>
Except autorebase.bat, all of these scripts could be downloaded from <ulink url="http://git.erp5.org/gitweb/slapos.package.git/tree/refs/heads/cygwin:/windows/scripts?js=1"/>. You can read the source or run script with '-h' to know the usage of these scripts.
</para>
<para>The autorebase.bat located in the cygwin root path is generated by slapos-cygwin-bootstap.sh, and used to fix the remap problem. If cygwin reports remap error, you could run this script to fix the problem. Before run this script, you need close all the cygwin terminals at first, then double click autorebase.bat in the windows explorer.</para>
</section>
</chapter>
<appendix id="appendix_cygwin_packages"><title>Cygwin Required Packages List</title>
<para>The following packages are requied by SlapOS Node
<itemizedlist>
......
#! /bin/bash
#
function check_os_is_wow64()
{
[[ $(uname) == CYGWIN_NT-*-WOW64 ]]
}
readonly -f check_os_is_wow64
export PATH=/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin:$PATH
if ! source /usr/share/csih/cygwin-service-installation-helper.sh ; then
echo "Error: Missing csih package."
exit 1
fi
# ======================================================================
# Functions
# ======================================================================
function show_usage()
{
echo "This script is used to build a bootstrap slapos in cywin."
echo ""
echo "Usage:"
echo ""
echo " ./slapos-cygwin-bootstrap.sh"
echo " ./slapos-cygwin-bootstrap.sh [--prefix=prefix] [-f | --force]"
echo ""
echo " --prefix=prefix The prefix is used by network connection name,"
echo " cygwin service name."
echo " --force"
echo " -f Force mode, everything will be reinstalled "
echo " even if it exits."
echo ""
echo "Before run this script, type the following command in the windows"
echo "command console to install cygwin:"
echo ""
echo " setup_cygwin.bat C:\slapos-bootstrap network"
echo " setup_cygwin.bat C:\slapos network"
echo ""
echo "Then sign up slapos.org, got the following certificate files:"
echo ""
......@@ -28,403 +37,219 @@ function show_usage()
echo ""
echo "save them in your home path."
echo ""
echo "Register another computer for test node, save them in the root path"
echo ""
echo " test-computer.key"
echo " test-computer.crt"
echo ""
echo ""
}
readonly -f show_usage
export PATH=/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin:$PATH
if ! source /usr/share/csih/cygwin-service-installation-helper.sh ; then
echo "Error: Missing csih package."
exit 1
fi
csih_inform "Starting bootstrap slapos node ..."
echo ""
# ======================================================================
# Constants
# ======================================================================
declare -r slapos_prefix=slapboot-
declare -r slapos_client_home=~/.slapos
declare -r client_configure_file=$slapos_client_home/slapos.cfg
declare -r client_certificate_file=$slapos_client_home/certificate
declare -r client_key_file=$slapos_client_home/key
declare -r node_certificate_file=/etc/opt/slapos/ssl/computer.crt
declare -r node_key_file=/etc/opt/slapos/ssl/computer.key
declare -r node_configure_file=/etc/opt/slapos/slapos.cfg
declare -r ipv4_local_network=10.202.29.0/24
declare -r ipv6_local_address=2001:67c:1254:e:32::1
declare -r slapos_administrator=${slapos_prefix:-slap}root
declare -r slapos_user_basename=${slapos_prefix:-slap}user
declare -r slapos_ifname=${slapos_prefix}re6stnet-lo
declare -r re6stnet_service_name=${slapos_prefix}re6stnet
declare -r cron_service_name=${slapos_prefix}cron
declare -r syslog_service_name=${slapos_prefix}syslog-ng
declare -r cygserver_service_name=${slapos_prefix}cygserver
declare -r slapos_installer_software=http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/cygwin-share:/software/slapos-windows-installer/software.cfg
declare -r cygwin_home=$(cygpath -a $(cygpath -w /)\\.. | sed -e "s%/$%%")
# -----------------------------------------------------------
# Local variable
# -----------------------------------------------------------
declare _administrator=${slapos_administrator}
declare _password=
declare _computer_certificate=
declare _computer_key=
declare _client_certificate=
declare _client_key=
declare _ipv4_local_network=${ipv4_local_network}
# -----------------------------------------------------------
# Command line options
# -----------------------------------------------------------
while test $# -gt 0; do
# Normalize the prefix.
case "$1" in
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
*) optarg= ;;
esac
case "$1" in
--password=*)
_password=$optarg
;;
-P)
_password=$2
shift
;;
-P)
_administrator=$2
shift
;;
--computer-certificate=*)
_computer_certificate=$optarg
;;
--computer-key=*)
_computer_key=$optarg
;;
--client-certificate=*)
_client_certificate=$optarg
;;
--client-key=*)
_client_key=$optarg
;;
--ipv4-local-network=*)
[[ x$optarg == x*.*.*.*/* ]] ||
csih_error "invalid --ipv4-local-network=$optarg, no match x.x.x.x/x"
_ipv4_local_network=$optarg
;;
*)
show_usage
exit 1
;;
esac
# Next please.
shift
done
function check_os_is_wow64()
{
[[ $(uname) == CYGWIN_NT-*-WOW64 ]]
}
readonly -f check_os_is_wow64
# -----------------------------------------------------------
# Patch cygwin packages for building slapos
# -----------------------------------------------------------
csih_inform "Patching cygwin packages for building slapos"
function slapos_sanity_check()
{
csih_check_program_or_error /usr/bin/cygport cygport
csih_check_program_or_error /usr/bin/libtool libtool
csih_check_program_or_error /usr/bin/cygport cygport
csih_check_program_or_error /usr/bin/libtool libtool
_filename=$(cygpath -a -w $(cygpath -w /)\\..\\setup.exe)
[[ -f $(cygpath -u ${_filename}) ]] || csih_error "missing ${_filename}"
}
readonly -f slapos_sanity_check
csih_inform "libtool patched"
sed -i -e "s/4\.3\.4/4.5.3/g" /usr/bin/libtool
function slapos_patch_cygwin()
{
csih_inform "Patching cygwin packages for building slapos"
csih_inform "/etc/passwd generated"
[[ -f /etc/passwd ]] || mkpasswd > /etc/passwd
csih_inform "libtool patched"
sed -i -e "s/4\.3\.4/4.5.3/g" /usr/bin/libtool
csih_inform "/etc/group generated"
[[ -f /etc/group ]] || mkgroup > /etc/group
csih_inform "/etc/passwd generated"
[[ -f /etc/passwd ]] || mkpasswd > /etc/passwd
_filename=$(cygpath -a -w $(cygpath -w /)\\..\\setup.exe)
csih_inform "check ${_filename}"
[[ -f $(cygpath -u ${_filename}) ]] || csih_error "missing ${_filename}"
csih_inform "/etc/group generated"
[[ -f /etc/group ]] || mkgroup > /etc/group
_filename=/usr/bin/cygport
if [[ -f ${_filename} ]] ; then
_filename=/usr/bin/cygport
if [[ -f ${_filename} ]] ; then
csih_inform "Patching ${_filename} ..."
sed -i -e 's/D="${workdir}\/inst"/D="${CYGCONF_PREFIX-${workdir}\/inst}"/g' ${_filename} &&
csih_inform "OK"
else
else
csih_error "Missing cygport package, no ${_filename} found."
fi
_filename=/usr/share/cygport/cygclass/autotools.cygclass
if [[ -f ${_filename} ]] ; then
fi
_filename=/usr/share/cygport/cygclass/autotools.cygclass
if [[ -f ${_filename} ]] ; then
csih_inform "Patching ${_filename} ..."
sed -i -e 's/prefix=$(__host_prefix)/prefix=${CYGCONF_PREFIX-$(__host_prefix)}/g' ${_filename} &&
csih_inform "OK"
else
else
csih_error "Missing cygport package, no ${_filename} found."
fi
_filename=/usr/share/cygport/cygclass/cmake.cygclass
if [[ -f ${_filename} ]] ; then
fi
_filename=/usr/share/cygport/cygclass/cmake.cygclass
if [[ -f ${_filename} ]] ; then
csih_inform "Patching ${_filename} ..."
sed -i -e 's/-DCMAKE_INSTALL_PREFIX=$(__host_prefix)/-DCMAKE_INSTALL_PREFIX=${CYGCONF_PREFIX-$(__host_prefix)}/g' ${_filename} &&
csih_inform "OK"
else
else
csih_error "Missing cygport package, no ${_filename} found."
fi
for _cmdname in ip useradd usermod groupadd brctl tunctl ; do
wget -c http://git.erp5.org/gitweb/slapos.package.git/blob_plain/heads/cygwin:/windows/scripts/${_cmdname} -O /usr/bin/${_cmdname} ||
csih_error "download ${_cmdname} failed"
csih_inform "download cygwin script ${_cmdname} OK"
chmod +x /usr/bin/${_cmdname} || csih_error "chmod /usr/bin/${_cmdname} failed"
done
if check_os_is_wow64 ; then
wget -c http://dashingsoft.com/products/slapos/ipwin-x64.exe -O /usr/bin/ipwin.exe ||
csih_error "download ipwin-x64.exe failed"
csih_inform "download ipwin-x64.exe OK"
else
wget -c http://dashingsoft.com/products/slapos/ipwin-x86.exe -O /usr/bin/ipwin.exe ||
csih_error "download ipwin-x86.exe failed"
csih_inform "download ipwin-x86.exe OK"
fi
chmod +x /usr/bin/ipwin.exe || csih_error "chmod /usr/bin/ipwin.exe failed"
csih_inform "Patch cygwin packages for building slapos OK"
echo ""
# -----------------------------------------------------------
# Install network interface used by slapos node
# -----------------------------------------------------------
csih_inform "Starting configure slapos network ..."
if ! netsh interface ipv6 show interface | grep -q "\\b${slapos_ifname}\\b" ; then
csih_inform "Installing network interface ${slapos_ifname} ..."
ipwin install netloop.inf *msloop ${slapos_ifname} ||
csih_error "install network interface ${slapos_ifname} failed"
fi
ip -4 addr add $(echo ${ipv4_local_network} | sed -e "s%\.0/%.1/%g") dev ${slapos_ifname} ||
csih_error "add ipv4 address failed"
fi
csih_inform "Configure slapos network OK"
echo ""
# Change format of readme.txt
_filename=$(cygpath -u $(cygpath -m /)/../readme.txt)
if [[ -f ${_filename} ]] ; then
echo "Changing $(cygpath -w ${_filename}) as dos format ..."
unix2dos ${_filename} && echo OK.
fi
# -----------------------------------------------------------
# Check IPv6 protocol, install it if it isn't installed
# -----------------------------------------------------------
csih_inform "Starting configure IPv6 protocol ..."
netsh interface ipv6 show interface > /dev/null || \
netsh interface ipv6 install || \
csih_error "install IPv6 protocol failed"
_filename=".minttyrc"
echo Checking ${_filename} ...
if [[ ! -f ${_filename} || "${_install_mode}" == "force" ]] ; then
cat <<EOF > ${_filename}
BoldAsFont=no
Font=Courier New
FontHeight=16
Scrollbar=none
EOF
echo "${_filename} has been generated."
else
echo OK.
fi
csih_inform "Configure IPv6 protocol OK"
echo ""
_filename="/cygtty.bat"
echo Checking ${_filename} ...
if [[ ! -x ${_filename} || "${_install_mode}" == "force" ]] ; then
cat <<EOF > ${_filename}
@echo off
# -----------------------------------------------------------
# Run the buildout of slapos node
# -----------------------------------------------------------
csih_inform "Starting run buildout of slapos node ..."
csih_inform "mkdir /opt/slapos/log"
mkdir -p /opt/slapos/log
csih_inform "mkdir /opt/download-cache"
mkdir -p /opt/download-cache
[[ -f /opt/slapos/buildout.cfg ]] ||
(cd /opt/slapos && echo "[buildout]
extends = http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/cygwin-share:/component/slapos/buildout.cfg
download-cache = /opt/download-cache
prefix = ${buildout:directory}
" > buildout.cfg) &&
csih_inform "buildout.cfg generated"
[[ -f /opt/slapos/bootstrap.py ]] ||
(cd /opt/slapos &&
python -S -c 'import urllib2;print urllib2.urlopen("http://git.erp5.org/gitweb/slapos.core.git/blob_plain/HEAD:/bootstrap.py").read()' > bootstrap.py ) ||
csih_error "download bootstrap.py failed"
csih_inform "download bootstrap.py OK"
[[ -f /opt/slapos/bin/buildout ]] ||
(cd /opt/slapos && python -S bootstrap.py) ||
csih_error "run bootstrap.py failed"
csih_inform "run bootstrap.py OK"
csih_inform "start bin/buildout"
(cd /opt/slapos ; bin/buildout -v -N) || csih_error "bin/buildout failed"
_filename=~/slapos-core-format.patch
wget -c http://git.erp5.org/gitweb/slapos.package.git/blob_plain/heads/cygwin:/windows/patches/$(basename ${_filename}) -O ${_filename} ||
csih_error "download ${_filename} failed"
csih_inform "download ${_filename} OK"
csih_inform "applay patch ${_filename}"
(cd $(ls -d /opt/slapos/eggs/slapos.core-*.egg/) &&
csih_inform "patch at $(pwd)" &&
patch -f --dry-run -p1 < ${_filename} > /dev/null &&
patch -p1 < ${_filename} &&
csih_inform "apply patch ${_filename} OK")
_filename=~/supervisor-cygwin.patch
wget -c http://git.erp5.org/gitweb/slapos.package.git/blob_plain/heads/cygwin:/windows/patches/$(basename ${_filename}) -O ${_filename} ||
csih_error "download ${_filename} failed"
csih_inform "download ${_filename} OK"
csih_inform "applay patch ${_filename}"
(cd $(ls -d /opt/slapos/eggs/supervisor-*.egg)/supervisor &&
csih_inform "patch at $(pwd)" &&
patch -f --dry-run -p1 < ${_filename} > /dev/null &&
patch -p1 < ${_filename} &&
csih_inform "apply patch ${_filename} OK")
csih_inform "Run buildout of slapos node OK"
echo ""
${slapos_cygroot:0:2}
chdir ${slapos_cygroot}\\bin
# -----------------------------------------------------------
# Configure slapos node and client
# -----------------------------------------------------------
csih_inform "Starting configure slapos client and node ..."
start mintty.exe -i /Cygwin-Terminal.ico -
EOF
chmod +x ${_filename}
echo "${_filename} has been generated."
else
echo OK.
fi
for _name in certificate key computer.key computer.crt ; do
[[ -f ~/${_name} ]] || csih_error "missing file ~/${_name}"
done
for _name in test-computer.key test-computer.crt ; do
[[ -f ${cygwin_home}/${_name} ]] || csih_error "missing file ${cygwin_home}/${_name}"
done
cp ~/certificate ${cygwin_home} && csih_inform "copy ~/certificate to ${cygwin_home}"
cp ~/key ${cygwin_home} && csih_inform "copy ~/key to ${cygwin_home}"
csih_inform "mkdir /etc/opt/slapos/ssl/partition_pki"
mkdir -p /etc/opt/slapos/ssl/partition_pki
csih_inform "mkdir ${slapos_client_home}"
mkdir -p ${slapos_client_home}
(cp ~/certificate ${client_certificate_file} &&
cp ~/key ${client_key_file} &&
cp ~/computer.crt ${node_certificate_file} &&
cp ~/computer.key ${node_key_file} &&
csih_inform "copy certificate/key files OK") ||
csih_error "copy certificate/key files failed"
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 "computer reference id: ${computer_guid}"
interface_guid=$(ipwin guid *msloop ${slapos_ifname}) ||
csih_error "get guid of interface ${slapos_ifname} failed"
[[ "$interface_guid" == {*-*-*-*} ]] ||
csih_error "invalid interface guid ${interface_guid} specified."
csih_inform "the guid of interface ${slapos_ifname} is ${interface_guid}"
wget -c http://git.erp5.org/gitweb/slapos.core.git/blob_plain/HEAD:/slapos.cfg.example -O ${node_configure_file} ||
csih_error "download ${node_configure_file} failed"
csih_inform "download ${node_configure_file} OK"
wget -c http://git.erp5.org/gitweb/slapos.core.git/blob_plain/HEAD:/slapos-client.cfg.example -O ${client_configure_file} ||
csih_error "download ${node_configure_file} failed"
csih_inform "download ${node_configure_file} OK"
csih_inform "ipv4_local_network is ${ipv4_local_network}"
sed -i -e "s%^\\s*interface_name.*$%interface_name = ${interface_guid}%" \
-e "s%^#\?\\s*ipv6_interface.*$%# ipv6_interface =%g" \
-e "s%^ipv4_local_network.*$%ipv4_local_network = ${ipv4_local_network}%" \
-e "s%^computer_id.*$%computer_id = ${computer_guid}%" \
-e "s%^user_base_name =.*$%user_base_name = ${slapos_user_basename}%" \
${node_configure_file}
csih_inform "type ${node_configure_file}:"
csih_inform "************************************************************"
cat ${node_configure_file}
csih_inform "************************************************************"
sed -i -e "s%^cert_file.*$%cert_file = ${client_certificate_file}%" \
-e "s%^key_file.*$%key_file = ${client_key_file}%" \
${client_configure_file}
csih_inform "type ${client_configure_file}:"
csih_inform "************************************************************"
cat ${client_configure_file}
csih_inform "************************************************************"
csih_inform "Configure slapos client and node OK"
echo ""
_filename="/autorebase.bat"
echo Checking ${_filename} ...
if [[ ! -f ${_filename} || "${_install_mode}" == "force" ]] ; then
cat <<EOF > ${_filename}
@echo off
${slapos_cygroot:0:2}
CHDIR ${slapos_cygroot}
${slapos_cygroot}\bin\find /opt/slapos -name "*.dll" > ${slapos_cygroot}\myfile.list
IF EXIST ${slapos_cygroot}\opt\slapgrid. ${slapos_cygroot}\bin\find /opt/slapgrid -name "*.dll" >> ${slapos_cygroot}\myfile.list
IF EXIST ${slapos_cygroot}\srv\slapgrid. ${slapos_cygroot}\bin\find /srv/slapgrid -name "*.dll" >> ${slapos_cygroot}\myfile.list
NET STOP ${slapos_prefix}cron
NET STOP ${slapos_prefix}re6stnet
NET STOP ${slapos_prefix}syslog-ng
NET STOP ${slapos_prefix}cygserver
bin\bash --login -c "/opt/slapos/bin/slapos node stop all"
bin\bash --login -c "for pid in \$(ps | grep '/usr/bin/python2.7' | gawk '{print \$4}') ; do TASKKILL /F /T /PID \$pid ; done"
PATH .\bin;%PATH%
dash /bin/rebaseall -T /myfile.list -v
PAUSE ...
EXIT 0
EOF
chmod +x ${_filename}
echo "${_filename} has been generated."
else
echo OK.
fi
# -----------------------------------------------------------
# Format slapos node
# -----------------------------------------------------------
csih_inform "Formatting SlapOS Node ..."
csih_inform "Patch cygwin packages for building slapos OK"
echo ""
}
readonly -f slapos_patch_cygwin
netsh interface ipv6 add addr ${slapos_ifname} ${ipv6_local_address}
/opt/slapos/bin/slapos node format -cv --now ||
csih_error "Run slapos node format failed. "
function install_slapos_cygwin_package()
{
for _cmdname in ip useradd usermod groupadd brctl tunctl ; do
[[ -f /usr/bin${_cmdname} && -z "${_install_mode}" ]] && continue
wget -c http://git.erp5.org/gitweb/slapos.package.git/blob_plain/heads/cygwin:/windows/scripts/${_cmdname} -O /usr/bin/${_cmdname} ||
csih_error "download ${_cmdname} failed"
csih_inform "download cygwin script ${_cmdname} OK"
chmod +x /usr/bin/${_cmdname} || csih_error "chmod /usr/bin/${_cmdname} failed"
done
echo ""
for _cmdname in regpwd ; do
[[ -x /usr/bin${_cmdname} && -z "${_install_mode}" ]] && continue
wget -c http://dashingsoft.com/products/slapos/${_cmdname}.exe -O /usr/bin/${_cmdname}.exe ||
csih_error "download ${_filename} failed"
csih_inform "download ${_filename} OK"
chmod +x /usr/bin/${_cmdname}.exe || csih_error "chmod /usr/bin/${_cmdname}.exe failed"
fi
# -----------------------------------------------------------
# Check and configure cygwin environments
# -----------------------------------------------------------
csih_check_program_or_error /usr/bin/cygrunsrv cygserver
csih_check_program_or_error /usr/bin/syslog-ng-config syslog-ng
csih_check_program_or_error /usr/bin/openssl openssl
csih_check_program_or_error /usr/bin/ipwin slapos-patches
csih_check_program_or_error /usr/bin/slapos-cron-config slapos-patches
if [[ ! ":$PATH" == :/opt/slapos/bin: ]] ; then
for profile in ~/.bash_profile ~/.profile ; do
! grep -q "export PATH=/opt/slapos/bin:" $profile &&
csih_inform "add /opt/slapos/bin to PATH" &&
echo "export PATH=/opt/slapos/bin:\${PATH}" >> $profile
done
fi
for _cmdname in ipwin ; do
[[ -x /usr/bin${_cmdname} && -z "${_install_mode}" ]] && continue
if check_os_is_wow64 ; then
_filename=${_cmdname}-x64.exe
else
_filename=${_cmdname}-x86.exe
fi
wget -c http://dashingsoft.com/products/slapos/${_filename} -O /usr/bin/${_cmdname}.exe ||
csih_error "download ${_filename} failed"
csih_inform "download ${_filename} OK"
chmod +x /usr/bin/${_cmdname}.exe || csih_error "chmod /usr/bin/${_cmdname}.exe failed"
fi
_path=/etc/slapos/scripts
csih_inform "create path: ${_path}"
mkdir -p ${_path}
for _name in slapos-configure.sh slapos-include.sh post-install.sh slapos-cleanup.sh ; do
_path=/etc/slapos/scripts
csih_inform "create path: ${_path}"
mkdir -p ${_path}
for _name in slapos-include.sh slapos-cygwin-bootstrap.sh slapos-configure.sh slapos-cleanup.sh ; do
[[ -x ${_path}/${_name} && -z "${_install_mode}" ]] && continue
wget -c http://git.erp5.org/gitweb/slapos.package.git/blob_plain/heads/cygwin:/windows/scripts/${_name} -O ${_path}/${_name} ||
csih_error "download ${_name} failed"
csih_inform "download script ${_path}/${_name} OK"
done
done
# Set prefix for slapos
if [[ -n ${slapos_prefix} ]] ; then
# Set prefix for slapos
if [[ -n "${slapos_prefix}" ]] ; then
echo "Set slapos prefix as ${slapos_prefix}"
sed -i -e "s%slapos_prefix=.*\$%slapos_prefix=${slapos_prefix}%" ${_path|/slapos-include.sh
fi
fi
}
readonly -f install_slapos_cygwin_package
# -----------------------------------------------------------
# Create account: slaproot
# -----------------------------------------------------------
# Start seclogon service in the Windows XP
if csih_is_xp ; then
csih_inform "set start property of seclogon to auto"
sc config seclogon start= auto ||
csih_warning "failed to set seclogon to auto start."
# In the later, it's RunAs service, and will start by default
fi
function install_ipv6_protocol()
{
csih_inform "Starting configure IPv6 protocol ..."
netsh interface ipv6 show interface > /dev/null || \
netsh interface ipv6 install || \
csih_error "install IPv6 protocol failed"
# echo Checking slapos account ${_administrator} ...
slapos_check_and_create_privileged_user ${_administrator} ${_password} ||
csih_error "failed to create account ${_administrator}."
csih_inform "Configure IPv6 protocol OK"
echo ""
}
readonly -f install_ipv6_protocol
# -----------------------------------------------------------
# Configure cygwin services: cygserver syslog-ng
# -----------------------------------------------------------
csih_inform "Starting configure cygwin services ..."
if ! cygrunsrv --query ${cygserver_service_name} > /dev/null 2>&1 ; then
function install_cygserver_service()
{
csih_inform "Starting configure cygwin services ..."
if ! cygrunsrv --query ${cygserver_service_name} > /dev/null 2>&1 ; then
csih_inform "run cygserver-config ..."
/usr/bin/cygserver-config --yes || \
csih_error "failed to run cygserver-config"
[[ ${cygserver_service_name} == cygserver ]] ||
cygrunsrv -I ${cygserver_service_name} -d "CYGWIN ${cygserver_service_name}" -p /usr/sbin/cygserver ||
csih_error "failed to install service ${cygserver_service_name}"
else
else
csih_inform "the cygserver service has been installed"
fi
check_cygwin_service ${cygserver_service_name}
fi
}
readonly -f install_cygserver_service
if ! cygrunsrv --query ${syslog_service_name} > /dev/null 2>&1 ; then
function install_syslog_service()
{
if ! cygrunsrv --query ${syslog_service_name} > /dev/null 2>&1 ; then
csih_inform "run syslog-ng-config ..."
/usr/bin/syslog-ng-config --yes || \
csih_error "failed to run syslog-ng-config"
......@@ -432,72 +257,86 @@ if ! cygrunsrv --query ${syslog_service_name} > /dev/null 2>&1 ; then
cygrunsrv -I ${syslog_service_name} -d "CYGWIN ${syslog_service_name}" -p /usr/sbin/syslog-ng -a "-F" ||
csih_error "failed to install service ${syslog_service_name}"
else
else
csih_inform "the syslog-ng service has been installed"
fi
check_cygwin_service ${syslog_service_name}
# Use slapos-cron-config to configure slapos cron service.
if ! cygrunsrv --query ${cron_service_name} > /dev/null 2>&1 ; then
[[ -x ${slapos_cron_config} ]] ||
csih_error "Couldn't find slapos cron config script: ${slapos_cron_config}"
if [[ -z "${csih_PRIVILEGED_PASSWORD}" ]] ; then
slapos_request_password ${_administrator} "Install cron service need the password of ${_administrator}."
fi
csih_inform "run slapos-cron-config ..."
${slapos_cron_config} ${cron_service_name} ${_administrator} ${csih_PRIVILEGED_PASSWORD} ||
csih_error "Failed to run ${slapos_cron_config}"
else
csih_inform "the cron service has been installed"
fi
check_cygwin_service ${cron_service_name}
csih_inform "Configure cygwin services OK"
echo ""
}
readonly -f install_cygserver_service
# -----------------------------------------------------------
# cron: Install cron service and create crontab
# Start script
# -----------------------------------------------------------
csih_inform "Starting configure section cron ..."
csih_inform "Starting bootstrap slapos node ..."
echo ""
_cron_user=${_administrator}
_crontab_file="/var/cron/tabs/${_cron_user}"
if [[ ! -f ${_crontab_file} ]] ; then
cat <<EOF > ${_crontab_file}
SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
MAILTO=""
_prefix=
_install_mode=
# Run "Installation/Destruction of Software Releases" and "Deploy/Start/Stop Partitions" once per minute
* * * * * /opt/slapos/bin/slapos node software --verbose --logfile=/opt/slapos/log/slapos-node-software.log > /dev/null 2>&1
* * * * * /opt/slapos/bin/slapos node instance --verbose --logfile=/opt/slapos/log/slapos-node-instance.log > /dev/null 2>&1
while test $# -gt 0; do
# Normalize the prefix.
case "$1" in
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
*) optarg= ;;
esac
# Run "Destroy Partitions to be destroyed" once per hour
0 * * * * /opt/slapos/bin/slapos node report --maximal_delay=3600 --verbose --logfile=/opt/slapos/log/slapos-node-report.log > /dev/null 2>&1
case "$1" in
--prefix=*)
_prefix=$optarg
;;
-f | --force)
_install_mode=force
;;
-h | --help)
show_usage
exit 0
;;
*)
show_usage
exit 1
;;
esac
# Run "Check/add IPs and so on" once per hour
0 * * * * /opt/slapos/bin/slapos node format >> /opt/slapos/log/slapos-node-format.log 2>&1
EOF
fi
# Next please.
shift
done
csih_inform "change owner of ${_crontab_file} to ${_cron_user}"
chown ${_cron_user} ${_crontab_file}
# ======================================================================
# Constants: slapos bootstrap node use prefiix "slapboot-"
# ======================================================================
declare -r slapos_prefix=${_prefix}
declare -r cygserver_service_name=${slapos_prefix}cygserver
declare -r syslog_service_name=${slapos_prefix}syslog-ng
declare -r slapos_cygroot=$(cygpath -w /)
# -----------------------------------------------------------
# Sanity Check
# -----------------------------------------------------------
slapos_sanity_check
# -----------------------------------------------------------
# Patch cygwin packages for building slapos
# -----------------------------------------------------------
slapos_patch_cygwin
csih_inform "change mode of ${_crontab_file} to 644"
chmod 644 ${_crontab_file}
ls -l ${_crontab_file}
# -----------------------------------------------------------
# Install slapos cygwin package
# -----------------------------------------------------------
install_slapos_cygwin_package
csih_inform "begin of crontab of ${_administrator}:"
csih_inform "************************************************************"
cat ${_crontab_file} || csih_error "No crob tab found."
csih_inform "************************************************************"
csih_inform "end of crontab of ${_administrator}"
# -----------------------------------------------------------
# Check IPv6 protocol, install it if it isn't installed
# -----------------------------------------------------------
install_ipv6_protocol
csih_inform "Configure section cron OK"
echo ""
# -----------------------------------------------------------
# Configure cygwin services: cygserver syslog-ng
# -----------------------------------------------------------
install_cygserver_service
install_syslog_service
# -----------------------------------------------------------
# End script
# -----------------------------------------------------------
echo ""
csih_inform "Configure slapos bootstrap node successfully."
echo ""
......
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