From 1523c924d88f8340d165c6c9d3a7acca7225f62a Mon Sep 17 00:00:00 2001 From: winlin Date: Mon, 7 Aug 2023 22:31:12 +0800 Subject: [PATCH] Refine DigitalOcean droplet image. v1.0.302 --- .github/workflows/alpine.yml | 4 - .github/workflows/focal.yml | 4 - .github/workflows/releases.yml | 2 - DEVELOPER.md | 31 +++- Dockerfile.dev | 30 ---- focal/Dockerfile | 3 +- .../containers/conf/conf.d/nginx.http.conf | 4 - .../containers/conf/conf.d/nginx.server.conf | 8 - .../containers/conf/default.d/00.default.conf | 6 - .../containers/conf/default.d/10.mgmt.conf | 19 --- .../containers/conf/default.d/20.srs.conf | 19 --- .../conf/default.d/90.dvr.preview.conf | 8 - platform/containers/conf/nginx.conf | 23 ++- platform/version.go | 2 +- releases/Dockerfile | 1 - releases/version.go | 2 +- scripts/setup-aapanel/README.md | 14 -- scripts/setup-aapanel/do_install.sh | 4 - scripts/setup-bt/README.md | 30 ---- scripts/setup-bt/do_install.sh | 4 - scripts/setup-droplet/README.md | 42 ----- .../files/etc/update-motd.d/99-one-click | 2 +- scripts/setup-droplet/scripts/00-ubuntu.sh | 64 +++---- scripts/setup-droplet/scripts/01-srs.sh | 158 ++++++++---------- scripts/setup-droplet/srs.json | 4 +- scripts/setup-lighthouse/README.md | 14 -- scripts/setup-lighthouse/setup_lighthouse.sh | 9 +- .../setup-ubuntu/Dockerfile.script | 0 28 files changed, 154 insertions(+), 357 deletions(-) delete mode 100644 Dockerfile.dev delete mode 100644 platform/containers/conf/conf.d/nginx.http.conf delete mode 100644 platform/containers/conf/conf.d/nginx.server.conf delete mode 100644 platform/containers/conf/default.d/00.default.conf delete mode 100644 platform/containers/conf/default.d/10.mgmt.conf delete mode 100644 platform/containers/conf/default.d/20.srs.conf delete mode 100644 platform/containers/conf/default.d/90.dvr.preview.conf delete mode 100644 scripts/setup-aapanel/README.md delete mode 100644 scripts/setup-bt/README.md delete mode 100644 scripts/setup-droplet/README.md delete mode 100644 scripts/setup-lighthouse/README.md rename Dockerfile.script => scripts/setup-ubuntu/Dockerfile.script (100%) diff --git a/.github/workflows/alpine.yml b/.github/workflows/alpine.yml index 36fdea27..1b5b7470 100644 --- a/.github/workflows/alpine.yml +++ b/.github/workflows/alpine.yml @@ -66,8 +66,6 @@ jobs: src: ossrs/srs-cloud:${{ env.SRS_TAG }} dst: | ossrs/srs-cloud:${{ env.SRS_MAJOR }} - ossrs/srs-terraform:${{ env.SRS_TAG }} - ossrs/srs-terraform:${{ env.SRS_MAJOR }} runs-on: ubuntu-20.04 aliyun: @@ -93,6 +91,4 @@ jobs: dst: | registry.cn-hangzhou.aliyuncs.com/ossrs/srs-cloud:${{ env.SRS_TAG }} registry.cn-hangzhou.aliyuncs.com/ossrs/srs-cloud:${{ env.SRS_MAJOR }} - registry.cn-hangzhou.aliyuncs.com/ossrs/srs-terraform:${{ env.SRS_TAG }} - registry.cn-hangzhou.aliyuncs.com/ossrs/srs-terraform:${{ env.SRS_MAJOR }} runs-on: ubuntu-20.04 diff --git a/.github/workflows/focal.yml b/.github/workflows/focal.yml index a22d4eb4..d308d9d8 100644 --- a/.github/workflows/focal.yml +++ b/.github/workflows/focal.yml @@ -66,8 +66,6 @@ jobs: src: ossrs/srs-cloud:${{ env.SRS_TAG }} dst: | ossrs/srs-cloud:${{ env.SRS_MAJOR }} - ossrs/srs-terraform:${{ env.SRS_TAG }} - ossrs/srs-terraform:${{ env.SRS_MAJOR }} runs-on: ubuntu-20.04 aliyun: @@ -93,6 +91,4 @@ jobs: dst: | registry.cn-hangzhou.aliyuncs.com/ossrs/srs-cloud:${{ env.SRS_TAG }} registry.cn-hangzhou.aliyuncs.com/ossrs/srs-cloud:${{ env.SRS_MAJOR }} - registry.cn-hangzhou.aliyuncs.com/ossrs/srs-terraform:${{ env.SRS_TAG }} - registry.cn-hangzhou.aliyuncs.com/ossrs/srs-terraform:${{ env.SRS_MAJOR }} runs-on: ubuntu-20.04 diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index f4003b02..73185846 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -81,8 +81,6 @@ jobs: dst: | registry.cn-hangzhou.aliyuncs.com/ossrs/srs-cloud:${{ env.SRS_TAG }} registry.cn-hangzhou.aliyuncs.com/ossrs/srs-cloud:${{ env.SRS_MAJOR }} - registry.cn-hangzhou.aliyuncs.com/ossrs/srs-terraform:${{ env.SRS_TAG }} - registry.cn-hangzhou.aliyuncs.com/ossrs/srs-terraform:${{ env.SRS_MAJOR }} runs-on: ubuntu-20.04 k8s: diff --git a/DEVELOPER.md b/DEVELOPER.md index 134fe012..e66cbdf7 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -263,7 +263,7 @@ Build a docker image: ```bash docker rm -f script 2>/dev/null || echo 'OK' && docker rmi srs-script-dev 2>/dev/null || echo 'OK' && -docker build -t srs-script-dev -f Dockerfile.script . +docker build -t srs-script-dev -f scripts/setup-ubuntu/Dockerfile.script . ``` Create a docker container in daemon: @@ -316,7 +316,7 @@ bash scripts/tools/secret.sh --output test/.env && docker exec -it script ./test/srs-cloud.test -test.v -wait-ready -endpoint http://localhost:2022 \ -srs-log=true -wait-ready=true -init-password=false \ -check-api-secret=true \ - -test.parallel 3 + -test.parallel 8 ``` Access the browser: [http://localhost:2022](http://localhost:2022) @@ -390,7 +390,7 @@ bash scripts/tools/secret.sh --output test/.env && docker exec -it aapanel ./test/srs-cloud.test -test.v -wait-ready -endpoint http://srs.cloud.local:80 \ -srs-log=true -wait-ready=true -init-password=false \ -check-api-secret=true \ - -test.parallel 3 + -test.parallel 8 ``` Open [http://localhost:7800/srscloud](http://localhost:7800/srscloud) to install plugin. @@ -473,7 +473,7 @@ bash scripts/tools/secret.sh --output test/.env && docker exec -it bt ./test/srs-cloud.test -test.v -wait-ready -endpoint http://srs.cloud.local:80 \ -srs-log=true -wait-ready=true -init-password=false \ -check-api-secret=true \ - -test.parallel 3 + -test.parallel 8 ``` Open [http://localhost:7800/srscloud](http://localhost:7800/srscloud) to install plugin. @@ -483,3 +483,26 @@ Open [http://localhost:7800/srscloud](http://localhost:7800/srscloud) to install In the [application store](http://localhost:7800/soft), there is a `srs_cloud` plugin. After test, you can install the plugin `build/bt-srs_cloud.zip` to production BT panel. +## Develop the Droplet Image + +To build SRS droplet image for [DigitalOcean Marketplace](https://marketplace.digitalocean.com/). + +For the first run, please [install Packer](https://www.packer.io/intro/getting-started/install.html) and plugin: + +```bash +brew tap hashicorp/tap && +brew install hashicorp/tap/packer && +PACKER_LOG=1 packer plugins install github.com/digitalocean/digitalocean v1.1.1 +``` + +Start to build SRS image by: + +```bash +(cd scripts/setup-droplet && +export DIGITALOCEAN_TOKEN=$(grep market "${HOME}/Library/Application Support/doctl/config.yaml" |grep -v context |awk '{print $2}') && +packer build srs.json) +``` + +> Note: You can also create a [token](https://cloud.digitalocean.com/account/api/tokens) and setup the env `DIGITALOCEAN_TOKEN`. + +Please check the [snapshot](https://cloud.digitalocean.com/images/snapshots/droplets). diff --git a/Dockerfile.dev b/Dockerfile.dev deleted file mode 100644 index d3fc6d30..00000000 --- a/Dockerfile.dev +++ /dev/null @@ -1,30 +0,0 @@ -ARG ARCH - -FROM ${ARCH}redis:5.0 AS redis - -FROM ${ARCH}ossrs/srs:4 AS srs - -FROM ${ARCH}ossrs/node:18 AS node - -FROM ${ARCH}ossrs/srs:ubuntu20 AS dist - -# https://serverfault.com/questions/949991/how-to-install-tzdata-on-a-ubuntu-docker-image -ENV DEBIAN_FRONTEND=noninteractive -# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#apt-get -RUN apt update && apt-get install -y certbot && rm -rf /var/lib/apt/lists/* - -# Copy nodejs for ui build. -COPY --from=node /usr/local/bin /usr/local/bin -COPY --from=node /usr/local/lib /usr/local/lib -# For redis server and tools. -COPY --from=redis /usr/local/bin/redis-cli /usr/local/bin/redis-cli -COPY --from=redis /usr/local/bin/redis-server /usr/local/bin/redis-server -# For SRS server. -COPY --from=srs /usr/local/srs /usr/local/srs - -# For dev, we mount current directory as /usr/local/srs-cloud, -# so we should link as /data. -RUN rm -rf /data && ln -sf /usr/local/srs-cloud/platform/containers/data /data - -# Setup the work directory to platform. -WORKDIR /usr/local/srs-cloud diff --git a/focal/Dockerfile b/focal/Dockerfile index 45c74097..e3535952 100644 --- a/focal/Dockerfile +++ b/focal/Dockerfile @@ -25,8 +25,7 @@ COPY --from=redis /usr/local/bin/redis-server /usr/local/bin/redis-server ENV PORT=":2024" NODE_ENV=production SRS_DOCKERIZED=true MGMT_DOCKER=true PLATFORM_DOCKER=true CLOUD=DOCKER # Create link for compatible reason. -RUN ln -sf /usr/local/srs-cloud /usr/local/srs-terraform && \ - mkdir -p /usr/local/lighthouse/softwares && \ +RUN mkdir -p /usr/local/lighthouse/softwares && \ ln -sf /usr/local/srs-cloud /usr/local/lighthouse/softwares/srs-cloud # Setup the work directory to platform. diff --git a/platform/containers/conf/conf.d/nginx.http.conf b/platform/containers/conf/conf.d/nginx.http.conf deleted file mode 100644 index b96a4711..00000000 --- a/platform/containers/conf/conf.d/nginx.http.conf +++ /dev/null @@ -1,4 +0,0 @@ -# !!! Important: SRS will restore this file during each restart, please never modify it. - -# Configurations apply to http section. - diff --git a/platform/containers/conf/conf.d/nginx.server.conf b/platform/containers/conf/conf.d/nginx.server.conf deleted file mode 100644 index 9dc181c9..00000000 --- a/platform/containers/conf/conf.d/nginx.server.conf +++ /dev/null @@ -1,8 +0,0 @@ -# !!! Important: SRS will restore this file during each restart, please never modify it. - -# Configurations apply to server section. -# Note that the SSL/TLS configuration is in nginx.dynamic.conf -listen 80 default_server; -listen [::]:80 default_server; -server_name localhost; - diff --git a/platform/containers/conf/default.d/00.default.conf b/platform/containers/conf/default.d/00.default.conf deleted file mode 100644 index 55f6a9a0..00000000 --- a/platform/containers/conf/default.d/00.default.conf +++ /dev/null @@ -1,6 +0,0 @@ -# !!! Important: SRS will restore this file during each restart, please never modify it. - -error_page 500 502 503 504 /50x.html; -location = /50x.html { -} - diff --git a/platform/containers/conf/default.d/10.mgmt.conf b/platform/containers/conf/default.d/10.mgmt.conf deleted file mode 100644 index 7755947c..00000000 --- a/platform/containers/conf/default.d/10.mgmt.conf +++ /dev/null @@ -1,19 +0,0 @@ -# !!! Important: SRS will restore this file during each restart, please never modify it. - -# For mgmt console ui and API. -location /mgmt/ { - proxy_pass http://127.0.0.1:2024$request_uri; -} -location /terraform/v1/mgmt/ { - proxy_pass http://127.0.0.1:2024$request_uri; -} -# For mgmt and market APIs. -location /terraform/v1/ { - proxy_pass http://127.0.0.1:2024$request_uri; -} - -# For static resources of website. -location /favicon.ico { - proxy_pass http://127.0.0.1:2024$request_uri; -} - diff --git a/platform/containers/conf/default.d/20.srs.conf b/platform/containers/conf/default.d/20.srs.conf deleted file mode 100644 index 314c60e7..00000000 --- a/platform/containers/conf/default.d/20.srs.conf +++ /dev/null @@ -1,19 +0,0 @@ -# !!! Important: SRS will restore this file during each restart, please never modify it. - -# For SRS homepage, console and players -# http://r.ossrs.net/console/ -# http://r.ossrs.net/players/ -location ~ ^/(console|players)/ { - proxy_pass http://127.0.0.1:8080/$request_uri; -} -# For SRS streaming, for example: -# http://r.ossrs.net/live/livestream.flv -location ~ ^/.+/.*\.(flv)$ { - proxy_pass http://127.0.0.1:8080$request_uri; -} -# For SRS backend API for console. -# For SRS WebRTC publish/play API. -location ~ ^/(api|rtc)/ { - proxy_pass http://127.0.0.1:1985$request_uri; -} - diff --git a/platform/containers/conf/default.d/90.dvr.preview.conf b/platform/containers/conf/default.d/90.dvr.preview.conf deleted file mode 100644 index bebe5cad..00000000 --- a/platform/containers/conf/default.d/90.dvr.preview.conf +++ /dev/null @@ -1,8 +0,0 @@ -# !!! Important: SRS will restore this file during each restart, please never modify it. - -# For DVR to preview the progressing HLS, or MP4 file. -# See https://nginx.viraptor.info/ -location ~ ^/terraform/v1/.+/.*\.(flv|m3u8|ts|aac|mp3|mp4)$ { - proxy_pass http://127.0.0.1:2024$request_uri; -} - diff --git a/platform/containers/conf/nginx.conf b/platform/containers/conf/nginx.conf index b1006576..a55a6c7a 100644 --- a/platform/containers/conf/nginx.conf +++ b/platform/containers/conf/nginx.conf @@ -32,9 +32,24 @@ http { include /etc/nginx/mime.types; default_type application/octet-stream; - # Load modular configuration files from the /etc/nginx/conf.d directory. - # See http://nginx.org/en/docs/ngx_core_module.html#include - # for more information. - include /etc/nginx/conf.d/*.conf; + #SRS-HTTP-START + include /data/config/nginx.http.conf; + #SRS-HTTP-END + + server { + listen 80 default_server; + server_name srs.cloud.local; + + #SRS-SERVER-START + include /data/config/nginx.server.conf; + #SRS-SERVER-END + + #SRS-PROXY-START + location / { + proxy_pass http://127.0.0.1:2022; + proxy_set_header Host $host; + } + #SRS-PROXY-END + } } diff --git a/platform/version.go b/platform/version.go index 0ad9c8bb..0b5c8c60 100644 --- a/platform/version.go +++ b/platform/version.go @@ -6,4 +6,4 @@ package main // The version for platform. -const version = "v1.0.301" +const version = "v1.0.302" diff --git a/releases/Dockerfile b/releases/Dockerfile index c0553e80..c5ed6a75 100644 --- a/releases/Dockerfile +++ b/releases/Dockerfile @@ -13,6 +13,5 @@ FROM ${ARCH}ossrs/srs-cloud:focal-1 AS dist COPY --from=build /g/releases/releases /usr/local/srs-cloud/releases/releases ENV PORT=":9000" -RUN ln -sf /usr/local/srs-cloud /usr/local/srs-terraform WORKDIR /usr/local/srs-cloud/releases CMD ["./releases"] diff --git a/releases/version.go b/releases/version.go index e55237e4..5aa0a146 100644 --- a/releases/version.go +++ b/releases/version.go @@ -6,7 +6,7 @@ package main // The latest version of SRS Cloud. -const latest = "v1.0.301" +const latest = "v1.0.302" // The api service version of SRS Cloud. const api = "v1.0.374" diff --git a/scripts/setup-aapanel/README.md b/scripts/setup-aapanel/README.md deleted file mode 100644 index c038f016..00000000 --- a/scripts/setup-aapanel/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# SRS Plugin for aaPanel - -To create a plugin for [aaPanel](https://www.aapanel.com). - -## Usage - -To create a `aapanel-srs_cloud.zip` by: - -```bash -bash auto/zip.sh -``` - -Upload the zip to aaPanel panel, and install SRS. - diff --git a/scripts/setup-aapanel/do_install.sh b/scripts/setup-aapanel/do_install.sh index 11b41f89..aefe5f88 100644 --- a/scripts/setup-aapanel/do_install.sh +++ b/scripts/setup-aapanel/do_install.sh @@ -89,10 +89,6 @@ Uninstall() { rm -rf $INSTALL_HOME echo "Remove install $INSTALL_HOME ok" - SRS_ALIAS=/usr/local/srs-terraform - rm -rf $SRS_HOME $SRS_ALIAS - echo "Remove srs home $SRS_HOME ok" - rm -f ~/credentials.txt echo "Remove credentials.txt" diff --git a/scripts/setup-bt/README.md b/scripts/setup-bt/README.md deleted file mode 100644 index 92846074..00000000 --- a/scripts/setup-bt/README.md +++ /dev/null @@ -1,30 +0,0 @@ -# SRS Plugin for BT - -To create a plugin for [BT](https://bt.cn). - -## Usage - -To create a `bt-srs_cloud.zip` by: - -```bash -bash auto/zip.sh -``` - -Upload the zip to BT panel, and install SRS. - -## Log - -Install log saved at `/tmp/srs_cloud_install.log` - -```bash -cat /tmp/srs_cloud_install.log -``` - -When install SRS ready, there should be a file at: - -```bash -ls -lh /www/server/panel/plugin/srs_cloud/.bt_ready -``` - -> Note: If not ready, you're not able to install srs cloud in BT or aaPanel. - diff --git a/scripts/setup-bt/do_install.sh b/scripts/setup-bt/do_install.sh index 11b41f89..aefe5f88 100644 --- a/scripts/setup-bt/do_install.sh +++ b/scripts/setup-bt/do_install.sh @@ -89,10 +89,6 @@ Uninstall() { rm -rf $INSTALL_HOME echo "Remove install $INSTALL_HOME ok" - SRS_ALIAS=/usr/local/srs-terraform - rm -rf $SRS_HOME $SRS_ALIAS - echo "Remove srs home $SRS_HOME ok" - rm -f ~/credentials.txt echo "Remove credentials.txt" diff --git a/scripts/setup-droplet/README.md b/scripts/setup-droplet/README.md deleted file mode 100644 index a8c1ba6d..00000000 --- a/scripts/setup-droplet/README.md +++ /dev/null @@ -1,42 +0,0 @@ -# Setup Droplet Image - -To build SRS droplet image for [DigitalOcean Marketplace](https://marketplace.digitalocean.com/). - -## Usage - -First of all, please create a [token](https://cloud.digitalocean.com/account/api/tokens) and setup the env -`DIGITALOCEAN_TOKEN`, for example: - -```bash -export DIGITALOCEAN_TOKEN=xxx -``` - -Then [install Packer](https://www.packer.io/intro/getting-started/install.html): - -```bash -brew tap hashicorp/tap -brew install hashicorp/tap/packer -``` - -Next, install the plugin: - -```bash -PACKER_LOG=1 packer plugins install \ - github.com/digitalocean/digitalocean v1.1.1 -``` - -Finally, start to build SRS image by: - -```bash -packer build srs.json -``` - -or from root: - -```bash -cd scripts/setup-droplet -PACKER_LOG=1 packer build srs.json -``` - -Please check the [snapshot](https://cloud.digitalocean.com/images/snapshots/droplets). - diff --git a/scripts/setup-droplet/files/etc/update-motd.d/99-one-click b/scripts/setup-droplet/files/etc/update-motd.d/99-one-click index f0ed84f5..40e2e0f6 100755 --- a/scripts/setup-droplet/files/etc/update-motd.d/99-one-click +++ b/scripts/setup-droplet/files/etc/update-motd.d/99-one-click @@ -24,5 +24,5 @@ On the server: For help and more information, visit https://discord.gg/bQUPDRqy79 ******************************************************************************** -To delete this message of the day: rm -rf $(readlink -f ${0}) +To delete this message of the day: rm -f $(readlink -f ${0}) EOF diff --git a/scripts/setup-droplet/scripts/00-ubuntu.sh b/scripts/setup-droplet/scripts/00-ubuntu.sh index cc4e9486..391e1e95 100644 --- a/scripts/setup-droplet/scripts/00-ubuntu.sh +++ b/scripts/setup-droplet/scripts/00-ubuntu.sh @@ -1,39 +1,43 @@ #!/bin/bash -# Ignore darwin -if [[ $(uname -s) == 'Darwin' ]]; then - echo "Mac is not supported"; exit 1; -fi - -# The main directory. -SRS_HOME=/usr/local/srs-cloud -DEPLOY_HOME=$(dirname ${SRS_HOME}) +# Update sysctl.conf and add if not exists. For example: +# update_sysctl net.ipv4.ip_forward 1 0 "# Controls IP packet forwarding" +function update_sysctl() { + SYSCTL_KEY=$1 && SYSCTL_VALUE=$2 && SYSCTL_EMPTY_LINE=$3 && SYSCTL_COMMENTS=$4 + echo "Update with sysctl $SYSCTL_KEY=$SYSCTL_VALUE, empty-line=$SYSCTL_EMPTY_LINE, comment=$SYSCTL_COMMENTS" + + grep -q "^${SYSCTL_KEY}[ ]*=" /etc/sysctl.conf + if [[ $? == 0 ]]; then + sed -i "s/^${SYSCTL_KEY}[ ]*=.*$/${SYSCTL_KEY} = ${SYSCTL_VALUE}/g" /etc/sysctl.conf + else + if [[ $SYSCTL_EMPTY_LINE == 1 ]]; then echo '' >> /etc/sysctl.conf; fi && + if [[ $SYSCTL_COMMENTS != '' ]]; then echo "$SYSCTL_COMMENTS" >> /etc/sysctl.conf; fi && + echo "${SYSCTL_KEY} = ${SYSCTL_VALUE}" >> /etc/sysctl.conf + fi + if [[ $? -ne 0 ]]; then echo "Failed to sysctl $SYSCTL_KEY = $SYSCTL_VALUE $SYSCTL_COMMENTS"; exit 1; fi + + RESULT=$(grep "^${SYSCTL_KEY}[ ]*=" /etc/sysctl.conf) + echo "Update done: ${RESULT}" +} + +# Check OS first, only support CentOS or Ubuntu +apt-get --version >/dev/null 2>&1 && OS_NAME='Ubuntu' +if [[ -z $OS_NAME ]]; then echo "Only support Ubuntu"; exit 1; fi echo "Install depends" +apt-get update -y && apt-get install -y git gcc g++ gdb make tree dstat docker docker.io nginx curl net-tools && apt-get -qqy clean if [[ $? -ne 0 ]]; then echo "Install depends failed"; exit 1; fi -echo "Create nginx directory" -mkdir -p /etc/nginx/default.d /etc/nginx/conf.d -if [[ $? -ne 0 ]]; then echo "Copy srs-cloud failed"; exit 1; fi - -echo "Install srs-cloud" -mkdir -p ${DEPLOY_HOME} && cd ${DEPLOY_HOME} -if [[ $? -ne 0 ]]; then echo "Copy srs-cloud failed"; exit 1; fi - -# When droplet created, it might fail as: -# gnutls_handshake() failed: The TLS connection was non-properly terminated. -# so we try to wait for a while and try later. -for ((i=0; i<30; i++)); do - rm -rf srs-cloud && git clone -b main https://github.com/ossrs/srs-cloud.git && GIT_DONE=YES - if [[ $? -eq 0 ]]; then break; fi - echo "Ignore error and try later..."; sleep 3; -done -if [[ $GIT_DONE != YES ]]; then - echo "Clone srs-cloud failed"; exit 1; -fi - -cd ${DEPLOY_HOME} && rm -rf srs-terraform && ln -sf srs-cloud srs-terraform -if [[ $? -ne 0 ]]; then echo "Link srs-cloud failed"; exit 1; fi +# Allow network forwarding, required by docker. +# See https://stackoverflow.com/a/41453306/17679565 +update_sysctl net.ipv4.ip_forward 1 1 "# Controls IP packet forwarding" + +# Setup the UDP buffer for WebRTC and SRT. +# See https://www.jianshu.com/p/6d4a89359352 +update_sysctl net.core.rmem_max 16777216 1 "# For RTC/SRT over UDP" +update_sysctl net.core.rmem_default 16777216 +update_sysctl net.core.wmem_max 16777216 +update_sysctl net.core.wmem_default 16777216 diff --git a/scripts/setup-droplet/scripts/01-srs.sh b/scripts/setup-droplet/scripts/01-srs.sh index 329a716e..7e75ea47 100644 --- a/scripts/setup-droplet/scripts/01-srs.sh +++ b/scripts/setup-droplet/scripts/01-srs.sh @@ -1,39 +1,84 @@ #!/bin/bash -# Ignore darwin -if [[ $(uname -s) == 'Darwin' ]]; then - echo "Mac is not supported"; exit 1; -fi - # The main directory. SRS_HOME=/usr/local/srs-cloud DATA_HOME=/data +IMAGE_URL=docker.io/ossrs/srs-cloud:1 + +# When droplet created, it might fail as: +# gnutls_handshake() failed: The TLS connection was non-properly terminated. +# so we try to wait for a while and try later. +SOURCE=/tmp/srs-cloud +echo "Install srs-cloud at $SOURCE" +for ((i=0; i<30; i++)); do + cd $(dirname $SOURCE) && rm -rf srs-cloud && + git clone -b main --depth 1 https://github.com/ossrs/srs-cloud.git && + GIT_DONE=YES + if [[ $? -eq 0 ]]; then break; fi + echo "Ignore error and try later..."; sleep 3; +done +if [[ $GIT_DONE != YES ]]; then + echo "Clone srs-cloud failed"; exit 1; +fi + +# Setup the nginx configuration. +rm -f /etc/nginx/nginx.conf && +cp ${SOURCE}/platform/containers/conf/nginx.conf /etc/nginx/nginx.conf && +sed -i "s/user nginx;/user www-data;/g" /etc/nginx/nginx.conf +if [[ $? -ne 0 ]]; then echo "Setup nginx config failed"; exit 1; fi # Install files to lighthouse directory. -cd ${SRS_HOME} && make install +mkdir -p ${SRS_HOME} ${DATA_HOME} && rm -rf ${SRS_HOME}/* && +cp -r ${SOURCE}/usr ${SRS_HOME}/usr && +cp ${SOURCE}/LICENSE ${SRS_HOME}/LICENSE && +cp ${SOURCE}/README.md ${SRS_HOME}/README.md && +mkdir -p ${SRS_HOME}/mgmt && +cp ${SOURCE}/mgmt/bootstrap ${SRS_HOME}/mgmt/bootstrap && +rm -rf $SOURCE if [[ $? -ne 0 ]]; then echo "Copy srs-cloud failed"; exit 1; fi -######################################################################################################################## -# Cache the docker images for srs-cloud to startup faster. -systemctl start docker && +echo "Start to create data and config files" +mkdir -p ${DATA_HOME}/config && touch ${DATA_HOME}/config/.env && +touch ${DATA_HOME}/config/nginx.http.conf && +touch ${DATA_HOME}/config/nginx.server.conf +if [[ $? -ne 0 ]]; then echo "Create /data/config failed"; exit 1; fi +echo "Create data and config files ok" + +echo "Start to update bootstrap" +sed -i "s|^DATA_HOME=.*|DATA_HOME=${DATA_HOME}|g" ${SRS_HOME}/mgmt/bootstrap && +sed -i "s|^IMAGE=.*|IMAGE=${IMAGE_URL}|g" ${SRS_HOME}/mgmt/bootstrap +if [[ $? -ne 0 ]]; then echo "Update bootstrap failed"; exit 1; fi +echo "Update bootstrap ok" + +# Choose default language. +echo "Start to setup .env" +if [[ -f ${DATA_HOME}/config/.env && -s ${DATA_HOME}/config/.env ]]; then + echo "The .env already exists, skip" +else + cat << END > ${DATA_HOME}/config/.env +CLOUD=DO +REACT_APP_LOCALE=en +IMAGE=${IMAGE_URL} +# Please use BT to configure the domain and HTTPS. +SRS_HTTPS=off +END + if [[ $? -ne 0 ]]; then echo "Setup .env failed"; exit 1; fi +fi + +# Update the docker images. echo "Cache docker images" && -docker pull docker.io/ossrs/srs-cloud:platform-1 -if [[ $? -ne 0 ]]; then echo "Cache docker images failed"; exit 1; fi +if [[ $(docker images --format "{{.Repository}}:{{.Tag}}" ${IMAGE_URL} |wc -l) -eq 1 ]]; then + echo "Docker images ${IMAGE_URL} exists, skip pull" +else + docker pull ${IMAGE_URL} + if [[ $? -ne 0 ]]; then echo "Cache docker images failed"; exit 1; fi +fi # If install ok, the directory should exists. -if [[ ! -d ${SRS_HOME} || ! -d ${SRS_HOME}/mgmt ]]; then +if [[ ! -d ${SRS_HOME} ]]; then echo "Install srs-cloud failed"; exit 1; fi -# Compatible with previous version. -cd $(dirname $SRS_HOME) && rm -rf srs-terraform && ln -sf srs-cloud srs-terraform -if [[ $? -ne 0 ]]; then echo "Link srs-cloud failed"; exit 1; fi - -# Setup data directory. -mkdir -p ${DATA_HOME}/config && touch ${DATA_HOME}/config/.env && -rm -rf ${SRS_HOME}/mgmt/containers/data && ln -sf ${DATA_HOME} ${SRS_HOME}/mgmt/containers/data -if [[ $? -ne 0 ]]; then echo "Link srs-cloud failed"; exit 1; fi - # Create srs-cloud service, and the credential file. # Remark: Never start the service, because the IP will change for new machine created. cd ${SRS_HOME} && @@ -41,74 +86,5 @@ cp -f usr/lib/systemd/system/srs-cloud.service /usr/lib/systemd/system/srs-cloud systemctl enable srs-cloud if [[ $? -ne 0 ]]; then echo "Install srs-cloud failed"; exit 1; fi -# Choose default language. -cat << END > ${DATA_HOME}/config/.env -CLOUD=DO -REACT_APP_LOCALE=en -END -if [[ $? -ne 0 ]]; then echo "Setup language failed"; exit 1; fi - -# Setup the nginx configuration. -rm -f /etc/nginx/nginx.conf && -ln -sf ${SRS_HOME}/mgmt/containers/conf/nginx.conf /etc/nginx/nginx.conf -if [[ $? -ne 0 ]]; then echo "Setup nginx config failed"; exit 1; fi - -# For DO Ubuntu20, use www-data as nginx user. -echo "Switch to user www-data for nginx" && -sed -i "s/user nginx;/user www-data;/g" /etc/nginx/nginx.conf -if [[ $? -ne 0 ]]; then echo "Setup nginx.conf failed"; exit 1; fi - -# Build the mgmt/containers/conf/conf.d/nginx.vhost.conf -cd ${SRS_HOME}/mgmt && bash auto/setup_vhost -if [[ $? -ne 0 ]]; then echo "Build nginx vhost failed"; exit 1; fi - -cd ${SRS_HOME}/mgmt && -rm -f /etc/nginx/conf.d/nginx.vhost.conf /etc/nginx/conf.d/server.conf && -ln -sf ${SRS_HOME}/mgmt/containers/conf/conf.d/nginx.vhost.conf /etc/nginx/conf.d/vhost.conf -if [[ $? -ne 0 ]]; then echo "Reload nginx failed"; exit 1; fi - -# Setup git alias to make it convenient. -cd ${SRS_HOME}/mgmt && -echo "Setup git alias to make it more convenient" && -git config --local alias.co checkout && -git config --local alias.br branch && -git config --local alias.ci commit && -git config --local alias.st status -if [[ $? -ne 0 ]]; then echo "Setup git alias failed"; exit 1; fi - -# Update sysctl.conf and add if not exists. For example: -# update_sysctl net.ipv4.ip_forward 1 0 "# Controls IP packet forwarding" -function update_sysctl() { - SYSCTL_KEY=$1 && SYSCTL_VALUE=$2 && SYSCTL_EMPTY_LINE=$3 && SYSCTL_COMMENTS=$4 - echo "Update with sysctl $SYSCTL_KEY=$SYSCTL_VALUE, empty-line=$SYSCTL_EMPTY_LINE, comment=$SYSCTL_COMMENTS" - - grep -q "^${SYSCTL_KEY}[ ]*=" /etc/sysctl.conf - if [[ $? == 0 ]]; then - sed -i "s/^${SYSCTL_KEY}[ ]*=.*$/${SYSCTL_KEY} = ${SYSCTL_VALUE}/g" /etc/sysctl.conf - else - if [[ $SYSCTL_EMPTY_LINE == 1 ]]; then echo '' >> /etc/sysctl.conf; fi && - if [[ $SYSCTL_COMMENTS != '' ]]; then echo "$SYSCTL_COMMENTS" >> /etc/sysctl.conf; fi && - echo "${SYSCTL_KEY} = ${SYSCTL_VALUE}" >> /etc/sysctl.conf - fi - if [[ $? -ne 0 ]]; then echo "Failed to sysctl $SYSCTL_KEY = $SYSCTL_VALUE $SYSCTL_COMMENTS"; exit 1; fi - - RESULT=$(grep "^${SYSCTL_KEY}[ ]*=" /etc/sysctl.conf) - echo "Update done: ${RESULT}" -} - -# Allow network forwarding, required by docker. -# See https://stackoverflow.com/a/41453306/17679565 -update_sysctl net.ipv4.ip_forward 1 1 "# Controls IP packet forwarding" - -# Setup the UDP buffer for WebRTC and SRT. -# See https://www.jianshu.com/p/6d4a89359352 -update_sysctl net.core.rmem_max 16777216 1 "# For RTC/SRT over UDP" -update_sysctl net.core.rmem_default 16777216 -update_sysctl net.core.wmem_max 16777216 -update_sysctl net.core.wmem_default 16777216 - -######################################################################################################################## -# Setup the mod and link. -rm -rf /root/credentials.txt && ln -sf ${DATA_HOME}/config/.env /root/credentials.txt && -if [[ $? -ne 0 ]]; then echo "Link files failed"; exit 1; fi +echo 'Install OK' diff --git a/scripts/setup-droplet/srs.json b/scripts/setup-droplet/srs.json index 5fba7a09..25d77e3f 100644 --- a/scripts/setup-droplet/srs.json +++ b/scripts/setup-droplet/srs.json @@ -1,9 +1,9 @@ { "variables": { "do_token": "{{env `DIGITALOCEAN_TOKEN`}}", - "image_name": "srs-4-snapshot-{{timestamp}}", + "image_name": "srs-5-snapshot-{{timestamp}}", "application_name": "SRS", - "application_version": "4.6.15" + "application_version": "5.7.18" }, "sensitive-variables": ["do_token"], "builders": [ diff --git a/scripts/setup-lighthouse/README.md b/scripts/setup-lighthouse/README.md deleted file mode 100644 index 0328c0d2..00000000 --- a/scripts/setup-lighthouse/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# Setup LightHouse Image - -To build SRS LightHouse/CVM image for [Tencent Cloud](https://cloud.tencent.com/). - -## Usage - -Run the script: - -```bash -bash $prjHome/vendor/srs-terraform/scripts/setup-lighthouse/setup_lighthouse.sh -``` - -Please follow internal setup project. - diff --git a/scripts/setup-lighthouse/setup_lighthouse.sh b/scripts/setup-lighthouse/setup_lighthouse.sh index d7937dd9..c129dde2 100755 --- a/scripts/setup-lighthouse/setup_lighthouse.sh +++ b/scripts/setup-lighthouse/setup_lighthouse.sh @@ -49,14 +49,11 @@ cd ${SRS_HOME} && make build && make install if [[ $? -ne 0 ]]; then echo "Copy srs-cloud failed"; exit 1; fi -cd $DEPLOY_HOME && rm -rf srs-terraform && ln -sf srs-cloud srs-terraform -if [[ $? -ne 0 ]]; then echo "Link srs-cloud failed"; exit 1; fi - ######################################################################################################################## # Cache the docker images for srs-cloud to startup faster. systemctl start docker && echo "Cache docker images" && -docker pull registry.cn-hangzhou.aliyuncs.com/ossrs/srs-cloud:platform-1 +docker pull registry.cn-hangzhou.aliyuncs.com/ossrs/srs-cloud:1 if [[ $? -ne 0 ]]; then echo "Cache docker images failed"; exit 1; fi # If install ok, the directory should exists. @@ -64,10 +61,6 @@ if [[ ! -d ${INSTALL_HOME} || ! -d ${INSTALL_HOME}/mgmt ]]; then echo "Install srs-cloud failed"; exit 1; fi -# Compatible with previous version. -cd $(dirname $INSTALL_HOME) && rm -rf srs-terraform && ln -sf srs-cloud srs-terraform -if [[ $? -ne 0 ]]; then echo "Link srs-cloud failed"; exit 1; fi - # Create global data directory. echo "Create data and config file" mkdir -p ${DATA_HOME}/config && touch ${DATA_HOME}/config/.env && diff --git a/Dockerfile.script b/scripts/setup-ubuntu/Dockerfile.script similarity index 100% rename from Dockerfile.script rename to scripts/setup-ubuntu/Dockerfile.script