install.sh 3.66 KB
Newer Older
1 2 3 4
#!/bin/bash

source install.rc

5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
function check_file()
{
  f=$1
  if [[ ! -z "${f// }" ]] ; then
    if [[ ! -f ${f} ]] ; then
      echo "The $2 file '$f' does not exists."
      echo "Please provide file or leave it empty."
      exit 1
    else
      check_file=`mktemp`
      cat ${f} > ${check_file}
    fi
  else
    check_file=''
  fi
}

echo "It is possible to configure SSL key for the host"
echo
echo "Note: Domain name has to match certificate Common Name"
echo
echo "Important: Domain name HAVE TO point to public IP of this machine"
echo "           in order for the installation to work"
28 29
echo
echo "Important: The SSL certificate and SSL Key have to match."
30 31 32 33 34 35 36 37 38 39 40 41 42 43
echo
echo "Leave empty values for everything, than the automatically generated"
echo "certificate will be used, for the public IP of this host."
echo
echo -n "Please type domain name: "
read fqdn
echo -n "Please type the path to SSL Certificate file: "
read ssl_crt_file
check_file "$ssl_crt_file" "SSL Certificate"
frontend_ssl_crt_file=$check_file
echo -n "Please type the path to SSL Key file: "
read ssl_key_file
check_file "$ssl_key_file" "SSL Key"
frontend_ssl_key_file=$check_file
44
echo -n "[OPTIONAL] Please type the path to the CA Certificate used to generate the key and certificate file: "
45 46 47 48 49 50 51 52 53 54 55 56 57
read ssl_ca_crt_file
check_file "$ssl_ca_crt_file" "SSL CA Certificate"
frontend_ssl_ca_crt_file=$check_file

cat > extra_vars.yml <<EOF
frontend_ssl_crt_file: "$frontend_ssl_crt_file"
frontend_ssl_key_file: "$frontend_ssl_key_file"
frontend_ssl_ca_crt_file: "$frontend_ssl_ca_crt_file"
EOF
if [[ ! -z "${fqdn// }" ]] ; then
  echo "frontend_custom_domain: \"$fqdn\"" >> extra_vars.yml
fi

58 59 60 61 62 63 64 65
LOG_FILE=install.log

echo -n "Started at " >> $LOG_FILE 2>&1
date >> $LOG_FILE 2>&1
echo -n "Bootstraping the system..."

yum remove -y firewalld >> $LOG_FILE 2>&1
yum install -y slapos.node*rpm >> $LOG_FILE 2>&1
66
ip -6 addr add fd46::1/64 dev lo >> $LOG_FILE 2>&1
67 68 69 70 71 72 73 74 75 76 77
mkdir -p /opt/slapgrid /srv/slapgrid >> $LOG_FILE 2>&1
slapos configure local >> $LOG_FILE 2>&1
pgrep -f 'slapos proxy' >/dev/null || (
  kill `cat /srv/slapgrid/var/run/supervisord.pid` >> $LOG_FILE 2>&1
  sleep 5 >> $LOG_FILE 2>&1
  slapos node instance --now --verbose >> $LOG_FILE 2>&1
  sleep 15 >> $LOG_FILE 2>&1
)
echo "done."
echo -n "Preparing the machine for SlapOS..."
slapos node format --now --alter_user=True >> $LOG_FILE 2>&1
78 79 80 81
# remove request cronjobs, they will be recreated during ansible run
# and they request the old software releases
rm -f /etc/cron.d/ansible*request*  >> $LOG_FILE 2>&1
# remove any other software from the proxy
82
/opt/slapos/parts/sqlite3/bin/sqlite3 /opt/slapos/slapproxy.db 'delete from software11 where url not in ("$FRONTEND_SR_URL","$ERP5_SR_URL");'  >> $LOG_FILE 2>&1
83 84 85 86 87 88 89
echo "done."
echo -n "Installing ERP5 software..."
yum install -y erp5*rpm >> $LOG_FILE 2>&1
echo "done."

echo -n "Instantiating ERP5 instance..."
for i in `seq 10` ; do
90
  ansible-playbook --extra-vars @extra_vars.yml /opt/slapos.playbook/$PLAYBOOK >> $LOG_FILE 2>&1
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
  ANSIBLE_RESULT=$?
  if [ "$ANSIBLE_RESULT" == "0" ] ; then
    break
  fi
  sleep 5m
done
echo "done."
if [ "$ANSIBLE_RESULT" == "0" ] ; then
  echo "The instance is ready. Please connect to:"
  tail -n 20 $LOG_FILE | grep https
  tail -n 20 $LOG_FILE | grep username
  exit 0
else
  echo "There was a problem with installation."
  echo "Please inspect 'install.log' for details."
  echo "While submitting support request, please attach 'install.log' file."
Łukasz Nowak's avatar
Łukasz Nowak committed
107 108 109 110
  echo "/opt/slapos/log/slapos-node-software.log:" >> $LOG_FILE 2>&1
  cat /opt/slapos/log/slapos-node-software.log >> $LOG_FILE 2>&1
  echo "/opt/slapos/log/slapos-node-instance.log:" >> $LOG_FILE 2>&1
  cat /opt/slapos/log/slapos-node-instance.log >> $LOG_FILE 2>&1
111 112
  exit 1
fi