Skip to content
Snippets Groups Projects
run.sh 3.2 KiB
Newer Older
  • Learn to ignore specific revisions
  • #!/bin/bash
    
    David Trattnig's avatar
    David Trattnig committed
    mode="engine"
    
    docker="false"
    
    #
    # Run Script for AURA Engine
    #
    # Call with one of these parameters:
    #
    # - engine
    # - core
    # - lqs
    # - api-dev
    # - api
    #
    # - docker:engine
    # - docker:core
    # - docker:lqs
    # - docker:build
    # - docker:api
    #
    
    
    if [[ $* =~ ^(engine|core|lqs|api-dev|api)$ ]]; then 
    	mode=$1 
    
    if [[ "$1" == *"docker:"* ]]; then
    
    	docker="true"
    
    	mode=${1#*:}
    
    David Trattnig's avatar
    David Trattnig committed
    echo "[ Run mode=$mode ]"
    
    echo "[ Docker=$docker ]"
    
    # +++ DEFAULT COMMANDS +++ #
    
    if [[ $docker == "false" ]]; then
    
    	### Runs Engine Core & Liquidsoap ###
    
    	if [[ $mode == "engine" ]]; then
    		/usr/bin/env python3.7 engine-core.py
    	fi
    
    	### Runs Engine Core only ###
    
    	if [[ $mode == "core" ]]; then
    		/usr/bin/env python3.7 engine-core.py --without-lqs
    	fi
    
    	### Runs Liquidsoap only ###
    
    	if [[ $mode == "lqs" ]]; then
    		lqs=$(/usr/bin/env python3.7 engine-core.py --get-lqs-command)
    		eval "$lqs"
    	fi
    
    	### Runs the API Server (Development) ###
    
    	if [[ $mode == "api-dev" ]]; then
    		echo "Building Web Applications"
    		sh ./script/build-web.sh
    		echo "Starting API Server"
    		/usr/bin/env python3.7 engine-api.py
    	fi
    
    	### Runs the API Server (Production) ###
    
    David Trattnig's avatar
    David Trattnig committed
    
    
    	if [[ $mode == "api" ]]; then
    		echo "Building Web Applications"
    		sh ./script/build-web.sh
    		echo "Activating Python Environment"
    		source ../python-env/bin/activate
    		echo "Starting API Server"
    		gunicorn -c configuration/gunicorn.conf.py engine-api:app
    	fi
    
    # +++ DOCKER COMMANDS +++ #
    
    if [[ $docker == "true" ]]; then
    	BASE_D=$(realpath "${BASH_SOURCE%/*}/")
    
    	### Runs Engine Core & Liquidsoap ###
    
    	if [[ $mode == "engine" ]]; then
    		exec sudo docker run --name aura-engine --rm -it \
    			-u $UID:$GID \
    			-p 127.0.0.1:8050:5000 \
    			-v "$BASE_D":/srv \
    			-v "$BASE_D/configuration/":/etc/aura \
    
    David Trattnig's avatar
    David Trattnig committed
    			--tmpfs /var/log/aura/ autoradio/engine /srv/engine-core.py
    
    	fi
    
    	### Runs Engine Core only ###
    
    	if [[ $mode == "core" ]]; then
    		exec sudo docker run --name aura-engine-core --rm -it \
    			-u $UID:$GID \
    			-p 127.0.0.1:8050:5000 \
    			-v "$BASE_D":/srv \
    			-v "$BASE_D/configuration/":/etc/aura \
    
    David Trattnig's avatar
    David Trattnig committed
    			--tmpfs /var/log/aura/ autoradio/engine /srv/engine-core.py "--without-lqs"
    
    	fi
    
    	### Runs Liquidsoap only ###
    
    	if [[ $mode == "lqs" ]]; then
    		lqs=$(/usr/bin/env python3.7 engine-core.py --get-lqs-command)
    		eval "$lqs"
    
    		exec sudo docker run --name aura-engine-liquidsoap --rm -it \
    			-u 1000:1000 \
    			-v "$BASE_D":/srv \
    			-v "$BASE_D/configuration/":/etc/aura \
    			--tmpfs /var/log/aura/ \
    
    David Trattnig's avatar
    David Trattnig committed
    			--device /dev/snd autoradio/engine /bin/bash \
    
    			-c "cd /srv/modules/liquidsoap && liquidsoap --debug --verbose engine.liq"
    
    	fi
    
    	### Runs Engine API using Gunicorn ###
    
    	if [[ $mode == "engine" ]]; then
    		exec sudo docker run --name aura-engine-api --rm -it \
    			-u $UID:$GID \
    			-p 127.0.0.1:8050:5000 \
    			-v "$BASE_D":/srv \
    			-v "$BASE_D/configuration/":/etc/aura \
    			--tmpfs /var/log/aura/ aura/engine /srv/engine-api.py \
    
    David Trattnig's avatar
    David Trattnig committed
    			--device autoradio/engine /bin/bash \
    
    			-c "gunicorn -c configuration/gunicorn.conf.py engine-api:app"
    	fi
    
    
    	### Create Docker Image from local project ###
    
    	if [[ $mode == "build" ]]; then
    
    David Trattnig's avatar
    David Trattnig committed
    		exec sudo docker build -t autoradio/engine .
    
    David Trattnig's avatar
    David Trattnig committed
    	### Pushes the latest Docker Image to Docker Hub ###
    
    	if [[ $mode == "push" ]]; then
    		exec sudo docker push autoradio/engine
    	fi
    
    David Trattnig's avatar
    David Trattnig committed
    fi