Skip to content

Commit

Permalink
Add option to reboot device (#121)
Browse files Browse the repository at this point in the history
* Fix typo
* Add option to reboot device
* Rename env variable
* Add user notification
* Fix typo
* Add README for REBOOT_DEVICE_ON_SERVICE_EXIT
* Use graceful shutdown
  • Loading branch information
Teko012 committed Aug 5, 2024
1 parent b3e3cf8 commit 5b6163b
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 16 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ You can reduce the duty cycle further by creating a *Device Variable* named `DUM
## Setting dump1090 antenna gain
By default, dump1090 will run with adaptive gain in dynamic range mode. You can override this by setting a *Device Variable* named `DUMP1090_GAIN` with a value of your liking. You can read more about manual gain optimization at the [adsb-wiki](https://github.com/wiedehopf/adsb-wiki/wiki/Optimizing-gain).

## Device reboot on service exit
dump978 and dump1090 can restart the device if it hits an error. You can enable this feature by setting a *Device Variable* named `REBOOT_DEVICE_ON_SERVICE_EXIT` with the value of `true`.

# Part 14 – Updating to the latest version
Updating to the latest version is trivial. If you installed balena-ads-b using the blue Deploy with balena-button, you can click it again and overwrite your current application. Choose the "Deploy to existing fleet" option, then select the fleet you want to update. All settings will be preserved. For convenience, the button is right here:

Expand Down
2 changes: 1 addition & 1 deletion adsb-exchange/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if [[ ",$(echo -e "${DISABLED_SERVICES}" | tr -d '[:space:]')," = *",$BALENA_SER
sleep infinity
fi

# Verify that all the required varibles are set before starting up the application.
# Verify that all the required variables are set before starting up the application.

echo "Verifying settings..."
echo " "
Expand Down
1 change: 1 addition & 0 deletions dump1090-fa/Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ENV DUMP1090_ADAPTIVE_BURST=""
ENV DUMP1090_ADAPTIVE_MIN_GAIN=""
ENV DUMP1090_ADAPTIVE_MAX_GAIN=""
ENV DUMP1090_SLOW_CPU=""
ENV REBOOT_DEVICE_ON_SERVICE_EXIT=""

ARG PERM_INSTALL="tini lighttpd gettext-base libusb-1.0-0 libbladerf2 libhackrf0 liblimesuite22.09-1 librtlsdr0 rtl-sdr libsoapysdr0.8 libncurses6 libboost-system-dev libboost-program-options-dev libboost-regex-dev"

Expand Down
14 changes: 12 additions & 2 deletions dump1090-fa/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if [[ ",$(echo -e "${DISABLED_SERVICES}" | tr -d '[:space:]')," = *",$BALENA_SER
curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/stop-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"serviceName": "'$BALENA_SERVICE_NAME'"}'
sleep infinity
fi
# Verify that all the required varibles are set before starting up the application.
# Verify that all the required variables are set before starting up the application.

echo "Verifying settings..."
echo " "
Expand Down Expand Up @@ -112,6 +112,16 @@ fi

# Start lighttpd and put it in the background.
/usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf 2>&1 | stdbuf -o0 sed --unbuffered '/^$/d' | awk -W interactive '{print "[lighttpd] " $0}' &


# Check if device reboot on service exit has been enabled through the REBOOT_DEVICE_ON_SERVICE_EXIT environment variable.
if [[ "$REBOOT_DEVICE_ON_SERVICE_EXIT" == "true" ]]; then
echo "Device reboot on service exit is enabled."
fi

# Wait for any services to exit.
wait -n

if [[ "$REBOOT_DEVICE_ON_SERVICE_EXIT" == "true" ]]; then
echo "Service exited, rebooting the device..."
curl -X POST --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v1/reboot?apikey=$BALENA_SUPERVISOR_API_KEY"
fi
3 changes: 2 additions & 1 deletion dump978-fa/Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ EXPOSE 30978 30979 8978

ENV DUMP978_DEVICE=00000978
ENV DUMP978_ENABLED=false
ENV REBOOT_DEVICE_ON_SERVICE_EXIT=""

ARG PERM_INSTALL="tini libboost-program-options-dev libusb-1.0-0 lighttpd librtlsdr0 rtl-sdr soapysdr-module-rtlsdr gettext-base libboost-filesystem1.74.0 libboost-regex1.74.0 libboost-system1.74.0"
ARG PERM_INSTALL="tini libboost-program-options-dev libusb-1.0-0 lighttpd librtlsdr0 rtl-sdr soapysdr-module-rtlsdr gettext-base libboost-filesystem1.74.0 libboost-regex1.74.0 libboost-system1.74.0"

RUN apt update && \
apt install -y $PERM_INSTALL && \
Expand Down
16 changes: 13 additions & 3 deletions dump978-fa/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if ! [[ "$UAT_ENABLED" = "true" ]]; then
sleep infinity
fi

# Verify that all the required varibles are set before starting up the application.
# Verify that all the required variables are set before starting up the application.

echo "Verifying settings..."
echo " "
Expand Down Expand Up @@ -48,14 +48,24 @@ echo " "

# Variables are verified – continue with startup procedure.

# Start dump1090-fa and put it in the background.
# Start dump978-fa and put it in the background.
/usr/bin/dump978-fa --sdr driver="$DUMP978_DRIVER" --raw-port 0.0.0.0:30978 --json-port 0.0.0.0:30979 --format CS8 --sdr-auto-gain &

# Start skyaware978 and put it in the background.
/usr/bin/skyaware978 --connect localhost:30978 --reconnect-interval 30 --lat "$LAT" --lon "$LON" --json-dir /run/skyaware978 &

# Start lighthttpd and put it in the background.
/usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf &


# Check if device reboot on service exit has been enabled through the REBOOT_DEVICE_ON_SERVICE_EXIT environment variable.
if [[ "$REBOOT_DEVICE_ON_SERVICE_EXIT" == "true" ]]; then
echo "Device reboot on service exit is enabled."
fi

# Wait for any services to exit.
wait -n

if [[ "$REBOOT_DEVICE_ON_SERVICE_EXIT" == "true" ]]; then
echo "Service exited, rebooting the device..."
curl -X POST --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v1/reboot?apikey=$BALENA_SUPERVISOR_API_KEY"
fi
2 changes: 1 addition & 1 deletion fr24feed/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if [[ ",$(echo -e "${DISABLED_SERVICES}" | tr -d '[:space:]')," = *",$BALENA_SER
sleep infinity
fi

# Verify that all the required varibles are set before starting up the application.
# Verify that all the required variables are set before starting up the application.

echo "Verifying settings..."
echo " "
Expand Down
2 changes: 1 addition & 1 deletion mlat-client/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if [[ ",$(echo -e "${DISABLED_SERVICES}" | tr -d '[:space:]')," = *",$BALENA_SER
sleep infinity
fi

# Verify that all the required varibles are set before starting up the application.
# Verify that all the required variables are set before starting up the application.

echo "Verifying settings..."
echo " "
Expand Down
2 changes: 1 addition & 1 deletion opensky-network/getserial.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e

# Verify that all the required varibles are set before starting up the application.
# Verify that all the required variables are set before starting up the application.

echo "Verifying required settings..."
echo " "
Expand Down
2 changes: 1 addition & 1 deletion opensky-network/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if [[ ",$(echo -e "${DISABLED_SERVICES}" | tr -d '[:space:]')," = *",$BALENA_SER
sleep infinity
fi

# Verify that all the required varibles are set before starting up the application.
# Verify that all the required variables are set before starting up the application.

echo "Verifying settings..."
echo " "
Expand Down
2 changes: 1 addition & 1 deletion piaware/getid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT

# Verify that all the required varibles are set before starting up the application.
# Verify that all the required variables are set before starting up the application.

echo "Verifying required settings..."
echo " "
Expand Down
2 changes: 1 addition & 1 deletion piaware/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if [[ ",$(echo -e "${DISABLED_SERVICES}" | tr -d '[:space:]')," = *",$BALENA_SER
sleep infinity
fi

# Verify that all the required varibles are set before starting up the application.
# Verify that all the required variables are set before starting up the application.

echo "Verifying settings..."
echo " "
Expand Down
2 changes: 1 addition & 1 deletion planefinder/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if [[ ",$(echo -e "${DISABLED_SERVICES}" | tr -d '[:space:]')," = *",$BALENA_SER
sleep infinity
fi

# Verify that all the required varibles are set before starting up the application.
# Verify that all the required variables are set before starting up the application.

echo "Verifying settings..."
echo " "
Expand Down
2 changes: 1 addition & 1 deletion radarbox/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if [[ ",$(echo -e "${DISABLED_SERVICES}" | tr -d '[:space:]')," = *",$BALENA_SER
sleep infinity
fi

# Verify that all the required varibles are set before starting up the application.
# Verify that all the required variables are set before starting up the application.

echo "Verifying settings..."
echo " "
Expand Down
2 changes: 1 addition & 1 deletion wingbits/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if [[ ",$(echo -e "${DISABLED_SERVICES}" | tr -d '[:space:]')," = *",$BALENA_SER
sleep infinity
fi

# Verify that all the required varibles are set before starting up the application.
# Verify that all the required variables are set before starting up the application.

echo "Verifying settings..."
echo " "
Expand Down

0 comments on commit 5b6163b

Please sign in to comment.