Skip to content

Commit

Permalink
added a local deployment script
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkamprath committed May 11, 2020
1 parent a4a53ec commit 857cf00
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions deployment-scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
75 changes: 75 additions & 0 deletions deployment-scripts/local-deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash
print_help_and_exit()
{
echo "Usage: "
echo " local-deploy.sh [-c /path/to/config.json] [-s <streaming password>] [-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 ""

0 comments on commit 857cf00

Please sign in to comment.