Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
saijel authored and KamalGalrani committed May 12, 2017
1 parent d1e7baa commit e8fdd4d
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 48 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ local:
cd tools && sudo make && cd ../lucida && make

start_all:
cd tools && ./start_all.sh
cd tools && ./start_all_tmux.sh

start_all_secure:
cd tools && ./start_all_tmux.sh secure
2 changes: 1 addition & 1 deletion lucida/calendar/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ corenlp:
fi

start_server:
gnome-terminal -x bash -c "./gradlew run $(filter-out $@,$(MAKECMDGOALS)); read -n1"
./gradlew run

start_test:
gnome-terminal -x bash -c "cd CalendarClient; ./start-Calendar-client.sh $(filter-out $@,$(MAKECMDGOALS)); read -n1"
Expand Down
2 changes: 1 addition & 1 deletion lucida/commandcenter/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ config
.DS_STORE
inputs
models

certs
2 changes: 1 addition & 1 deletion lucida/commandcenter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ clean:
rm -rf lucidaservice lucidatypes

start_server:
gnome-terminal -x bash -c "source ${PWD}/../../tools/python_2_7_12/bin/activate && python app.py $(filter-out $@,$(MAKECMDGOALS)); read -n1"
source ${PWD}/../../tools/python_2_7_12/bin/activate && python app.py

docker:
cp ../lucidaservice.thrift .; \
Expand Down
58 changes: 39 additions & 19 deletions lucida/commandcenter/app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import sys, glob, os
sys.path.insert(0, glob.glob(os.path.abspath(os.path.dirname(__file__)) +
'/../../tools/thrift-0.9.3/lib/py/build/lib*')[0])

import sys, glob, os
sys.path.insert(0, glob.glob(os.path.abspath(os.path.dirname(__file__)) +
'/../../tools/thrift-0.9.3/lib/py/build/lib*')[0])

from controllers import *
from flask import *
from threading import Thread
Expand All @@ -27,20 +27,40 @@

# Session.
app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'

def flask_listener():
app.run(host='0.0.0.0', port=3000, debug=True, use_reloader=False,
threaded=True)


# For https (with ASR capability)
if os.environ.get('SECURE_HOST'):
print 'Starting secure flask'
app.run(host='0.0.0.0', port=3000, debug=True, use_reloader=False,
threaded=True, ssl_context=('certs/server.crt', 'certs/server.key'))
# For http (without ASR capability)
else:
print 'Starting non-secure flask'
app.run(host='0.0.0.0', port=3000, debug=True, use_reloader=False,
threaded=True)

def web_socket_listener():
print 'Start web socket at 8081'
logging.basicConfig(level=logging.DEBUG,
format="%(levelname)8s %(asctime)s %(message)s ")
logging.debug('Starting up server')
WebSocket.tornado.options.parse_command_line()
WebSocket.Application().listen(8081)
WebSocket.tornado.ioloop.IOLoop.instance().start()

print 'Start web socket at 8081'
logging.basicConfig(level=logging.DEBUG,
format="%(levelname)8s %(asctime)s %(message)s ")
logging.debug('Starting up server')
WebSocket.tornado.options.parse_command_line()

# For wss (with ASR capability)
if os.environ.get('SECURE_HOST'):
print 'Starting secure web socket'
WebSocket.Application().listen(8081, ssl_options={
"certfile":"certs/server.crt",
"keyfile":"certs/server.key"})
# For ws (without ASR capability)
else:
print 'Starting non-secure web socket'
WebSocket.Application().listen(8081)

WebSocket.tornado.ioloop.IOLoop.instance().start()

if __name__ == '__main__':
Thread(target = flask_listener).start()
web_socket_listener()
Thread(target = flask_listener).start()
web_socket_listener()
24 changes: 24 additions & 0 deletions lucida/commandcenter/gen_certs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

if [ ! -e certs/server.key ] || [ ! -e certs/server.crt ]; then

mkdir certs
cd certs/

# Generate a private key
openssl genrsa -des3 -out server.key 1024

# Generate a CSR
openssl req -new -key server.key -out server.csr

# Remove passphrase from key
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
rm server.key.org

# Generate a self signed certificate
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
rm server.csr

cd ..
fi
2 changes: 1 addition & 1 deletion lucida/djinntonic/dig/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $(TARGET): $(OBJECTS)
$(CXX) -Wall $(CXXFLAGS) -c $< -o $@

start_server:
gnome-terminal -x bash -c "./DIGServer $(filter-out $@,$(MAKECMDGOALS)); read -n1"
./DIGServer

start_test:
gnome-terminal -x bash -c "./run-test.sh $(filter-out $@,$(MAKECMDGOALS)); read -n1"
Expand Down
3 changes: 1 addition & 2 deletions lucida/djinntonic/face/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ $(TARGET): $(OBJECTS)
$(CXX) -Wall $(CXXFLAGS) -c $< -o $@

start_server:
gnome-terminal -x bash -c "./FACEServer $(filter-out $@,$(MAKECMDGOALS)); read -n1"

./FACEServer
start_test:
gnome-terminal -x bash -c "./run-test.sh $(filter-out $@,$(MAKECMDGOALS)); read -n1"

Expand Down
2 changes: 1 addition & 1 deletion lucida/djinntonic/imc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $(TARGET): $(OBJECTS)
$(CXX) -Wall $(CXXFLAGS) -c $< -o $@

start_server:
gnome-terminal -x bash -c "./IMCServer $(filter-out $@,$(MAKECMDGOALS)); read -n1"
./IMCServer

start_test:
gnome-terminal -x bash -c "./run-test.sh $(filter-out $@,$(MAKECMDGOALS)); read -n1"
Expand Down
2 changes: 1 addition & 1 deletion lucida/imagematching/opencv_imm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SUBDIRS=server test
include ../../../Makefile.common

start_server:
gnome-terminal -x bash -c "cd server; ./imm_server $(filter-out $@,$(MAKECMDGOALS)); read -n1"
cd server; ./imm_server

start_test:
gnome-terminal -x bash -c "cd test; ./imm_test $(filter-out $@,$(MAKECMDGOALS)); read -n1"
Expand Down
2 changes: 1 addition & 1 deletion lucida/questionanswering/OpenEphyra/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ thrift:
fi

start_server:
gnome-terminal -x bash -c "chmod +x start_server.sh && ./start_server.sh $(filter-out $@,$(MAKECMDGOALS)); read -n1"
chmod +x start_server.sh && ./start_server.sh

start_test:
gnome-terminal -x bash -c "chmod +x start_test.sh && ./start_test.sh $(filter-out $@,$(MAKECMDGOALS)); read -n1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
export GST_PLUGIN_PATH=$(pwd)/kaldi/tools/gst-kaldi-nnet2-online/src

gnome-terminal -x bash -c "python kaldigstserver/worker.py -u ws://localhost:8081/worker/ws/speech -c sample_english_nnet2.yaml; read -n1"
python kaldigstserver/worker.py -u ${ASR_ADDR_PORT}/worker/ws/speech -c sample_english_nnet2.yaml
18 changes: 0 additions & 18 deletions tools/start_all.sh

This file was deleted.

84 changes: 84 additions & 0 deletions tools/start_all_tmux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash

# This script is used to start all of the microservices
# for the Lucida project by creating a tmux window for each
# server in the background.
# Example calls:
# $./start_all_tmux.sh secure
# $./start_all_tmux.sh
# To attach to the tmux session
# use the following command:
# $tmux a -t lucida

SESSION_NAME="lucida"

# Check if session already exists
tmux has-session -t ${SESSION_NAME}
if [ $? -eq 0 ]; then
echo "Session ${SESSION_NAME} already exists."
exit 0;
elif [ -n "$TMUX" ]; then
echo "Already in a tmux session"
exit 0;
else
echo "Session ${SESSION_NAME} does not exit. Creating a ${SESSION_NAME} session."
fi

# Check to see if we should run on http/ws (non-secure) or https/wss (secure)
if [ "$1" == "secure" ]; then
echo "Enabling secure host"
# Getting the host IP address
export ASR_ADDR_PORT="wss://$(/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'):8081"
export SECURE_HOST=true

# Generate self-signed certificates
cd $(pwd)/../lucida/commandcenter/
chmod +x gen_certs.sh
./gen_certs.sh
cd $(pwd)/../../tools
else
echo "Enabling non-secure host"
export ASR_ADDR_PORT="ws://localhost:8081"
fi

declare -a commandcenter=("CMD" "$(pwd)/../lucida/commandcenter/")
declare -a questionanswering=("QA" "$(pwd)/../lucida/questionanswering/OpenEphyra/")
declare -a imagematching=("IMM" "$(pwd)/../lucida/imagematching/opencv_imm/")
declare -a calendar=("CA" "$(pwd)/../lucida/calendar/")
declare -a speechrecognition=("ASR" "$(pwd)/../lucida/speechrecognition/kaldi_gstreamer_asr/")
declare -a imageclassification=("IMC" "$(pwd)/../lucida/djinntonic/imc/")
declare -a digitrecognition=("DIG" "$(pwd)/../lucida/djinntonic/dig/")
declare -a facerecognition=("FACE" "$(pwd)/../lucida/djinntonic/face")

declare -a services=(
commandcenter
questionanswering
imagematching
calendar
speechrecognition
imageclassification
digitrecognition
facerecognition)

# Create the session
tmux new-session -s ${SESSION_NAME} -d

# Create the service windows
TMUX_WIN=0
for i in "${services[@]}"
do
NAME=$i[0]
SERV_PATH=$i[1]
if [ $TMUX_WIN == 0 ]; then
tmux rename-window -t ${SESSION_NAME}:$TMUX_WIN ${!NAME}
else
tmux new-window -n ${!NAME} -t ${SESSION_NAME}
fi
tmux send-keys -t ${SESSION_NAME}:$TMUX_WIN "cd ${!SERV_PATH}" C-m
tmux send-keys -t ${SESSION_NAME}:$TMUX_WIN "make start_server" C-m
((TMUX_WIN++))
done

# Start out on the first window when we attach
tmux select-window -t ${SESSION_NAME}:0

0 comments on commit e8fdd4d

Please sign in to comment.