Skip to content

Instantly share code, notes, and snippets.

@xythobuz
Last active August 31, 2021 22:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xythobuz/d4d50e315a71a85e5361a26ca2ff53a4 to your computer and use it in GitHub Desktop.
Save xythobuz/d4d50e315a71a85e5361a26ca2ff53a4 to your computer and use it in GitHub Desktop.
Status page for RTL-SDR server on Raspberry Pi
www-data ALL=(root) NOPASSWD: /etc/init.d/rtl-sdr-server
www-data ALL=(root) NOPASSWD: /bin/rm
www-data ALL=(root) NOPASSWD: /bin/cat

RTL-SDR TCP Server on Raspberry Pi 3

Quick start:

  • Install current Raspbian Lite to an SD card
  • Place empty ssh file in /boot to enable remote access
  • Set hard-coded DHCP IP for RPi in Router
  • Install stuff (sudo apt-get update && sudo apt-get install rtl-sdr apache2 php5)
  • Copy rtl-sdr-server to /etc/init.d, change hard-coded IP
  • Make script executable (sudo chmod a+x /etc/init.d/rtl-sdr-server)
  • Enable script at boot (sudo update-rc.d rtl-sdr-server defaults)
  • Move index.php page into webroot and remove apache example index.html
  • Move 020-web file to /etc/sudoers.d to enable PHP script to start & stop server

Have fun :)

<?php
header('Content-type: text/html; charset=utf-8');
?>
<html>
<head>
<title>RTL-SDR Server</title>
</head>
<body>
<?php
if (isset($_GET['restart'])) {
?>
<h1>RTL-SDR Server Restart</h1>
<ul>
<li>Stopping RTL-SDR Server...</li>
<?php
print("<pre>$ sudo /etc/init.d/rtl-sdr-server stop\n" . shell_exec("sudo /etc/init.d/rtl-sdr-server stop") . "</pre>");
?>
<li>Deleting old logfile...</li>
<?php
print("<pre>$ sudo rm -rf /var/log/rtl-sdr-server.err\n" . shell_exec("sudo rm -rf /var/log/rtl-sdr-server.err") . "</pre>");
?>
<li>Starting RTL-SDR Server...</li>
<?php
print("<pre>$ sudo /etc/init.d/rtl-sdr-server start\n" . shell_exec("sudo /etc/init.d/rtl-sdr-server start") . "</pre>");
?>
</ul>
<hr>
<p>RTL-SDR status: <?php print(shell_exec('sudo /etc/init.d/rtl-sdr-server status')); ?></p>
<p><a href="index.php">Return to homepage...</a></p>
<?php
} else {
?>
<h1>RTL-SDR Server C&amp;C</h1>
<p>RTL-SDR status: <?php print(shell_exec('sudo /etc/init.d/rtl-sdr-server status')); ?></p>
<p><a href="index.php?restart=1">Restart RTL-SDR Server</a></p>
<hr>
<p>Logfile (stderr):</p>
<?php
print('<pre style="min-height: 150px; max-height: 200px; border: 1px solid black; overflow: auto;">' . shell_exec("sudo cat /var/log/rtl-sdr-server.err") . "</pre>");
}
?>
<p style="font-size: small; text-align: center;">Made by <a href="http://xythobuz.de">xythobuz</a></p>
</body>
</html>
#! /bin/sh
# /etc/init.d/rtl-sdr-server
### BEGIN INIT INFO
# Provides: rtl-sdr-server
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Simple script to start a program at boot
# Description: Start or stop the rtl_tcp server. IP is hardcoded!
### END INIT INFO
# If you want a command to always run, put it here
rmmod dvb_usb_rtl28xxu > /dev/null 2> /dev/null
dir="/home/pi"
cmd="/usr/bin/rtl_tcp -a 192.168.0.198"
user=""
name=`basename $0`
pid_file="/var/run/$name.pid"
stdout_log="/dev/null"
stderr_log="/var/log/$name.err"
get_pid() {
cat "$pid_file"
}
is_running() {
[ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1
}
case "$1" in
start)
if is_running; then
echo "Already started"
else
echo "Starting $name"
cd "$dir"
if [ -z "$user" ]; then
sudo $cmd >> "$stdout_log" 2>> "$stderr_log" &
else
sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log" &
fi
echo $! > "$pid_file"
if ! is_running; then
echo "Unable to start, see $stdout_log and $stderr_log"
exit 1
fi
fi
;;
stop)
if is_running; then
echo -n "Stopping $name.."
kill `get_pid`
for i in {1..10}
do
if ! is_running; then
break
fi
echo -n "."
sleep 1
done
echo
if is_running; then
echo "Not stopped; may still be shutting down or shutdown may have failed"
exit 1
else
echo "Stopped"
if [ -f "$pid_file" ]; then
rm "$pid_file"
fi
fi
else
echo "Not running"
fi
;;
restart)
$0 stop
if is_running; then
echo "Unable to stop, will not attempt to start"
exit 1
fi
$0 start
;;
status)
if is_running; then
echo "Running"
else
echo "Stopped"
exit 1
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment