From d66a05b019705c3f8632cbdfb6b3d5cde212ef57 Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Mon, 11 Mar 2019 17:01:16 +0000 Subject: [PATCH] Use a helper to start dump1090-fa so we can read ENABLED from the defaults file, like beast-splitter does --- debian/dump1090-fa.default | 7 +++++-- debian/dump1090-fa.install | 3 ++- debian/dump1090-fa.service | 7 ++----- debian/start-dump1090-fa | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 8 deletions(-) create mode 100755 debian/start-dump1090-fa diff --git a/debian/dump1090-fa.default b/debian/dump1090-fa.default index d646aaa..9d03380 100644 --- a/debian/dump1090-fa.default +++ b/debian/dump1090-fa.default @@ -1,11 +1,14 @@ # dump1090-fa configuration -# This is read by the systemd service file as an environment file, -# and evaluated by some scripts as a POSIX shell fragment. +# This is sourced by /usr/share/dump1090-fa/start-dump1090-fa as a +# shellscript fragment. # If you are using a PiAware sdcard image, this config file is regenerated # on boot based on the contents of piaware-config.txt; any changes made to this # file will be lost. +# dump1090-fa won't automatically start unless ENABLED=yes +ENABLED=yes + RECEIVER_OPTIONS="--device-index 0 --gain -10 --ppm 0 --net-bo-port 30005" DECODER_OPTIONS="--max-range 360" NET_OPTIONS="--net --net-heartbeat 60 --net-ro-size 1000 --net-ro-interval 1 --net-ri-port 0 --net-ro-port 30002 --net-sbs-port 30003 --net-bi-port 30004,30104 --net-bo-port 30005" diff --git a/debian/dump1090-fa.install b/debian/dump1090-fa.install index ad434ce..67292d1 100644 --- a/debian/dump1090-fa.install +++ b/debian/dump1090-fa.install @@ -1,3 +1,4 @@ public_html/* usr/share/dump1090-fa/html debian/lighttpd/* etc/lighttpd/conf-available -bladerf/* /usr/share/dump1090-fa/bladerf +bladerf/* usr/share/dump1090-fa/bladerf +debian/start-dump1090-fa usr/share/dump1090-fa/ diff --git a/debian/dump1090-fa.service b/debian/dump1090-fa.service index 4b8ea7b..13a006f 100644 --- a/debian/dump1090-fa.service +++ b/debian/dump1090-fa.service @@ -7,17 +7,14 @@ Wants=network.target After=network.target [Service] -EnvironmentFile=/etc/default/dump1090-fa -EnvironmentFile=-/var/cache/piaware/location.env User=dump1090 RuntimeDirectory=dump1090-fa RuntimeDirectoryMode=0755 -ExecStart=/usr/bin/dump1090-fa \ - $RECEIVER_OPTIONS $DECODER_OPTIONS $NET_OPTIONS $JSON_OPTIONS $PIAWARE_DUMP1090_LOCATION_OPTIONS \ - --write-json /run/dump1090-fa --quiet +ExecStart=/usr/share/dump1090-fa/start-dump1090-fa --write-json /run/dump1090-fa --quiet Type=simple Restart=on-failure RestartSec=30 +RestartPreventExitStatus=64 Nice=-5 [Install] diff --git a/debian/start-dump1090-fa b/debian/start-dump1090-fa new file mode 100755 index 0000000..907e437 --- /dev/null +++ b/debian/start-dump1090-fa @@ -0,0 +1,33 @@ +#!/bin/sh + +# Helper script that reads /etc/default/dump1090-fa +# and either starts dump1090-fa with the configured +# arguments, or exits with status 64 to tell systemd +# not to auto-restart the service. + +if [ -f /etc/default/dump1090-fa ] +then + . /etc/default/dump1090-fa +fi + +if [ -f /var/cache/piaware/location.env ] +then + . /var/cache/piaware/location.env +fi + +if [ "x$ENABLED" != "xyes" ] +then + echo "dump1090-fa not enabled in /etc/default/dump1090-fa" >&2 + exit 64 +fi + +if [ -n "$LAT" -a -n "$LON" ] +then + POSITION="--lat $LAT --lon $LON" +fi + +exec /usr/bin/dump1090-fa \ + $RECEIVER_OPTIONS $DECODER_OPTIONS $NET_OPTIONS $JSON_OPTIONS $POSITION \ + "$@" +# exec failed, do not restart +exit 64