diff --git a/CHANGELOG.md b/CHANGELOG.md index 72bd2e4..b66a630 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Added +* Created a deployment script for running the `multistreaming-server` locally. + ### Changed * Improved error handling in the RTMP configuration generation script. * Improved error handling in the Lindode deploy script. diff --git a/deployment-scripts/README.md b/deployment-scripts/README.md index a390f67..416e40e 100644 --- a/deployment-scripts/README.md +++ b/deployment-scripts/README.md @@ -13,3 +13,17 @@ When running this script, it takes the following arguments: * `-h` - This will display more detailed information on how to use the script, including environment variables that are supported. If the script successfully completes, you will have a Linode server running with the Multi-Service RTMP Broadcaster software running. The script also prints some useful information and commands to use at the end of its run. Most notable is the server's IP address. This should be used in your streaming software configuration as described in [this project's README](https://github.com/michaelkamprath/multi-service-rtmp-broadcaster/blob/master/README.md). + +Two environment variables you might consider setting is the `RTMP_SERVER_LINODE_NODE_TYPE` variable to set the Linode type your server should use and `RTMP_SERVER_LINODE_REGION` variable to set the Linode region your server should reside. The Linode server type should have sufficient cores to handle the transcoding load required for your configuration. The Linode region should be the one closest to where you are streaming from. + +## Local Host + +Running the `multistreaming-server` locally is a great option if your local internet connection can support bandwidth required to push all of the rebroadcasted streams you intend to push. You should also consider if your local CPU should have sufficient cores to perform any transcoding you desire for individual streams. This script will simply launch a Docker container locally for the `multistreaming-server`. + +When running this script, it takes the following arguments: +* `-c /path/to/config.json` - The file path the the JSON file containing the multistreaming server configuration. _REQUIRED_ +* `-s stream_password` - The password that someone needs to use to push a stream to the rebroadcasting server. _REQUIRED_ +* `-b` - When present, the Docker image will be built locally (script assumes it has not been moved from this git repository). When not present, the docker image will be pull from Docker Hub. +* `-h` - This will display more detailed information on how to use the script, including environment variables that are supported. + +If the script successfully completes, you will be running a Docker container locally with the Multi-Service RTMP Broadcaster software running. The script also prints some useful information and commands to use at the end of its run. The IP address you should use to configure your streaming software's destination is `127.0.0.1` or `localhost`. diff --git a/deployment-scripts/local-deploy.sh b/deployment-scripts/local-deploy.sh new file mode 100755 index 0000000..172919b --- /dev/null +++ b/deployment-scripts/local-deploy.sh @@ -0,0 +1,75 @@ +#!/bin/bash +print_help_and_exit() +{ + echo "Usage: " + echo " local-deploy.sh [-c /path/to/config.json] [-s ] [-b]" + echo "" + echo "Environment Variables (can be used instead of command arguments): " + echo " RTMP_SERVER_CONFIG_FILEPATH : path to RTMP server config JSON file. Can replace -c option." + echo " RTMP_SERVER_STREAM_PASSWORD : Password used by RTMP streaming server for livestreams. Can replace -s option." + echo " RTMP_SERVER_DOCKER_IMAGE_NAME : The image name to pull from Docker hub, or the image name to use if building locally (-b)." + exit 0 +} + + +build_docker_image_locally() +{ + # assumes this script is running in its original git repository. + BASEDIR=$(dirname "$BASH_SOURCE") + if [ $RTMP_SERVER_DOCKER_IMAGE_NAME == $DEFAULT_DOCKER_HUB_IMAGE_NAME ]; then + RTMP_SERVER_DOCKER_IMAGE_NAME="multistreaming-server:latest" + fi + docker build -t $RTMP_SERVER_DOCKER_IMAGE_NAME $BASEDIR/../multistreaming-server/ +} + +DEFAULT_DOCKER_HUB_IMAGE_NAME="kamprath/multistreaming-server:latest" +RTMP_SERVER_DOCKER_IMAGE_NAME=${RTMP_SERVER_DOCKER_IMAGE_NAME:-$DEFAULT_DOCKER_HUB_IMAGE_NAME} + +# check arguments passed to this script +while getopts "bc:s:h" option; do + case "${option}" in + b) + # By default this script pulls from Docker hub. This ooption + # forces a local build of the Docker image. + build_docker_image_locally + ;; + c) + RTMP_SERVER_CONFIG_FILEPATH=$OPTARG + ;; + s) + RTMP_SERVER_STREAM_PASSWORD=$OPTARG + ;; + h) + print_help_and_exit + ;; + esac +done +shift $((OPTIND -1)) + +if [ -z $RTMP_SERVER_STREAM_PASSWORD ]; then + echo "You must define a streaming password for the streaming server. Use the '-s' option or set the RTMP_SERVER_STREAM_PASSWORD environment variable." + exit 2 +fi + +if [ -z $RTMP_SERVER_CONFIG_FILEPATH ]; then + echo "You must define a filepath to the streaming server configuration JSON file. Use the -c option." +fi +echo "RTMP_SERVER_DOCKER_IMAGE_NAME = $RTMP_SERVER_DOCKER_IMAGE_NAME" + +# +echo "Launching $RTMP_SERVER_DOCKER_IMAGE_NAME Docker image." +config_file_absolute_path="$(cd "$(dirname "$RTMP_SERVER_CONFIG_FILEPATH")"; pwd)/$(basename "$RTMP_SERVER_CONFIG_FILEPATH")" +docker_proc_id=$( \ + docker run -d -p 80:80 -p 1935:1935 \ + --env MULTISTREAMING_PASSWORD=${RTMP_SERVER_STREAM_PASSWORD} \ + -v ${config_file_absolute_path}:/rtmp-configuation.json \ + ${RTMP_SERVER_DOCKER_IMAGE_NAME} \ +) +docker_short_proc_id=$(echo $docker_proc_id | cut -c1-12) +echo "" +echo "Launched docker container $docker_short_proc_id. To stop this contianer:" +echo " docker stop $docker_short_proc_id" +echo "" +echo "Visit the Multistreaming Server's statistics page here:" +echo " http://127.0.0.1/stat" +echo ""