diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1920f4a..4561bd2 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -12,6 +12,11 @@ on: type: boolean description: "Use base image testpr" default: false + build_latest_as_test: + required: false + type: boolean + description: "Build latest as test" + default: false # Build and deploy the image on pushes to main branch push: @@ -44,8 +49,164 @@ jobs: run: | echo "Workflow dispatch reason: $INPUTS_REASON" echo "Use test image: $INPUTS_USE_TEST_IMAGE" + binary_build_armv7: + name: Build Binary - armv7 + runs-on: ubuntu-latest + # needs: test_rust_functionality + + steps: + - name: Checkout + uses: actions/checkout@v4.1.1 + with: + fetch-depth: 0 + repository: sdr-enthusiasts/acars-bridge + + - name: Run Docker on tmpfs + uses: JonasAlfredsson/docker-on-tmpfs@v1 + with: + tmpfs_size: 5 + swap_size: 4 + swap_location: "/mnt/swapfile" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build armv7 + uses: docker/build-push-action@v5 + with: + context: . + push: false + file: Dockerfile.build_binary + tags: acars-bridge:armv7 + platforms: linux/arm/v7 + outputs: type=local,dest=./image_armv7/ + + - name: Upload artifact armv7 binary + uses: actions/upload-artifact@v4.0.0 + with: + name: acars-bridge.armv7 + path: ./image_armv7/acars-bridge + + binary_build_arm64: + name: Build Binary - arm64 + runs-on: ubuntu-latest + # needs: test_rust_functionality + + steps: + - name: Checkout + uses: actions/checkout@v4.1.1 + with: + fetch-depth: 0 + repository: sdr-enthusiasts/acars-bridge + + - name: Run Docker on tmpfs + uses: JonasAlfredsson/docker-on-tmpfs@v1 + with: + tmpfs_size: 5 + swap_size: 4 + swap_location: "/mnt/swapfile" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build arm64 + uses: docker/build-push-action@v5 + with: + context: . + push: false + file: Dockerfile.build_binary + tags: acars-bridge:arm64 + platforms: linux/arm64 + outputs: type=local,dest=./image_arm64/ + + - name: Upload artifact arm64 binary + uses: actions/upload-artifact@v4.0.0 + with: + name: acars-bridge.arm64 + path: ./image_arm64/acars-bridge + + binary_build_amd64: + name: Build Binary - amd64 + runs-on: ubuntu-latest + # needs: test_rust_functionality + + steps: + - name: Checkout + uses: actions/checkout@v4.1.1 + with: + fetch-depth: 0 + repository: sdr-enthusiasts/acars-bridge + + - name: Run Docker on tmpfs + uses: JonasAlfredsson/docker-on-tmpfs@v1 + with: + tmpfs_size: 5 + swap_size: 4 + swap_location: "/mnt/swapfile" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build amd64 + uses: docker/build-push-action@v5 + with: + context: . + push: false + file: Dockerfile.build_binary + tags: acars-bridge:amd64 + platforms: linux/amd64 + outputs: type=local,dest=./image_amd64/ + + - name: Upload artifact amd64 binary + uses: actions/upload-artifact@v4.0.0 + with: + name: acars-bridge.amd64 + path: ./image_amd64/acars-bridge + + consolidate_binaries: + name: Consolidate & Cache Binaries + runs-on: ubuntu-latest + needs: [binary_build_amd64, binary_build_arm64, binary_build_armv7] + steps: + - run: mkdir -p ./bin + + - uses: actions/download-artifact@v4.0.0 + with: + name: acars-bridge.amd64 + path: ./bin/acars-bridge.amd64 + + - uses: actions/download-artifact@v4.0.0 + with: + name: acars-bridge.armv7 + path: ./bin/acars-bridge.armv7 + + - uses: actions/download-artifact@v4.0.0 + with: + name: acars-bridge.arm64 + path: ./bin/acars-bridge.arm64 + + - run: ls -la ./bin/* + + - name: Cache Binaries + uses: actions/cache@v3 + with: + path: ./bin/ + key: ${{ github.run_id }} build_and_push: name: Image Build & Push + needs: [consolidate_binaries] + if: | + github.event.inputs.build_latest_as_test == 'false' || + github.event.inputs.build_latest_as_test == '' uses: sdr-enthusiasts/common-github-workflows/.github/workflows/build_and_push_image.yml@main with: push_enabled: true @@ -63,5 +224,37 @@ jobs: build_platform_specific: ${{ github.event.inputs.use_test_image == 'false' || github.event.inputs.use_test_image == '' }} build_nohealthcheck: ${{ github.event.inputs.use_test_image == 'false' || github.event.inputs.use_test_image == '' }} build_baseimage_url: :acars-decoder/:acars-decoder-test-pr + cache_enabled: true + cache_path: ./bin/ + cache_key: ${{ github.run_id }} + secrets: + ghcr_token: ${{ secrets.GITHUB_TOKEN }} + + deploy_test: + name: Deploy as test + needs: [consolidate_binaries] + if: | + github.event.inputs.build_latest_as_test == 'true' && + (github.event.inputs.use_test_image == 'false' || github.event.inputs.use_test_image == '') + uses: sdr-enthusiasts/common-github-workflows/.github/workflows/build_and_push_image.yml@main + with: + push_enabled: true + push_destinations: ghcr.io + ghcr_repo_owner: ${{ github.repository_owner }} + ghcr_repo: ${{ github.repository }} + build_with_tmpfs: true + get_version_method: git_commit_hash_short + # set build_latest to true if github.event.inputs.use_test_image is false + build_latest: true + docker_latest_tag: test + build_baseimage_test: false + # only build the entire stack if we are not using the test image + build_version_specific: false + build_platform_specific: false + build_nohealthcheck: false + build_baseimage_url: :acars-decoder/:acars-decoder-test-pr + cache_enabled: true + cache_path: ./bin/ + cache_key: ${{ github.run_id }} secrets: ghcr_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml index a784085..fce0557 100644 --- a/.github/workflows/test-pr.yml +++ b/.github/workflows/test-pr.yml @@ -1,64 +1,196 @@ -name: Test PR +name: Deploy -# FIXME: Can we not build either job if stuff has been unchanged since last commit for that job? -# FIXME: Use branch name for tagging docker build on: - pull_request: + # Build and deploy the image on pushes to main branch + push: branches: - main paths: - - rootfs/** - - .github/workflows/test-pr.yml + - "rust/**" + - "Dockerfile" + - "Dockerfile.build_binary" + - "rootfs/**" env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} jobs: - deploy_ghcr_latest: - name: Deploy Test to ghcr.io + binary_build_armv7: + name: Build Binary - armv7 runs-on: ubuntu-latest - permissions: - contents: read - packages: write + # needs: test_rust_functionality steps: - # Check out our code - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v4.1.1 + with: + fetch-depth: 0 + repository: sdr-enthusiasts/acars-bridge + + - name: Run Docker on tmpfs + uses: JonasAlfredsson/docker-on-tmpfs@v1 + with: + tmpfs_size: 5 + swap_size: 4 + swap_location: "/mnt/swapfile" - # Set up QEMU for multi-arch builds - name: Set up QEMU uses: docker/setup-qemu-action@v3 - # Log into ghcr (so we can push images) - - name: Login to ghcr.io - uses: docker/login-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build armv7 + uses: docker/build-push-action@v5 + with: + context: . + push: false + file: Dockerfile.build_binary + tags: acars-bridge:armv7 + platforms: linux/arm/v7 + outputs: type=local,dest=./image_armv7/ + + - name: Upload artifact armv7 binary + uses: actions/upload-artifact@v4.0.0 + with: + name: acars-bridge.armv7 + path: ./image_armv7/acars-bridge + + binary_build_arm64: + name: Build Binary - arm64 + runs-on: ubuntu-latest + # needs: test_rust_functionality + + steps: + - name: Checkout + uses: actions/checkout@v4.1.1 + with: + fetch-depth: 0 + repository: sdr-enthusiasts/acars-bridge + + - name: Run Docker on tmpfs + uses: JonasAlfredsson/docker-on-tmpfs@v1 + with: + tmpfs_size: 5 + swap_size: 4 + swap_location: "/mnt/swapfile" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build arm64 + uses: docker/build-push-action@v5 + with: + context: . + push: false + file: Dockerfile.build_binary + tags: acars-bridge:arm64 + platforms: linux/arm64 + outputs: type=local,dest=./image_arm64/ + + - name: Upload artifact arm64 binary + uses: actions/upload-artifact@v4.0.0 + with: + name: acars-bridge.arm64 + path: ./image_arm64/acars-bridge + + binary_build_amd64: + name: Build Binary - amd64 + runs-on: ubuntu-latest + # needs: test_rust_functionality + + steps: + - name: Checkout + uses: actions/checkout@v4.1.1 with: - registry: ${{ env.REGISTRY }} - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} + fetch-depth: 0 + repository: sdr-enthusiasts/acars-bridge - # Get metadata from repo - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v5 + - name: Run Docker on tmpfs + uses: JonasAlfredsson/docker-on-tmpfs@v1 with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tmpfs_size: 5 + swap_size: 4 + swap_location: "/mnt/swapfile" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 - # Set up buildx for multi platform builds - name: Set up Docker Buildx - id: buildx uses: docker/setup-buildx-action@v3 - # Build & Push Dockerfile (test) - - name: Build & Push ghcr.io/sdr-enthusiasts/docker-acarsdec:test + - name: Build amd64 uses: docker/build-push-action@v5 with: context: . - file: ./Dockerfile - no-cache: true - platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm/v6,linux/arm64 - push: true - tags: ghcr.io/sdr-enthusiasts/docker-acarsdec:test - labels: ${{ steps.meta.outputs.labels }} + push: false + file: Dockerfile.build_binary + tags: acars-bridge:amd64 + platforms: linux/amd64 + outputs: type=local,dest=./image_amd64/ + + - name: Upload artifact amd64 binary + uses: actions/upload-artifact@v4.0.0 + with: + name: acars-bridge.amd64 + path: ./image_amd64/acars-bridge + + consolidate_binaries: + name: Consolidate & Cache Binaries + runs-on: ubuntu-latest + needs: [binary_build_amd64, binary_build_arm64, binary_build_armv7] + steps: + - run: mkdir -p ./bin + + - uses: actions/download-artifact@v4.0.0 + with: + name: acars-bridge.amd64 + path: ./bin/acars-bridge.amd64 + + - uses: actions/download-artifact@v4.0.0 + with: + name: acars-bridge.armv7 + path: ./bin/acars-bridge.armv7 + + - uses: actions/download-artifact@v4.0.0 + with: + name: acars-bridge.arm64 + path: ./bin/acars-bridge.arm64 + + - run: ls -la ./bin/* + + - name: Cache Binaries + uses: actions/cache@v3 + with: + path: ./bin/ + key: ${{ github.run_id }} + + deploy_test: + name: Deploy as test + needs: [consolidate_binaries] + uses: sdr-enthusiasts/common-github-workflows/.github/workflows/build_and_push_image.yml@main + with: + push_enabled: false + push_destinations: ghcr.io + ghcr_repo_owner: ${{ github.repository_owner }} + ghcr_repo: ${{ github.repository }} + build_with_tmpfs: true + get_version_method: git_commit_hash_short + # set build_latest to true if github.event.inputs.use_test_image is false + build_latest: true + docker_latest_tag: test + build_baseimage_test: false + # only build the entire stack if we are not using the test image + build_version_specific: false + build_platform_specific: false + build_nohealthcheck: false + build_baseimage_url: :acars-decoder/:acars-decoder-test-pr + cache_enabled: true + cache_path: ./bin/ + cache_key: ${{ github.run_id }} + secrets: + ghcr_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/Dockerfile b/Dockerfile index b1663c5..2fbbcb0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,11 +9,16 @@ ENV DEVICE_INDEX="" \ RTLMULT="160" \ SERIAL="" \ SOAPYSDR="" \ - SERVER="acarshub" \ - SERVER_PORT="5550" \ + OUTPUT_SERVER="acars_router" \ + OUTPUT_SERVER_PORT="5550" \ + OUTPUT_SERVER_MODE="udp" \ MODE="J" SHELL ["/bin/bash", "-o", "pipefail", "-c"] +COPY ./rootfs / +COPY ./bin/acars-bridge.armv7/acars-bridge /opt/acars-bridge.armv7 +COPY ./bin/acars-bridge.arm64/acars-bridge /opt/acars-bridge.arm64 +COPY ./bin/acars-bridge.amd64/acars-bridge /opt/acars-bridge.amd64 # hadolint ignore=DL3008,SC2086,SC2039 RUN set -x && \ @@ -29,11 +34,23 @@ RUN set -x && \ TEMP_PACKAGES+=(wget) && \ TEMP_PACKAGES+=(libusb-1.0-0-dev) && \ KEPT_PACKAGES+=(libusb-1.0-0) && \ + KEPT_PACKAGES+=(libzmq5) && \ # install packages apt-get update && \ apt-get install -y --no-install-recommends \ "${KEPT_PACKAGES[@]}" \ "${TEMP_PACKAGES[@]}" && \ + # ensure binaries are executable + chmod -v a+x \ + /opt/acars-bridge.armv7 \ + /opt/acars-bridge.arm64 \ + /opt/acars-bridge.amd64 \ + && \ + # remove foreign architecture binaries + /rename_current_arch_binary.sh && \ + rm -fv \ + /opt/acars-bridge.* \ + && \ # install sdrplay curl --location --output /tmp/install_sdrplay.sh https://raw.githubusercontent.com/sdr-enthusiasts/install-libsdrplay/main/install_sdrplay.sh && \ chmod +x /tmp/install_sdrplay.sh && \ @@ -48,6 +65,8 @@ RUN set -x && \ make install && \ ldconfig && \ popd && popd && \ + # remove the source code + rm -rf /src/airspyone_host && \ # Deploy SoapySDR git clone https://github.com/pothosware/SoapySDR.git /src/SoapySDR && \ pushd /src/SoapySDR && \ @@ -61,6 +80,8 @@ RUN set -x && \ make install && \ popd && popd && \ ldconfig && \ + # remove the source code + rm -rf /src/SoapySDR && \ # Deploy SoapyRTLTCP git clone https://github.com/pothosware/SoapyRTLTCP.git /src/SoapyRTLTCP && \ pushd /src/SoapyRTLTCP && \ @@ -71,6 +92,8 @@ RUN set -x && \ make install && \ popd && popd && \ ldconfig && \ + # remove the source code + rm -rf /src/SoapyRTLTCP && \ # Deploy SoapyRTLSDR git clone https://github.com/pothosware/SoapyRTLSDR.git /src/SoapyRTLSDR && \ pushd /src/SoapyRTLSDR && \ @@ -83,6 +106,8 @@ RUN set -x && \ make install && \ popd && popd && \ ldconfig && \ + # remove the source code + rm -rf /src/SoapyRTLSDR && \ # install sdrplay support for soapy git clone https://github.com/pothosware/SoapySDRPlay.git /src/SoapySDRPlay && \ pushd /src/SoapySDRPlay && \ @@ -94,6 +119,8 @@ RUN set -x && \ popd && \ popd && \ ldconfig && \ + # remove the source code + rm -rf /src/SoapySDRPlay && \ # Deploy Airspy git clone https://github.com/pothosware/SoapyAirspy.git /src/SoapyAirspy && \ pushd /src/SoapyAirspy && \ @@ -105,6 +132,8 @@ RUN set -x && \ popd && \ popd && \ ldconfig && \ + # remove the source code + rm -rf /src/SoapyAirspy && \ # acarsdec #git clone --depth 1 --single-branch --branch master https://github.com/TLeconte/acarsdec /src/acarsdec && \ git clone --depth 1 --single-branch --branch master https://github.com/wiedehopf/acarsdec.git /src/acarsdec && \ @@ -123,8 +152,6 @@ RUN set -x && \ apt-get autoremove -y && \ rm -rf /src/* /tmp/* /var/lib/apt/lists/* -COPY rootfs/ / - # ENTRYPOINT [ "/init" ] # Add healthcheck diff --git a/Dockerfile.local b/Dockerfile.local new file mode 100644 index 0000000..61476b8 --- /dev/null +++ b/Dockerfile.local @@ -0,0 +1,164 @@ +#build acars-bridge +FROM rust:1.75.0 as builder +WORKDIR /tmp/acars-bridge +# hadolint ignore=DL3008,DL3003,SC1091 +RUN set -x && \ + apt-get update && \ + apt-get install -y --no-install-recommends libzmq3-dev + +RUN set -x && \ + git clone https://github.com/sdr-enthusiasts/acars-bridge.git . && \ + cargo build --release && \ + # clean up the apt-cache + apt-get clean && \ + rm -rf /var/lib/apt/lists/* && \ + cp /tmp/acars-bridge/target/release/acars-bridge . && \ + cargo clean + + +FROM ghcr.io/sdr-enthusiasts/docker-baseimage:acars-decoder + +ENV DEVICE_INDEX="" \ + QUIET_LOGS="TRUE" \ + FREQUENCIES="" \ + FEED_ID="" \ + PPM="0"\ + GAIN="-10" \ + RTLMULT="160" \ + SERIAL="" \ + SOAPYSDR="" \ + OUTPUT_SERVER="acars_router" \ + OUTPUT_SERVER_PORT="5550" \ + OUTPUT_SERVER_MODE="udp" \ + MODE="J" + +SHELL ["/bin/bash", "-o", "pipefail", "-c"] + +# hadolint ignore=DL3008,SC2086,SC2039 +RUN set -x && \ + TEMP_PACKAGES=() && \ + KEPT_PACKAGES=() && \ + # Required for building multiple packages. + TEMP_PACKAGES+=(build-essential) && \ + TEMP_PACKAGES+=(pkg-config) && \ + TEMP_PACKAGES+=(cmake) && \ + TEMP_PACKAGES+=(git) && \ + TEMP_PACKAGES+=(automake) && \ + TEMP_PACKAGES+=(autoconf) && \ + TEMP_PACKAGES+=(wget) && \ + TEMP_PACKAGES+=(libusb-1.0-0-dev) && \ + KEPT_PACKAGES+=(libusb-1.0-0) && \ + KEPT_PACKAGES+=(libzmq5) && \ + # install packages + apt-get update && \ + apt-get install -y --no-install-recommends \ + "${KEPT_PACKAGES[@]}" \ + "${TEMP_PACKAGES[@]}" && \ + # install sdrplay + curl --location --output /tmp/install_sdrplay.sh https://raw.githubusercontent.com/sdr-enthusiasts/install-libsdrplay/main/install_sdrplay.sh && \ + chmod +x /tmp/install_sdrplay.sh && \ + /tmp/install_sdrplay.sh && \ + # deploy airspyone host + git clone https://github.com/airspy/airspyone_host.git /src/airspyone_host && \ + pushd /src/airspyone_host && \ + mkdir -p /src/airspyone_host/build && \ + pushd /src/airspyone_host/build && \ + cmake ../ -DINSTALL_UDEV_RULES=ON && \ + make && \ + make install && \ + ldconfig && \ + popd && popd && \ + # remove the source code + rm -rf /src/airspyone_host && \ + # Deploy SoapySDR + git clone https://github.com/pothosware/SoapySDR.git /src/SoapySDR && \ + pushd /src/SoapySDR && \ + BRANCH_SOAPYSDR=$(git tag --sort="creatordate" | tail -1) && \ + git checkout "$BRANCH_SOAPYSDR" && \ + mkdir -p /src/SoapySDR/build && \ + pushd /src/SoapySDR/build && \ + cmake ../ -DCMAKE_BUILD_TYPE=Debug && \ + make all && \ + make test && \ + make install && \ + popd && popd && \ + ldconfig && \ + # remove the source code + rm -rf /src/SoapySDR && \ + # Deploy SoapyRTLTCP + git clone https://github.com/pothosware/SoapyRTLTCP.git /src/SoapyRTLTCP && \ + pushd /src/SoapyRTLTCP && \ + mkdir -p /src/SoapyRTLTCP/build && \ + pushd /src/SoapyRTLTCP/build && \ + cmake ../ -DCMAKE_BUILD_TYPE=Debug && \ + make all && \ + make install && \ + popd && popd && \ + ldconfig && \ + # remove the source code + rm -rf /src/SoapyRTLTCP && \ + # Deploy SoapyRTLSDR + git clone https://github.com/pothosware/SoapyRTLSDR.git /src/SoapyRTLSDR && \ + pushd /src/SoapyRTLSDR && \ + BRANCH_SOAPYRTLSDR=$(git tag --sort="creatordate" | tail -1) && \ + git checkout "$BRANCH_SOAPYRTLSDR" && \ + mkdir -p /src/SoapyRTLSDR/build && \ + pushd /src/SoapyRTLSDR/build && \ + cmake ../ -DCMAKE_BUILD_TYPE=Debug && \ + make all && \ + make install && \ + popd && popd && \ + ldconfig && \ + # remove the source code + rm -rf /src/SoapyRTLSDR && \ + # install sdrplay support for soapy + git clone https://github.com/pothosware/SoapySDRPlay.git /src/SoapySDRPlay && \ + pushd /src/SoapySDRPlay && \ + mkdir build && \ + pushd build && \ + cmake .. && \ + make && \ + make install && \ + popd && \ + popd && \ + ldconfig && \ + # remove the source code + rm -rf /src/SoapySDRPlay && \ + # Deploy Airspy + git clone https://github.com/pothosware/SoapyAirspy.git /src/SoapyAirspy && \ + pushd /src/SoapyAirspy && \ + mkdir build && \ + pushd build && \ + cmake .. && \ + make && \ + make install && \ + popd && \ + popd && \ + ldconfig && \ + # remove the source code + rm -rf /src/SoapyAirspy && \ + # acarsdec + #git clone --depth 1 --single-branch --branch master https://github.com/TLeconte/acarsdec /src/acarsdec && \ + git clone --depth 1 --single-branch --branch master https://github.com/wiedehopf/acarsdec.git /src/acarsdec && \ + pushd /src/acarsdec && \ + #git checkout master && \ + #git checkout testing && \ + sed -i -e 's/-march=native//' CMakeLists.txt && \ + mkdir build && \ + pushd build && \ + cmake ../ -DCMAKE_BUILD_TYPE=Debug -Drtl=OFF -Dsdrplay=OFF -Dairspy=OFF -Dsoapy=ON && \ + make && \ + make install && \ + popd && popd && \ + # Clean up + apt-get remove -y "${TEMP_PACKAGES[@]}" && \ + apt-get autoremove -y && \ + rm -rf /src/* /tmp/* /var/lib/apt/lists/* + +COPY rootfs/ / +COPY --from=builder /tmp/acars-bridge/acars-bridge /opt/acars-bridge + +# ENTRYPOINT [ "/init" ] + +# Add healthcheck +HEALTHCHECK --start-period=3600s --interval=600s CMD /scripts/healthcheck.sh diff --git a/LICENSE b/LICENSE index 0c1ffcc..c506185 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 Fred Clausen +Copyright (C) 2022-2024 Fred Clausen Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index c071de9..c5a9c21 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ services: - SERIAL=13305 - FEED_ID=ACARS - FREQUENCIES=130.025;130.450;131.125;131.550 + - OUTPUT_SERVER_MODE=tcp tmpfs: - /run:exec,size=64M - /var/log @@ -52,18 +53,20 @@ services: ## Configuration options -| Variable | Description | Required | Default | -| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------------ | -| `TZ` | Your timezone | No | UTC | -| `SOAPYSDR` | The SoapySDR device string that identifies your dongle. See below for supported soapy sdr types. | No | Blank | -| `FEED_ID` | Used by the decoder to insert a unique ID in to the output message | Yes | Blank | -| `FREQUENCIES` | Colon-separated list of frequencies, but to a maximum of 8, for the decoder to list to | Yes | Blank | -| `PPM` | Parts per million correction of the decoder | No | 0 | -| `GAIN` | The gain applied to the RTL-SDR dongle. Recommended to leave at the default autogain. To set manually, gain in in db (0 to 49.6; >52 and -10 will result in AGC; default is AGC) | No | `-10` for autogain | -| `SERVER` | The server where messages will be forwarded to. | No | Blank | -| `SERVER_PORT` | The port where the server will receive messages on. | No | `5550` | -| `MODE` | The output mode. `P` for planeplotter, `J` for JSON and `A` for acarsdec. | No | `J` | -| `QUIET_LOGS` | Mute log output to the bare minimum. Set to `false` to see all of the log messages. | No | `TRUE` | +| Variable | Description | Required | Default | +| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------------ | +| `TZ` | Your timezone | No | UTC | +| `SOAPYSDR` | The SoapySDR device string that identifies your dongle. See below for supported soapy sdr types. | No | Blank | +| `FEED_ID` | Used by the decoder to insert a unique ID in to the output message | Yes | Blank | +| `FREQUENCIES` | Colon-separated list of frequencies, but to a maximum of 8, for the decoder to list to | Yes | Blank | +| `PPM` | Parts per million correction of the decoder | No | 0 | +| `GAIN` | The gain applied to the RTL-SDR dongle. Recommended to leave at the default autogain. To set manually, gain in in db (0 to 49.6; >52 and -10 will result in AGC; default is AGC) | No | `-10` for autogain | +| `OUTPUT_SERVER` | The server where messages will be forwarded to. | No | `acars_router` | +| `OUTPUT_SERVER_PORT` | The port where the server will receive messages on. | No | `5550` | +| `OUTPUT_SERVER_MODE` | The output mode. `udp`, `tcp` and `zmq` are valid | No | `udp` | +| `MODE` | The output mode. `P` for planeplotter, `J` for JSON and `A` for acarsdec. | No | `J` | +| `QUIET_LOGS` | Mute log output to the bare minimum. Set to `false` to see all of the log messages. | No | `TRUE` | +| `ACARSDEC_COMMAND_EXTRA` | Additional arguments to pass to the decoder. | No | Blank | ## SoapySDR device string @@ -75,3 +78,17 @@ Supported Soapy Drivers: - `rtltcp` - `airspy` - `sdrplay` + +## Output modes + +TL;DR: No change to your setup is necessary for continued functionality, but you should update your configuration to use the new variables and at least use TCP. + +A recent change in the container has meant we are migrating from `SERVER`/`SERVER_PORT` to `OUTPUT_SERVER`/`OUTPUT_SERVER_PORT` as a better name for what the variable is representing. The old variables will continue to work for the time being, but please update your configuration to use the new variables. Simply replace `SERVER` with `OUTPUT_SERVER` and `SERVER_PORT` with `OUTPUT_SERVER_PORT`. If you do not have `SERVER`/`SERVER_PORT` set, you do not need to do anything and it will work as it did before. + +Generally speaking for a proper migration, whatever your `SERVER` was before should be set in your compose as `OUTPUT_SERVER` and whatever your `SERVER_PORT` was before should be set as `OUTPUT_SERVER_PORT`. If `SERVER` was not set, you do not have to add in `OUTPUT_SERVER`. If you did not have `SERVER_PORT` set in your compose, you do not have to add in `OUTPUT_SERVER_PORT` unless you want to use `zmq`. + +Additionally, the `OUTPUT_SERVER_MODE` variable has been added to allow for the output mode to be set. The default is `udp` and the container will function as it did before. `tcp` and `zmq` are also valid options and recommended over `udp` for reliability. + +To use `tcp` with `acars_router` with the default ports it would have mapped, simply set `OUTPUT_SERVER_MODE=tcp` and leave the `OUTPUT_SERVER_PORT` as `5550` or unset. + +If you wish to use `zmq` with `acars_router` with the default ports it would have mapped, simply set `OUTPUT_SERVER_MODE=zmq` and set `OUTPUT_SERVER_PORT` as `35550`. diff --git a/rootfs/etc/s6-overlay/s6-rc.d/acars_feeder/dependencies.d/01-acarsdec b/rootfs/etc/s6-overlay/s6-rc.d/acars_bridge/dependencies.d/01-acarsdec similarity index 100% rename from rootfs/etc/s6-overlay/s6-rc.d/acars_feeder/dependencies.d/01-acarsdec rename to rootfs/etc/s6-overlay/s6-rc.d/acars_bridge/dependencies.d/01-acarsdec diff --git a/rootfs/etc/s6-overlay/s6-rc.d/acars_feeder/dependencies.d/03-sdrplay-license b/rootfs/etc/s6-overlay/s6-rc.d/acars_bridge/dependencies.d/03-sdrplay-license similarity index 100% rename from rootfs/etc/s6-overlay/s6-rc.d/acars_feeder/dependencies.d/03-sdrplay-license rename to rootfs/etc/s6-overlay/s6-rc.d/acars_bridge/dependencies.d/03-sdrplay-license diff --git a/rootfs/etc/s6-overlay/s6-rc.d/acars_bridge/run b/rootfs/etc/s6-overlay/s6-rc.d/acars_bridge/run new file mode 100755 index 0000000..a600547 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/acars_bridge/run @@ -0,0 +1,2 @@ +#!/bin/sh +exec /etc/s6-overlay/scripts/acars_bridge diff --git a/rootfs/etc/s6-overlay/s6-rc.d/acars_feeder/type b/rootfs/etc/s6-overlay/s6-rc.d/acars_bridge/type similarity index 100% rename from rootfs/etc/s6-overlay/s6-rc.d/acars_feeder/type rename to rootfs/etc/s6-overlay/s6-rc.d/acars_bridge/type diff --git a/rootfs/etc/s6-overlay/s6-rc.d/acars_feeder/run b/rootfs/etc/s6-overlay/s6-rc.d/acars_feeder/run deleted file mode 100755 index 83de848..0000000 --- a/rootfs/etc/s6-overlay/s6-rc.d/acars_feeder/run +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -exec /etc/s6-overlay/scripts/acars_feeder diff --git a/rootfs/etc/s6-overlay/s6-rc.d/acars_server/dependencies.d/03-sdrplay-license b/rootfs/etc/s6-overlay/s6-rc.d/acars_server/dependencies.d/03-sdrplay-license deleted file mode 100644 index e69de29..0000000 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/acars_server/run b/rootfs/etc/s6-overlay/s6-rc.d/acars_server/run deleted file mode 100755 index 07118a0..0000000 --- a/rootfs/etc/s6-overlay/s6-rc.d/acars_server/run +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -exec /etc/s6-overlay/scripts/acars_server diff --git a/rootfs/etc/s6-overlay/s6-rc.d/acars_server/type b/rootfs/etc/s6-overlay/s6-rc.d/acars_server/type deleted file mode 100644 index 5883cff..0000000 --- a/rootfs/etc/s6-overlay/s6-rc.d/acars_server/type +++ /dev/null @@ -1 +0,0 @@ -longrun diff --git a/rootfs/etc/s6-overlay/s6-rc.d/acars_stats/dependencies.d/01-acarsdec b/rootfs/etc/s6-overlay/s6-rc.d/acars_stats/dependencies.d/01-acarsdec deleted file mode 100644 index e69de29..0000000 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/acars_stats/dependencies.d/03-sdrplay-license b/rootfs/etc/s6-overlay/s6-rc.d/acars_stats/dependencies.d/03-sdrplay-license deleted file mode 100644 index e69de29..0000000 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/acars_stats/run b/rootfs/etc/s6-overlay/s6-rc.d/acars_stats/run deleted file mode 100755 index 5c4dc31..0000000 --- a/rootfs/etc/s6-overlay/s6-rc.d/acars_stats/run +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -exec /etc/s6-overlay/scripts/acars_stats diff --git a/rootfs/etc/s6-overlay/s6-rc.d/acars_stats/type b/rootfs/etc/s6-overlay/s6-rc.d/acars_stats/type deleted file mode 100644 index 5883cff..0000000 --- a/rootfs/etc/s6-overlay/s6-rc.d/acars_stats/type +++ /dev/null @@ -1 +0,0 @@ -longrun diff --git a/rootfs/etc/s6-overlay/s6-rc.d/acars_server/dependencies.d/01-acarsdec b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/acars_bridge similarity index 100% rename from rootfs/etc/s6-overlay/s6-rc.d/acars_server/dependencies.d/01-acarsdec rename to rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/acars_bridge diff --git a/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/acars_feeder b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/acars_feeder deleted file mode 100644 index e69de29..0000000 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/acars_server b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/acars_server deleted file mode 100644 index e69de29..0000000 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/acars_stats b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/acars_stats deleted file mode 100644 index e69de29..0000000 diff --git a/rootfs/etc/s6-overlay/scripts/01-acarsdec b/rootfs/etc/s6-overlay/scripts/01-acarsdec index de6f8fe..6eac8f7 100755 --- a/rootfs/etc/s6-overlay/scripts/01-acarsdec +++ b/rootfs/etc/s6-overlay/scripts/01-acarsdec @@ -37,10 +37,14 @@ FREQ_STRING="" for i in "${SPLIT_FREQS[@]}" do : -if [[ $(echo "$i > 118.0" | bc) -eq 0 || $(echo "$i < 137.0" | bc) -eq 0 ]]; then - "${s6wrap[@]}" echo "FREQUENCY $i is not in the range of 118.0 - 137.0" -fi -FREQ_STRING+=" $i" + if [[ $(echo "$i > 118.0" | bc) -eq 0 || $(echo "$i < 137.0" | bc) -eq 0 ]]; then + "${s6wrap[@]}" echo "FREQUENCY $i is not in the range of 118.0 - 137.0" + fi + if [[ -z "${FREQ_STRING}" ]]; then + FREQ_STRING="$i" + else + FREQ_STRING+=" $i" + fi done # Make sure mode is valid @@ -49,11 +53,6 @@ if [[ "${MODE}" != @(J|j|P|p|A|a) ]]; then exit 1 fi -if [[ -n "${SERVER}" && -z "${SERVER_PORT}" ]]; then - "${s6wrap[@]}" echo "SERVER is set but SERVER_PORT is not set, exiting" - exit 1 -fi - # Make sure GAIN is valid (if set) if [[ -n "${GAIN}" ]] && [[ "$(awk '{if ($1 > 0 && $1 < 100) printf "%i", $1 * 10; else printf "%i", $1;}' <<< "${GAIN}")" == "0" ]]; then "${s6wrap[@]}" echo "GAIN is not valid, exiting" diff --git a/rootfs/etc/s6-overlay/scripts/acars_bridge b/rootfs/etc/s6-overlay/scripts/acars_bridge new file mode 100755 index 0000000..d319a67 --- /dev/null +++ b/rootfs/etc/s6-overlay/scripts/acars_bridge @@ -0,0 +1,45 @@ +#!/command/with-contenv bash +# shellcheck shell=bash + +SCRIPT_NAME="$(basename "$0")" +SCRIPT_NAME="${SCRIPT_NAME%.*}" + +# shellcheck disable=SC2034 +s6wrap=(s6wrap --quiet --timestamps --prepend="$SCRIPT_NAME" --args) +# lets see if legacy SERVER / SERVER_PORT are set + +if [[ -n "$SERVER" ]]; then + "${s6wrap[@]}" echo "[WARN] SERVER is deprecated, please use OUTPUT_SERVER" + OUTPUT_SERVER="$SERVER" +fi + +if [[ -n "$SERVER_PORT" ]]; then + "${s6wrap[@]}" echo "[WARN] SERVER_PORT is deprecated, please use OUTPUT_SERVER_PORT" + OUTPUT_SERVER_PORT="$SERVER_PORT" +fi + +# detect legacy udp +if [[ "$OUTPUT_SERVER_MODE" == "udp" ]]; then + "${s6wrap[@]}" echo "[WARN] Using UDP mode to connect to $OUTPUT_SERVER:$OUTPUT_SERVER_PORT. Suggest switching to TCP or ZMQ Mode. Please see documentation for more information." +fi + +SOURCE_PORT=5550 +ACARS_BRIDGE_BIN="/opt/acars-bridge" +ACARS_BRIDGE_CMD=(--source-port "$SOURCE_PORT") +ACARS_BRIDGE_CMD+=(--source-protocol "udp") +ACARS_BRIDGE_CMD+=(--source-host "0.0.0.0") + +if [[ -n "$OUTPUT_SERVER" ]]; then + ACARS_BRIDGE_CMD+=(--destination-host "$OUTPUT_SERVER") +fi + +if [[ -n "$OUTPUT_SERVER_PORT" ]]; then + ACARS_BRIDGE_CMD+=(--destination-port "$OUTPUT_SERVER_PORT") +fi + +if [[ -n "$OUTPUT_SERVER_MODE" ]]; then + ACARS_BRIDGE_CMD+=(--destination-protocol "$OUTPUT_SERVER_MODE") +fi + +"${s6wrap[@]}" echo "[INFO] Starting acars-bridge with command: $ACARS_BRIDGE_BIN ${ACARS_BRIDGE_CMD[*]}" +"${s6wrap[@]}" "$ACARS_BRIDGE_BIN" "${ACARS_BRIDGE_CMD[@]}" diff --git a/rootfs/etc/s6-overlay/scripts/acars_feeder b/rootfs/etc/s6-overlay/scripts/acars_feeder deleted file mode 100755 index 82a2442..0000000 --- a/rootfs/etc/s6-overlay/scripts/acars_feeder +++ /dev/null @@ -1,30 +0,0 @@ -#!/command/with-contenv bash -# shellcheck shell=bash - -SCRIPT_NAME="$(basename "$0")" -SCRIPT_NAME="${SCRIPT_NAME%.*}" - -# shellcheck disable=SC2034 -s6wrap=(s6wrap --quiet --timestamps --prepend="$SCRIPT_NAME" --args) - -# Require that acars_server is running -if ! netstat -an | grep -P '^\s*tcp\s+\d+\s+\d+\s+0\.0\.0\.0:15550\s+(?>\d{1,3}\.{0,1}){4}:\*\s+LISTEN\s*$' > /dev/null; then - sleep 1 - if [[ ! ${QUIET_LOGS,,} =~ true ]]; then - # shellcheck disable=SC2154 - "${s6wrap[@]}" echo "acars_server not running, exiting" - fi - exit -fi -set -e - -SERVER_ADDR="UDP:${SERVER}:${SERVER_PORT}" - -if [[ ! ${QUIET_LOGS,,} =~ true ]]; then - "${s6wrap[@]}" echo "Starting acars_feeder with ${SERVER_ADDR}" -fi - -# shellcheck disable=SC2016 -socat -d TCP:127.0.0.1:15550 "$SERVER_ADDR" - -sleep 5 diff --git a/rootfs/etc/s6-overlay/scripts/acars_server b/rootfs/etc/s6-overlay/scripts/acars_server deleted file mode 100755 index 2247c80..0000000 --- a/rootfs/etc/s6-overlay/scripts/acars_server +++ /dev/null @@ -1,8 +0,0 @@ -#!/command/with-contenv bash -#shellcheck shell=bash - -# Listens for the output of acarsdec (UDP), and makes it available for multiple processes at TCP port 15550 - -socat -u udp-listen:5550,fork stdout | ncat -4 --keep-open --listen 0.0.0.0 15550 - -sleep 5 diff --git a/rootfs/etc/s6-overlay/scripts/acars_stats b/rootfs/etc/s6-overlay/scripts/acars_stats deleted file mode 100755 index 5984690..0000000 --- a/rootfs/etc/s6-overlay/scripts/acars_stats +++ /dev/null @@ -1,45 +0,0 @@ -#!/command/with-contenv bash -#shellcheck shell=bash - -SCRIPT_NAME="$(basename "$0")" -SCRIPT_NAME="${SCRIPT_NAME%.*}" - -# shellcheck disable=SC2034 -s6wrap=(s6wrap --quiet --timestamps --prepend="$SCRIPT_NAME" --args) - -set -o pipefail - -# Require that acars_server is running -if ! netstat -an | grep -P '^\s*tcp\s+\d+\s+\d+\s+0\.0\.0\.0:15550\s+(?>\d{1,3}\.{0,1}){4}:\*\s+LISTEN\s*$' > /dev/null; then - sleep 1 - if [[ ! ${QUIET_LOGS,,} =~ true ]]; then - # shellcheck disable=SC2154 - "${s6wrap[@]}" echo "acars_server not running, exiting" - fi - exit -fi - -# Start our stats loop -while true; do - - # capture 5 mins of flows - timeout --foreground 300s socat -u TCP:127.0.0.1:15550 CREATE:/run/acars/acars.past5min.json - - # if the port isn't reachable, this file isn't created, either container is shutting down or acars_server isn't reachable - # in both cases let's exit, if this should still be running it will be restarted - if ! [[ -f /run/acars/acars.past5min.json ]]; then - exit - fi - - # shellcheck disable=SC2016 - "${s6wrap[@]}" echo "$(wc -l < /run/acars/acars.past5min.json) ACARS messages received in last 5 mins" - - # rotate files keeping last 2 hours - for i in {24..1}; do - mv "/run/acars/acars.$((i-1)).json" "/run/acars/acars.$i.json" > /dev/null 2>&1 || true - done - mv "/run/acars/acars.past5min.json" "/run/acars/acars.0.json" > /dev/null 2>&1 || true - -done - -sleep 5 diff --git a/rootfs/etc/s6-overlay/scripts/acarsdec b/rootfs/etc/s6-overlay/scripts/acarsdec index 1114d3d..a01dfb1 100755 --- a/rootfs/etc/s6-overlay/scripts/acarsdec +++ b/rootfs/etc/s6-overlay/scripts/acarsdec @@ -4,17 +4,6 @@ # shellcheck disable=SC1091 source /scripts/common -# Require that acars_server is running -if ! netstat -an | grep -P '^\s*tcp\s+\d+\s+\d+\s+0\.0\.0\.0:15550\s+(?>\d{1,3}\.{0,1}){4}:\*\s+LISTEN\s*$' > /dev/null; then - sleep 1 - if [[ ! ${QUIET_LOGS,,} =~ true ]]; then - # shellcheck disable=SC2154 - "${s6wrap[@]}" echo "acars_server not running, exiting" - fi - exit -fi -set -e - ACARS_BIN="/usr/local/bin/acarsdec" # shellcheck disable=SC2001 SOAPYSDR="" @@ -37,7 +26,7 @@ if [ -n "${PPM}" ]; then ACARS_CMD+=("-p" "$PPM") fi -if [ -n "${SERVER}" ]; then +if [[ -n "${SERVER}" ]] || [[ -n "$OUTPUT_SERVER" ]]; then ACARS_CMD+=("-o" "0") ACARS_CMD+=("-l" "/dev/null") else @@ -53,34 +42,39 @@ if [ -n "${VERBOSE}" ]; then ACARS_CMD+=("-v") fi -# Send output JSON to acars_server -if [ -n "${SERVER}" ]; then - if [[ "${MODE}" == @(J|j) ]]; then - ACARS_CMD+=("-j" "127.0.0.1:5550") - elif [[ "${MODE}" == @(P|p) ]]; then - ACARS_CMD+=("-n" "127.0.0.1:5550") - elif [[ "${MODE}" == @(A|a) ]]; then - ACARS_CMD+=("-N" "127.0.0.1:5550") - fi +# Send output JSON to acars-bridge + +if [[ "${MODE}" == @(J|j) ]]; then + ACARS_CMD+=("-j" "127.0.0.1:5550") +elif [[ "${MODE}" == @(P|p) ]]; then + ACARS_CMD+=("-n" "127.0.0.1:5550") +elif [[ "${MODE}" == @(A|a) ]]; then + ACARS_CMD+=("-N" "127.0.0.1:5550") fi + # Specify SOAPYSDR if [ -n "${SOAPYSDR}" ]; then ACARS_CMD+=("-d" "$SOAPYSDR") fi +if [[ -n "$ACARSDEC_COMMAND_EXTRA" ]]; then + ACARS_CMD+=("$ACARSDEC_COMMAND_EXTRA") +fi + # shellcheck disable=SC2206 ACARS_CMD+=($FREQ_STRING) set -eo pipefail +# shellcheck disable=SC2154 "${s6wrap[@]}" echo "Starting: '$ACARS_BIN" "${ACARS_CMD[*]}'" if [[ ${QUIET_LOGS,,} =~ true ]]; then # shellcheck disable=SC2016 "${s6wrap[@]}" "$ACARS_BIN" "${ACARS_CMD[@]}" 2>&1 | \ stdbuf -oL sed --unbuffered '/^$/d' | \ - stdbuf -oL awk '! /^dumpvdl2/' | \ + stdbuf -oL awk '! /^acarsdec/' | \ stdbuf -oL awk '! /^Sampling rate set/' | \ stdbuf -oL awk '! /^Found \[0-9]+ device(s):/' | \ stdbuf -oL awk '! /^ [0-9]+/' | \ diff --git a/rootfs/rename_current_arch_binary.sh b/rootfs/rename_current_arch_binary.sh new file mode 100755 index 0000000..0d666ef --- /dev/null +++ b/rootfs/rename_current_arch_binary.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -x + +ls -la /opt/ + +# determine which binary to keep +if /opt/acars-bridge.amd64 --version > /dev/null 2>&1; then + mv -v /opt/acars-bridge.amd64 /opt/acars-bridge +elif /opt/acars-bridge.arm64 --version > /dev/null 2>&1; then + mv -v /opt/acars-bridge.arm64 /opt/acars-bridge +elif /opt/acars-bridge.armv7 --version > /dev/null 2>&1; then + mv -v /opt/acars-bridge.armv7 /opt/acars-bridge +else + >&2 echo "ERROR: Unsupported architecture" + exit 1 +fi diff --git a/rootfs/scripts/healthcheck.sh b/rootfs/scripts/healthcheck.sh index 33296ba..f24244a 100755 --- a/rootfs/scripts/healthcheck.sh +++ b/rootfs/scripts/healthcheck.sh @@ -8,117 +8,6 @@ source /opt/healthchecks-framework/healthchecks.sh # Default original codes EXITCODE=0 -# ===== Local Helper Functions ===== - -function get_pid_of_decoder { - - # $1: service_dir - service_dir="$1" - - # Ensure variables are unset - unset SOAPYSDR ACARS_BIN FREQ_STRING - - # Get SOAPYSDR - eval "$(grep "SOAPYSDR=\"" "$service_dir")" - - # Get FREQS_ACARS - eval "$(grep "FREQ_STRING=\"" "$service_dir")" - - # Get ACARS_BIN - eval "$(grep "ACARS_BIN=\"" "$service_dir")" - - # Get PS output for the relevant process - if [[ -n "$ACARS_BIN" ]]; then - if [[ -n "$SOAPYSDR" ]]; then - # shellcheck disable=SC2009 - ps_output=$(ps aux | grep "$ACARS_BIN" | grep " -d $SOAPYSDR " | grep "$FREQ_STRING") - fi - fi - - # Find the PID of the decoder based on command line - process_pid=$(echo "$ps_output" | tr -s " " | cut -d " " -f 2) - - # Return the process_pid - echo "$process_pid" - -} - -# ===== Check acarsdec processes ===== - -# For each service... -for service_dir in /etc/s6-overlay/scripts/*; do - service_name=$(basename "$service_dir") - - # If the service is acarsdec-*... - if [[ "$service_name" == acarsdec ]]; then - - decoder_pid=$(get_pid_of_decoder "$service_dir") - decoder_udp_port="5550" - decoder_server_prefix="acars" - - # If the server isn't acarsdec-. - else - # skip it! - continue - fi - - # If the process doesn't exists, then fail - - echo "==== Checking $service_name =====" - - if [[ -z "$decoder_pid" ]]; then - echo "Cannot find PID of decoder $service_name: UNHEALTHY" - EXITCODE=1 - else - # If the process does exist, then make sure it has made a connection to localhost on the relevant port. - if ! check_udp4_connection_established_for_pid "127.0.0.1" "ANY" "127.0.0.1" "$decoder_udp_port" "$decoder_pid"; then - echo "Decoder $service_name (pid $decoder_pid) not connected to ${decoder_server_prefix}_server at 127.0.0.1:$decoder_udp_port: UNHEALTHY" - EXITCODE=1 - else - echo "Decoder $service_name (pid $decoder_pid) is connected to ${decoder_server_prefix}_server at 127.0.0.1:$decoder_udp_port: HEALTHY" - fi - fi - -done - -# ===== Check acars_server, acars_feeder, acars_stats processes ===== - -echo "==== Checking acars_server =====" - -# Check acars_server is listening for TCP on 127.0.0.1:15550 -acars_pidof_acars_tcp_server=$(pgrep -f 'ncat -4 --keep-open --listen 0.0.0.0 15550') -if ! check_tcp4_socket_listening_for_pid "0.0.0.0" "15550" "${acars_pidof_acars_tcp_server}"; then - echo "acars_server TCP not listening on port 15550 (pid $acars_pidof_acars_tcp_server): UNHEALTHY" - EXITCODE=1 -else - echo "acars_server TCP listening on port 15550 (pid $acars_pidof_acars_tcp_server): HEALTHY" -fi - -echo "==== Checking acars_stats =====" - -# Check acars_stats: -acars_pidof_acars_stats=$(pgrep -fx 'socat -u TCP:127.0.0.1:15550 CREATE:/run/acars/acars.past5min.json') - -# Ensure TCP connection to acars_server at 127.0.0.1:15550 -if ! check_tcp4_connection_established_for_pid "127.0.0.1" "ANY" "127.0.0.1" "15550" "${acars_pidof_acars_stats}"; then -echo "acars_stats (pid $acars_pidof_acars_stats) not connected to acars_server (pid $acars_pidof_acars_tcp_server) at 127.0.0.1:15550: UNHEALTHY" -EXITCODE=1 -else -echo "acars_stats (pid $acars_pidof_acars_stats) connected to acars_server (pid $acars_pidof_acars_tcp_server) at 127.0.0.1:15550: HEALTHY" -fi - -echo "==== Check for ACARS activity =====" - -# Check for activity -# read .json files, ensure messages received in past hour -acars_num_msgs_past_hour=$(find /run/acars -type f -name 'acars.*.json' -cmin -60 -exec cat {} \; | wc -l) -if [[ "$acars_num_msgs_past_hour" -gt 0 ]]; then - echo "$acars_num_msgs_past_hour ACARS messages received in past hour: HEALTHY" -else - echo "$acars_num_msgs_past_hour ACARS messages received in past hour: UNHEALTHY" - EXITCODE=1 -fi - echo "==== Check Service Death Tallies =====" # Check service death tally