#!/bin/bash

set -o nounset
set -o errexit
shopt -s nullglob
cd $(dirname "${0}")

source ./common.sh
source ./config

if [ -f started ]; then
  echo "Container is already running..."
  exit 1
fi

env -i unshare -n ../../../../src/clone/clone

ifconfig ${network_iface_host} ${network_gateway_ip} netmask ${network_netmask}
touch started

function ssh_running() {
  cat console.log | grep "ssh state changed" | tail -n1 | cut -d' ' -f8 | grep running > /dev/null
}

start=$(date +%s)
while ! ssh_running; do
  if [ $(($(date +%s) - ${start})) -gt 5 ]; then
    echo "Timeout waiting for SSH to come up..."
    exit 1
  fi

  sleep 0.1
done

# Setup persistent connections into the container
ssh -o ControlMaster=yes -N -F ssh/ssh_config root@${id} &
ssh -o ControlMaster=yes -N -F ssh/ssh_config vcap@${id} &

#!/bin/bash

set -o nounset
set -o errexit
shopt -s nullglob
cd $(dirname "${0}")

source ./common.sh
source ./config

if [ -f started ]; then
  echo "Container is already running..."
  exit 1
fi

env -i unshare -n ../../../../src/clone/clone

ifconfig ${network_iface_host} ${network_gateway_ip} netmask ${network_netmask}
touch started

function ssh_state() {
  grep "ssh state changed" console.log | cut -d" " -f8
}

start=$(date +%s)
while ! ssh_state | grep -q "spawned"; do
  if [ $(($(date +%s) - ${start})) -gt 5 ]; then
    echo "Timeout waiting for SSH to come up..."
    exit 1
  fi

  sleep 0.1
done

# Setup persistent connections into the container
ssh -o ControlMaster=yes -N -F ssh/ssh_config root@${id} &
ssh -o ControlMaster=yes -N -F ssh/ssh_config vcap@${id} &

Make SSH detection more robust
warden: Make SSH detection more robust

After enabling rsyslog upstart appeared to stop emitting the "running"
event for SSH. Instead, grep for every target state and see if "spawned"
is one of them.

Change-Id: I4535e7ef24d2eb67e17e50f3df7ef7b512814476
