XenAPI: Fix another race condition

Fix it properly this time by forcing a PID from run.sh and using that to track.

A second issue is that upstart may run services twice, introduce a flock test
to ensure that we only run stack.sh once as running in parallel causes issues.

Change-Id: I05990c7154366350b0f9cc3e6c70d6f34238486f
This commit is contained in:
Bob Ball 2015-01-15 12:48:26 +00:00
parent 5f6f43ed9f
commit 0686dae661
2 changed files with 20 additions and 14 deletions

View File

@ -119,9 +119,7 @@ script
chown -R $STACK_USER /opt/stack chown -R $STACK_USER /opt/stack
if su -c "/opt/stack/run.sh" $STACK_USER; then su -c "/opt/stack/run.sh" $STACK_USER
touch /var/run/devstack.succeeded
fi
# Update /etc/issue # Update /etc/issue
{ {
@ -177,8 +175,19 @@ fi
cat <<EOF >$STAGING_DIR/opt/stack/run.sh cat <<EOF >$STAGING_DIR/opt/stack/run.sh
#!/bin/bash #!/bin/bash
set -eux set -eux
cd /opt/stack/devstack (
./unstack.sh || true flock -n 9 || exit 1
./stack.sh
[ -e /opt/stack/runsh.succeeded ] && rm /opt/stack/runsh.succeeded
echo \$\$ >> /opt/stack/run_sh.pid
cd /opt/stack/devstack
./unstack.sh || true
./stack.sh
# Got to the end - success
touch /opt/stack/runsh.succeeded
rm /opt/stack/run_sh.pid
) 9> /opt/stack/.runsh_lock
EOF EOF
chmod 755 $STAGING_DIR/opt/stack/run.sh chmod 755 $STAGING_DIR/opt/stack/run.sh

View File

@ -365,8 +365,8 @@ COPYENV=${COPYENV:-1}
if [ "$WAIT_TILL_LAUNCH" = "1" ] && [ -e ~/.ssh/id_rsa.pub ] && [ "$COPYENV" = "1" ]; then if [ "$WAIT_TILL_LAUNCH" = "1" ] && [ -e ~/.ssh/id_rsa.pub ] && [ "$COPYENV" = "1" ]; then
set +x set +x
echo "VM Launched - Waiting for devstack to start" echo "VM Launched - Waiting for run.sh"
while ! ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "service devstack status | grep -q running"; do while ! ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "test -e /opt/stack/run_sh.pid"; do
sleep 10 sleep 10
done done
echo -n "devstack service is running, waiting for stack.sh to start logging..." echo -n "devstack service is running, waiting for stack.sh to start logging..."
@ -376,14 +376,11 @@ if [ "$WAIT_TILL_LAUNCH" = "1" ] && [ -e ~/.ssh/id_rsa.pub ] && [ "$COPYENV" =
done done
set -x set -x
# Watch devstack's output (which doesn't start until stack.sh is running, pid=`ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "cat /opt/stack/run_sh.pid"`
# but wait for run.sh (which starts stack.sh) to exit as that is what
# hopefully writes the succeeded cookie.
pid=`ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS pgrep run.sh`
ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "tail --pid $pid -n +1 -f /tmp/devstack/log/stack.log" ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "tail --pid $pid -n +1 -f /tmp/devstack/log/stack.log"
# Fail if devstack did not succeed # Fail if devstack did not succeed
ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS 'test -e /var/run/devstack.succeeded' ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS 'test -e /opt/stack/runsh.succeeded'
set +x set +x
echo "################################################################################" echo "################################################################################"
@ -401,7 +398,7 @@ else
echo "" echo ""
echo "ssh into your domU now: 'ssh stack@$OS_VM_MANAGEMENT_ADDRESS' using your password" echo "ssh into your domU now: 'ssh stack@$OS_VM_MANAGEMENT_ADDRESS' using your password"
echo "and then do: 'sudo service devstack status' to check if devstack is still running." echo "and then do: 'sudo service devstack status' to check if devstack is still running."
echo "Check that /var/run/devstack.succeeded exists" echo "Check that /opt/stack/runsh.succeeded exists"
echo "" echo ""
echo "When devstack completes, you can visit the OpenStack Dashboard" echo "When devstack completes, you can visit the OpenStack Dashboard"
echo "at http://$OS_VM_SERVICES_ADDRESS, and contact other services at the usual ports." echo "at http://$OS_VM_SERVICES_ADDRESS, and contact other services at the usual ports."