Last active
January 19, 2016 11:56
-
-
Save gautric/255e8e1e93c7a6c0573c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Licensed to the Rhiot under one or more | |
# contributor license agreements. See the NOTICE file distributed with | |
# this work for additional information regarding copyright ownership. | |
# The licenses this file to You under the Apache License, Version 2.0 | |
# (the "License"); you may not use this file except in compliance with | |
# the License. You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
#!/usr/bin/env bash | |
### Common function | |
exec_docker() { | |
echo "CMD : docker $@" > $RHIOT_RCP_LOG | |
docker $@ > $RHIOT_RCP_LOG 2>&1 | |
# check docker cmd and ignore "rm" | |
if [ $? -ne 0 ] && [ $1 != "rm" ] ; then | |
log_error "Command = docker $@ = failed " | |
log_info "Please check $RHIOT_RCP_LOG" | |
exit -1 | |
fi | |
} | |
output_log() { | |
tee -a $RHIOT_RCP_LOG | |
} | |
log() { | |
echo "$@" | tee -a $RHIOT_RCP_LOG | |
} | |
log_cmd() { | |
log "CMD : $@" | |
} | |
log_info() { | |
log "INFO : $@" | |
} | |
log_error() { | |
log "ERROR: $@" | |
} | |
### General configuration | |
if [ -z "${RHIOT_VERSION}" ]; then | |
RHIOT_VERSION=0.1.3 | |
fi | |
if [ -z "${RHIOT_HOME}" ]; then | |
RHIOT_HOME="${HOME}/.rhiot" | |
fi | |
if [ -z "${RHIOT_DOCKER_MACHINE_ENV}" ]; then | |
RHIOT_DOCKER_MACHINE_ENV="default" | |
fi | |
RHIOT_RCP_LOG=$RHIOT_HOME/rcp.log | |
REQUIRED_DOCKER_VERSION=1.8.2 | |
if [ ! -d ${RHIOT_HOME} ]; then | |
mkdir -p ${RHIOT_HOME} | |
log_info "create RHIOT_HOME=${RHIOT_HOME}" | |
fi | |
log_info "Starting Rhiot Cloud Platform" | |
### Docker boot init | |
case "$OSTYPE" in | |
linux-gnu) | |
if ! type "docker" ; then | |
log_info "Docker not found - installing..." | |
curl -sSL https://get.docker.com/ | sh | |
else | |
DOCKER_VERSION=`docker version --format '{{.Server.Version}}'` | |
if [ "$DOCKER_VERSION" \< "$REQUIRED_DOCKER_VERSION" ]; then | |
log_info "Docker ${REQUIRED_DOCKER_VERSION} is required to run Rhiot. Version ${DOCKER_VERSION} found - upgrading..." | |
curl -sSL https://get.docker.com/ | sh | |
fi | |
fi | |
;; | |
darwin*) | |
if ! type "docker-machine" > /dev/null 2>&1 ; then | |
log_error "Please install docker for MacOS X" | |
exit 1 | |
fi | |
docker-machine env $RHIOT_DOCKER_MACHINE_ENV > /dev/null 2>&1 | |
if [ $? -ne 0 ]; then | |
log_info "docker-machine start $RHIOT_DOCKER_MACHINE_ENV" | |
docker-machine start $RHIOT_DOCKER_MACHINE_ENV > /dev/null 2>&1 | |
fi | |
eval $(docker-machine env $RHIOT_DOCKER_MACHINE_ENV) | |
;; | |
esac | |
if [ $(docker ps | wc -l) -gt 1 ]; then | |
log_info "Stop previous container" | |
exec_docker stop $(docker ps -q) | |
fi | |
log_info "Remove previous container" | |
exec_docker rm -f mongodb AMQP_SERVICE_HOST datastream-node spark_master spark_worker | |
### MongoDB | |
log_info "MongoDB" | |
if [ $(docker ps -a | grep mongodb_data | wc -l) -eq 0 ]; then | |
log_info "MongoDB data volume doesn't exist. Creating..." | |
exec_docker run -v /data/db --name mongodb_data busybox true | |
fi | |
exec_docker run -d --volumes-from mongodb_data --name mongodb -p 27017:27017 mongo | |
log_info "MongoDB started" | |
### IoT Connector | |
log_info "ActiveMQ" | |
exec_docker pull rhiot/activemq:${RHIOT_VERSION} | |
exec_docker run -d --name AMQP_SERVICE_HOST \ | |
-e spring_activemq_broker_enabled=true -e spring_activemq_broker_amqpEnabled=true -e spring_activemq_broker_websocketEnabled=true \ | |
-p 5672:5672 -p 9090:9090 \ | |
-t rhiot/activemq:${RHIOT_VERSION} | |
log_info "ActiveMQ started" | |
### Data stream node | |
log_info "Datastream" | |
exec_docker pull rhiot/datastream-node | |
exec_docker run -d --name datastream-node \ | |
--link AMQP_SERVICE_HOST:AMQP_SERVICE_HOST -e AMQP_SERVICE_HOST=AMQP_SERVICE_HOST \ | |
--link mongodb:mongodb \ | |
-p 8080:8080 -p 5683:5683 -t rhiot/datastream-node | |
log_info "Datastream started" | |
### Spark standalone cluster | |
log_info "Spark" | |
exec_docker pull rhiot/spark-standalone:${RHIOT_VERSION} | |
exec_docker run -d --name spark_master -p 8081:8080 -P -t rhiot/spark-standalone:${RHIOT_VERSION} /start-master.sh "$@" | |
sleep 5 | |
SPARK_MASTER_SERVICE_HOST=`docker inspect spark_master | grep IPAddress\": | cut -d '"' -f 4 | uniq` | |
log_info "Spark master started" | |
exec_docker run -d --name spark_worker \ | |
--link spark_master:spark_master --link AMQP_SERVICE_HOST:AMQP_SERVICE_HOST -e SPARK_MASTER_SERVICE_HOST=${SPARK_MASTER_SERVICE_HOST} \ | |
-v /tmp/jobs:/tmp/jobs -P \ | |
-t rhiot/spark-standalone:${RHIOT_VERSION} /start-worker.sh | |
log_info "Spark worker started" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment