setup-testing-version.sh 972 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

cat << EOF > /root/run-test
#!/bin/bash

BOOTSTRAP="/root/start-bootstrap"
FILE="/etc/cron.d/ansible-vm-bootstrap"
if [[ ! -f "$BOOTSTRAP" ]]
then
  exit 1
fi

# Check if playbook has been correctly extracted
COUNT=$(ls /opt/slapos.playbook | wc -l)
if [[ ! $COUNT -gt 1 ]]
then
  rm -f $FILE
  rm -f /opt/slapos.playbook/playbook.tar.gz
fi

lf=/tmp/pidLockFile
cat /dev/null >> $lf
read lastPID < $lf
# if lastPID is not null and a process with that pid exists , exit
[ ! -z "$lastPID" -a -d /proc/$lastPID ] && exit
# save my pid in the lock file
echo $$ > $lf

if [[ -f "$FILE" ]] && [[ -s "$FILE" ]] && [[ $COUNT -gt 1 ]]
then
  rm /etc/cron.d/vm-boostrap
fi

export TERM=xterm
sleep 5
wget -O /root/launch-test http://deploy.erp5.cn/launch-test
chmod +x /root/launch-test
bash -lc /root/launch-test

EOF

cat << EOF > /etc/cron.d/vm-boostrap
# Bootstrap vm every minutes until it succeed
* * * * * root bash -lc /root/run-test >> /var/log/vm-bootstrap.log 2>&1
EOF