#!/bin/bash

env

source /root/tachyon_base_files/configure_tachyon.sh

IP=$(ip -o -4 addr list eth0 | perl -n -e 'if (m{inet\s([\d\.]+)\/\d+\s}xms) { print $1 }')
echo "WORKER_IP=$IP"
MASTER_IP=$1
WORKER_IP=$IP

echo "preparing Tachyon"
prepare_tachyon $MASTER_IP

echo "starting Hadoop Datanode"
service hadoop-datanode start

echo "starting sshd"
/usr/sbin/sshd

sleep 5

echo "starting Tachyon Worker"
#source /root/tachyon_worker_files/run_tachyon_worker.sh
#chown -R hdfs:hdfs $TACHYON_CONTAINER
#run_tachyon=run_tachyon_worker.sh
#cp /root/tachyon_worker_files/"$run_tachyon" /
#chmod a+rx /"$run_tachyon"
#sudo -u hdfs TACHYON_CONTAINER=$TACHYON_CONTAINER MASTER_IP=$MASTER_IP /"$run_tachyon"

$TACHYON_CONTAINER/bin/tachyon bootstrap-conf $MASTER_IP

$TACHYON_CONTAINER/bin/tachyon-start.sh worker SudoMount


# Keep this script alive in container, so that docker will keep the container running
while [ 1 ];
do
  sleep 1
done
