127 строки
4.1 KiB
Bash
Executable File
127 строки
4.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Usage:
|
|
# Run the service in the local environment: ./scripts/run
|
|
# Run the service inside a Docker container: ./scripts/run -s
|
|
# Run the service inside a Docker container: ./scripts/run --in-sandbox
|
|
# Run only the web service: ./scripts/run --webservice
|
|
# Run only the simulation: ./scripts/run --simulation
|
|
# Run the IoT Hub Manager Docker image: ./scripts/run --iothubman
|
|
# Show how to use this script: ./scripts/run -h
|
|
# Show how to use this script: ./scripts/run --help
|
|
|
|
# Debug|Release
|
|
CONFIGURATION=Release
|
|
|
|
set -e
|
|
APP_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )/"
|
|
source "$APP_HOME/scripts/.functions.sh"
|
|
|
|
# Folder where PCS sandboxes cache data. Reuse the same folder to speed up the
|
|
# sandbox and to save disk space.
|
|
# Use PCS_CACHE="$APP_HOME/.cache" to cache inside the project folder
|
|
PCS_CACHE="/tmp/azure/iotpcs/.cache"
|
|
|
|
help() {
|
|
echo "Usage:"
|
|
echo " Run the service in the local environment: ./scripts/run"
|
|
echo " Run the service inside a Docker container: ./scripts/run -s|--in-sandbox"
|
|
echo " Run only the web service: ./scripts/run --webservice"
|
|
echo " Run only the simulation: ./scripts/run --simulation"
|
|
echo " Run the IoT Hub Manager Docker image: ./scripts/run --iothubman"
|
|
echo " Show how to use this script: ./scripts/run -h|--help"
|
|
}
|
|
|
|
setup_sandbox_cache() {
|
|
mkdir -p $PCS_CACHE/sandbox/.config
|
|
mkdir -p $PCS_CACHE/sandbox/.dotnet
|
|
mkdir -p $PCS_CACHE/sandbox/.nuget
|
|
}
|
|
|
|
run_in_sandbox() {
|
|
|
|
setup_sandbox_cache
|
|
|
|
cd $APP_HOME
|
|
|
|
# On Windows this script should use docker.exe, in which case
|
|
# the parameters syntax is different, e.g. volumes path
|
|
# (i.e. C:\path\path\... vs /c/path/path/...).
|
|
set +e
|
|
IS_WINDOWS=$(which cmd.exe)
|
|
set -e
|
|
if [[ -z "$IS_WINDOWS" ]]; then
|
|
check_dependency_docker
|
|
|
|
./scripts/env-vars-check
|
|
|
|
docker run -it \
|
|
-p $PCS_DEVICESIMULATION_WEBSERVICE_PORT:$PCS_DEVICESIMULATION_WEBSERVICE_PORT \
|
|
-e "PCS_DEVICESIMULATION_WEBSERVICE_PORT=$PCS_DEVICESIMULATION_WEBSERVICE_PORT" \
|
|
-e "PCS_IOTHUBMANAGER_WEBSERVICE_URL=$PCS_IOTHUBMANAGER_WEBSERVICE_URL" \
|
|
-v "$PCS_CACHE/sandbox/.config:/root/.config" \
|
|
-v "$PCS_CACHE/sandbox/.dotnet:/root/.dotnet" \
|
|
-v "$PCS_CACHE/sandbox/.nuget:/root/.nuget" \
|
|
-v "$APP_HOME:/opt/code" \
|
|
azureiotpcs/code-builder-dotnet:1.0-dotnetcore /opt/scripts/run
|
|
else
|
|
# Note 'winpty' is required to provide a TTY to Docker
|
|
cmd.exe /c "winpty .\scripts\run.cmd" --in-sandbox
|
|
fi
|
|
}
|
|
|
|
prepare_for_run() {
|
|
check_dependency_dotnet
|
|
cd $APP_HOME
|
|
|
|
./scripts/env-vars-check
|
|
|
|
dotnet restore --verbosity=quiet
|
|
}
|
|
|
|
run_all() {
|
|
echo "Starting simulation agent and web service..."
|
|
dotnet run --configuration $CONFIGURATION --project SimulationAgent/*.csproj & \
|
|
dotnet run --configuration $CONFIGURATION --project WebService/*.csproj && \
|
|
fg
|
|
}
|
|
|
|
run_webservice() {
|
|
echo "Starting web service..."
|
|
dotnet run --configuration $CONFIGURATION --project WebService/*.csproj
|
|
}
|
|
|
|
run_simulation() {
|
|
echo "Starting simulation agent and web service..."
|
|
dotnet run --configuration $CONFIGURATION --project SimulationAgent/*.csproj
|
|
}
|
|
|
|
run_iothubmanager() {
|
|
check_dependency_docker
|
|
|
|
VERSION=latest
|
|
docker run -it -p $PCS_IOTHUBMANAGER_WEBSERVICE_PORT:$PCS_IOTHUBMANAGER_WEBSERVICE_PORT \
|
|
-e PCS_IOTHUBMANAGER_WEBSERVICE_PORT=$PCS_IOTHUBMANAGER_WEBSERVICE_PORT \
|
|
-e PCS_IOTHUB_CONN_STRING=$PCS_IOTHUB_CONN_STRING \
|
|
azureiotpcs/iothubmanager-dotnet:$VERSION
|
|
}
|
|
|
|
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
|
help
|
|
elif [[ "$1" == "--in-sandbox" || "$1" == "-s" ]]; then
|
|
run_in_sandbox
|
|
elif [[ "$1" == "" ]]; then
|
|
prepare_for_run
|
|
run_all
|
|
elif [[ "$1" == "--webservice" ]]; then
|
|
prepare_for_run
|
|
run_webservice
|
|
elif [[ "$1" == "--simulation" ]]; then
|
|
prepare_for_run
|
|
run_simulation
|
|
elif [[ "$1" == "--iothubman" ]]; then
|
|
run_iothubmanager
|
|
fi
|
|
|
|
set +e
|