|
1 | | -# clone the latest rust repo |
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# DESCRIPTION-------------------------------------------------------------------------- |
| 4 | + # This bash file is used to build and run CMB service resources. |
| 5 | + # These are resources relating to the distributed authority feature. The CMB service is built and maintained by the services team. |
| 6 | + |
| 7 | +# CONTENTS----------------------------------------------------------------------------- |
| 8 | + # There are two resources that are built and run: |
| 9 | + # 1. The echo server - this is a "mock" server that simply echoes back the messages it receives. It is used to test message serialization. |
| 10 | + # The echo server is used inside the DistributedAuthorityCodecTests. These are tests that are built and maintained by the CMB service team. |
| 11 | + # 2. The standalone server - this is a release build of the full CMB service. |
| 12 | + |
| 13 | +# USAGE--------------------------------------------------------------------------------- |
| 14 | + # The script requires ports to be defined. This works via the following command: |
| 15 | + # ./<path-to-script>/run_cmb_service.sh -e <echo-server-port> -s <cmb-service-port> |
| 16 | + |
| 17 | + # Example usage: |
| 18 | + # ./<path-to-script>/run_cmb_service.sh -e 7788 -s 7799 |
| 19 | + |
| 20 | + # This script is currently used in the desktop-standalone-tests yamato job. |
| 21 | + |
| 22 | +# TECHNICAL CONSIDERATIONS--------------------------------------------------------------- |
| 23 | + # This is a bash script and so needs to be run on a Unix based system. |
| 24 | + # - It runs on mac and ubuntu bokken machines. It will not run on windows bokken machines. |
| 25 | + |
| 26 | + # This script starts processes running in the background. All logs are still written to stdout and will be seen in the logs of the job. |
| 27 | + # Running in the background means that the processes will continue to run after the script exits. |
| 28 | + # This is not a concern for bokken machines as all processes are killed when the machine is shut down. |
| 29 | + |
| 30 | +# QUALITY THOUGHTS-------------------------------------------------------------------- |
| 31 | + # Currently this script simply uses the head of the cmb service repo. |
| 32 | + # We might want to consider using the latest released version in the future. |
| 33 | + |
| 34 | +#------------------------------------------------------------------------------------- |
| 35 | + |
| 36 | +# Define error message if ports are not defined |
| 37 | +ERROR="Error: Expected ports to be defined! Example script usage:" |
| 38 | +EXAMPLE="run_cmb_service.sh -e <echo-server-port> -s <cmb-service-port>" |
| 39 | + |
| 40 | +# get arguments passed to the script |
| 41 | +while getopts 'e:s:' flag; do |
| 42 | +case "${flag}" in |
| 43 | + e) echo_port="${OPTARG}" ;; |
| 44 | + s) service_port="${OPTARG}" ;; |
| 45 | + *) printf "%s\n" "$ERROR" "$EXAMPLE" |
| 46 | + exit 1 ;; |
| 47 | + esac |
| 48 | +done |
| 49 | + |
| 50 | +# ensure arguments were passed and the ports are defined |
| 51 | +if [ -z "$echo_port" ] || [ -z "$service_port" ]; then |
| 52 | + printf "%s\n" "$ERROR" "$EXAMPLE"; |
| 53 | + exit 1; |
| 54 | +elif [[ "$echo_port" == "$service_port" ]]; then |
| 55 | + printf "Ports cannot be the same! Please use different ports.\n"; |
| 56 | + exit 1; |
| 57 | +fi |
| 58 | + |
| 59 | +echo "Starting with echo server on port: $echo_port and the cmb service on port: $service_port" |
| 60 | + |
| 61 | +# Setup ------------------------------------------------------------------------- |
| 62 | + |
| 63 | +# clone the cmb service repo |
2 | 64 | git clone https://github.com/Unity-Technologies/mps-common-multiplayer-backend.git |
| 65 | +# navigate to the cmb service directory |
3 | 66 | cd ./mps-common-multiplayer-backend/runtime |
4 | 67 |
|
5 | 68 | # Install rust |
6 | 69 | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y |
| 70 | +# Add the cargo bin directory to the PATH |
7 | 71 | export PATH="$HOME/.cargo/bin:$PATH" |
8 | 72 |
|
| 73 | + |
| 74 | +# Echo server ------------------------------------------------------------------- |
| 75 | + |
9 | 76 | # Build the echo server |
10 | 77 | cargo build --example ngo_echo_server |
| 78 | +# Run the echo server in the background |
| 79 | +cargo run --example ngo_echo_server -- --port $echo_port & |
| 80 | + |
11 | 81 |
|
12 | | -# Run the echo server in the background - this will reuse the artifacts from the build |
13 | | -cargo run --example ngo_echo_server -- --port $ECHO_SERVER_PORT & |
| 82 | +# CMB Service ------------------------------------------------------------------- |
14 | 83 |
|
15 | | -# Build a release version of the standalone server |
| 84 | +# Build a release version of the standalone cmb service |
16 | 85 | cargo build --release --locked |
17 | 86 |
|
18 | | -# Run the standalone server on an infinite loop in the background |
19 | | -while :; do ./target/release/comb-server -l error --metrics-port 5000 standalone --port $CMB_SERVICE_PORT -t 60m; done & |
| 87 | +# Run the standalone service on an infinite loop in the background. |
| 88 | +# The infinite loop is required as the service will exit each time all connected clients disconnect. |
| 89 | +# This means the service will exit after each test. The infinite loop will immediately restart the service each time it exits. |
| 90 | +while :; do |
| 91 | + ./target/release/comb-server -l error --metrics-port 5000 standalone --port $service_port -t 60m; |
| 92 | +done & # <- use & to run the entire loop in the background |
0 commit comments