add a bash script to run with systemd for digirig and ICOM dedicated VHF packet station
This commit is contained in:
119
ansible/roles/scanner_digirig/templates/digirig-direwolf.sh
Normal file
119
ansible/roles/scanner_digirig/templates/digirig-direwolf.sh
Normal file
@@ -0,0 +1,119 @@
|
||||
#!/bin/bash
|
||||
# @author Craig McDaniel
|
||||
#
|
||||
# This script runs Direwolf, socat and kissatach. It starts them in that order and makes sure they
|
||||
# all stay running and work together. If one crashes, this script stops everything. This effectively
|
||||
# sets up a AX.25 interface on a Linux computer using the Linux AX.25 stack.
|
||||
#
|
||||
# It's designed to be uses with systemd for things like auto start, auto re-start.
|
||||
#
|
||||
#
|
||||
# RF signals! _ RF signals!
|
||||
# \ _/
|
||||
# \ /
|
||||
# +-------+
|
||||
# | Radio | ----- RF signals!
|
||||
# +-------+
|
||||
# |
|
||||
# | Analog cable
|
||||
# |
|
||||
# +---------+
|
||||
# | Digirig |
|
||||
# +---------+
|
||||
# |
|
||||
# | USB sound card
|
||||
# |
|
||||
# +----|---------------------------------------------------------------------------+
|
||||
# | | This is your computer. The things in here are virtual components. |
|
||||
# | | |
|
||||
# | +-----------+ +-------+ +------------+ Linux kernel |
|
||||
# | | Direwolf | <---> | Socat | <----> | Kissattach | <------> ax0 interface |
|
||||
# | +-----------+ +-------+ +------------+ |
|
||||
# | |
|
||||
# +--------------------------------------------------------------------------------+
|
||||
|
||||
# Configuration
|
||||
DIREWOLF_CMD="/usr/local/bin/direwolf -t 0 -X 1 -c /opt/busnet/direwolf/config/digirig.conf"
|
||||
SOCAT_CMD="/usr/bin/socat PTY,raw,echo=0,link=/dev/radio/digirig-tnc TCP4:127.0.0.1:8001"
|
||||
KISSATTACH_CMD="/usr/sbin/kissattach /dev/radio/digirig-tnc digirig"
|
||||
KISSPARAMS_CMD="kissparms -c 1 -p digirig"
|
||||
INTERFACE_NAME="ax0"
|
||||
|
||||
cleanup() {
|
||||
echo
|
||||
echo "Exit signal detected. Cleaning up..."
|
||||
trap - SIGTERM # prevent recursion
|
||||
kill 0
|
||||
exit
|
||||
}
|
||||
|
||||
# Trap exit signals
|
||||
trap cleanup SIGINT SIGTERM
|
||||
|
||||
echo
|
||||
echo "======================================================================"
|
||||
echo "Starting Direwolf..."
|
||||
echo "======================================================================"
|
||||
echo
|
||||
$DIREWOLF_CMD &
|
||||
DIREWOLF_PID=$!
|
||||
sleep 1
|
||||
if ! kill -0 $DIREWOLF_PID; then
|
||||
echo "Direwolf failed to start."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Wait 3 seconds for Direwolf to initialize, then start socat.
|
||||
# socat creates a full duplex/bidirectional pipe between a serial port /dev/radio/digirig-tnc and
|
||||
# Direwolf's KISS TCP interface, which is running on localhost:8001. The kissattach program needs
|
||||
# a serial port to work, and this is how we accomplish connecting kissattach to direwolf.
|
||||
sleep 3
|
||||
|
||||
echo
|
||||
echo "======================================================================"
|
||||
echo "Starting socat..."
|
||||
echo "======================================================================"
|
||||
echo
|
||||
sudo $SOCAT_CMD &
|
||||
SOCAT_PID=$!
|
||||
if ! kill -0 $SOCAT_PID; then
|
||||
echo "Socat failed to start."
|
||||
kill $DIREWOLF_PID
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Run kissatach to create an AX.25 network interface on the system.
|
||||
#
|
||||
# Kissattach annoyingly forks itself in the background, so we can't directly monitor the process.
|
||||
# We rely on the control-group feature of systemd to kill all child processes for us, even if
|
||||
# they fork!
|
||||
#
|
||||
# Kissattach cannot use KISS over TCP directly to Direwolf. It expects a serial terminal to exist,
|
||||
# which is why we use socat to create the pipe between Direwolf's KISS TCP port and this serial
|
||||
# device.
|
||||
sleep 1
|
||||
|
||||
echo
|
||||
echo "======================================================================"
|
||||
echo "Starting kissattach and setting kissparams..."
|
||||
echo "======================================================================"
|
||||
echo
|
||||
sudo $KISSATTACH_CMD
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "kissattach failed to start."
|
||||
cleanup
|
||||
fi
|
||||
|
||||
# We have to set something on the AX.25 interface that Direwolf requires.
|
||||
sudo $KISSPARAMS_CMD
|
||||
|
||||
echo
|
||||
echo "All processes started. Monitoring via wait..."
|
||||
|
||||
# 'wait -n' waits for ANY background process to exit.
|
||||
# It returns as soon as Direwolf or Socat dies.
|
||||
wait -n
|
||||
|
||||
# If we get here, one of the processes died.
|
||||
cleanup
|
||||
Reference in New Issue
Block a user