Fix instance errors (#34)

* Fix some common errors when starting up.

Added more polls for services that we want to make sure are up and running.

Fixed issue where launch script wouldn't run when /snap/bin wasn't in the PATH.

* Added very basic resiliance to launch.sh script.

Tears down a machine and attempts to rebuild it if the build drops into an error state.
This commit is contained in:
Pete Vander Giessen 2018-11-14 11:14:30 +01:00 committed by GitHub
parent d14498cbd9
commit 454fd38526
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 14 deletions

View File

@ -7,6 +7,9 @@ echo "Creating OpenStack Databases"
while ! nc -z localhost 3306; do sleep 0.1; done;
sleep 5
# Wait for rabbitmq to start
while ! nc -z localhost 5672; do sleep 0.1; done;
for db in neutron nova nova_api nova_cell0 cinder glance keystone; do
echo "CREATE DATABASE IF NOT EXISTS ${db}; GRANT ALL PRIVILEGES ON ${db}.* TO '${db}'@'localhost' IDENTIFIED BY '${db}';" \
| mysql-start-client -u root
@ -41,6 +44,9 @@ while ! nc -z localhost 9292; do sleep 0.1; done;
sleep 5
# Wait for identity service
while ! nc -z localhost 5000; do sleep 0.1; done;
openstack image show cirros || {
[ -f $HOME/images/cirros-0.3.5-x86_64-disk.img ] || {
mkdir -p $HOME/images
@ -51,3 +57,6 @@ openstack image show cirros || {
openstack image create --file ${HOME}/images/cirros-0.3.5-x86_64-disk.img \
--public --container-format=bare --disk-format=qcow2 cirros
}
# Wait for horizon
while ! nc -z localhost 80; do sleep 0.1; done;

View File

@ -9,42 +9,56 @@ else
SERVER=$1
fi
if [[ ! $(microstack.openstack keypair list | grep "| microstack |") ]]; then
if [[ ! $(openstack keypair list | grep "| microstack |") ]]; then
echo "creating keypair ($HOME/.ssh/id_microstack)"
mkdir -p $HOME/.ssh
chmod 700 $HOME/.ssh
microstack.openstack keypair create microstack >> $HOME/.ssh/id_microstack
openstack keypair create microstack >> $HOME/.ssh/id_microstack
chmod 600 $HOME/.ssh/id_microstack
fi
echo "Launching instance ..."
microstack.openstack server create --flavor m1.tiny --image cirros --nic net-id=test --key-name microstack $SERVER
openstack server create --flavor m1.tiny --image cirros --nic net-id=test --key-name microstack $SERVER
echo "Checking security groups ..."
SECGROUP_ID=`microstack.openstack security group list --project admin -f value -c ID`
if [[ ! $(microstack.openstack security group rule list | grep icmp | grep $SECGROUP_ID) ]]; then
SECGROUP_ID=`openstack security group list --project admin -f value -c ID`
if [[ ! $(openstack security group rule list | grep icmp | grep $SECGROUP_ID) ]]; then
echo "Creating security group rule for ping."
microstack.openstack security group rule create $SECGROUP_ID --proto icmp
openstack security group rule create $SECGROUP_ID --proto icmp
fi
if [[ ! $(microstack.openstack security group rule list | grep tcp | grep $SECGROUP_ID) ]]; then
if [[ ! $(openstack security group rule list | grep tcp | grep $SECGROUP_ID) ]]; then
echo "Creating security group rule for ssh."
microstack.openstack security group rule create $SECGROUP_ID --proto tcp --dst-port 22
openstack security group rule create $SECGROUP_ID --proto tcp --dst-port 22
fi
TRIES=0
while [[ $(openstack server list | grep $SERVER | grep ERROR) ]]; do
if test $TRIES -gt 3; then
break
fi
TRIES=$(($TRIES + 1))
echo "I ran into an issue launching an instance. Retrying ... (try $TRIES of 3)"
openstack server delete $SERVER
openstack server create --flavor m1.tiny --image cirros --nic net-id=test --key-name microstack $SERVER
while [[ $(openstack server list | grep $SERVER | grep BUILD) ]]; do
sleep 1;
done
done
echo "Allocating floating ip ..."
ALLOCATED_FIP=`microstack.openstack floating ip create -f value -c floating_ip_address external`
microstack.openstack server add floating ip $SERVER $ALLOCATED_FIP
ALLOCATED_FIP=`openstack floating ip create -f value -c floating_ip_address external`
openstack server add floating ip $SERVER $ALLOCATED_FIP
echo "Waiting for server to become ACTIVE."
while :; do
if [[ $(microstack.openstack server list | grep $SERVER | grep ACTIVE) ]]; then
microstack.openstack server list
if [[ $(openstack server list | grep $SERVER | grep ACTIVE) ]]; then
openstack server list
echo "Access your server with 'ssh -i $HOME/.ssh/id_microstack cirros@$ALLOCATED_FIP'"
break
fi
if [[ $(microstack.openstack server list | grep $SERVER | grep ERROR) ]]; then
microstack.openstack server list
if [[ $(openstack server list | grep $SERVER | grep ERROR) ]]; then
openstack server list
echo "Uh-oh. There was an error. See /var/snap/microstack/common/logs for details."
break
fi