rpirena/www/cgi/rpirena-control

112 lines
2.4 KiB
Text
Raw Permalink Normal View History

#! /bin/bash
# -*- sh -*-
declare -a QUERY=(${QUERY_STRING//&/ })
ACTION=${QUERY[0]}
TARGET=${QUERY[-1]}
[ "$TARGET" = "$ACTION" ] && TARGET=""
cat <<EOT
Content-type: text/html
<html>
<head>
<meta charset="UTF-8" />
<title>RPiRENA Data Acqusition</title>
</head>
<body>
<h1>Live plots of $(hostname)</h1>
EOT
exec 2>&1
if [ -z "$ACTION" ]
then
RUNNING=""
for r in python rpirena-auto.py
do
if sudo -u stephan /usr/bin/killall -s 0 -r "$r" 2>/dev/null
then
RUNNING="$r"
echo "<h2>$r is running!</h2>"
fi
done
[ -z "$RUNNING" ] && echo "<h2>rpirena is NOT running.</h2>"
cat <<EOT
<h2>Please choose an action:</h2>
<ul>
<li/><a href="rpirena-control?halt">Shutdown</a> the Raspberry Pi (sudo halt).
EOT
[ -z "$RUNNING" ] && cat <<EOF
<li/><a href="rpirena-control?start">Start</a> rpirena-auto.py (sudo /etc/rc.local start_rpirena).
EOF
[ "$RUNNING" = 'rpirena-auto.py' ] && cat <<EOF
<li/><a href="rpirena-control?stop">Stop</a> rpirena-auto.py (echo "stop" &gt; ~stephan/rpirena/auto-run).
<li/><a href="rpirena-control?restart">Restart</a> a new data file (echo "restart" &gt; ~stephan/rpirena/auto-run).
EOF
cat <<EOT
<li/><a href="rpirena">Return to the Plots.</a>
</ul>
<pre>
EOT
ps axfu | grep -v ' 0.0 *0 *0 .*]$'
cat <<EOT
</pre>
</body>
</html>
EOT
exit 0
fi
case "$ACTION" in
restart|stop)
if sudo -u stephan /usr/bin/killall -s 0 -r 'rpirena-auto.py'
then
CONFIRM="<a href=\"rpirena?${ACTION}\">Really ${ACTION} the acquisition</a>"
else
CONFIRM='rpirena-auto.py is not running.'
fi
;;
start)
if sudo -u stephan /usr/bin/killall -s 0 -r 'rpirena(-auto)?.py'
then
CONFIRM='rpirena(-auto)?.py is running'
else
if [ "$TARGET" = "force" ]
then
echo "<pre>"
sudo /etc/rc.local start_rpirena
sleep 1
echo "</pre>"
CONFIRM="sudo /etc/rc.local was executed"
else
CONFIRM='<a href="rpirena-control?start&amp;force">Really start rpirena-auto.py?</a>'
fi
fi
;;
halt)
if [ "$TARGET" = "force" ]
then
echo "</ul><h2>Shutdown in procgress, bye …</h2>sudo /sbin/halt</body></html>"
sleep 1
sudo /sbin/halt
exit 0
else
CONFIRM='<a href="rpirena-control?halt&amp;force">Really shutdown the Raspberry Pi?</a>'
fi
;;
esac
cat <<EOT
<h2>Please confirm:</h2>
<ul>
<li/> $CONFIRM
<li/> <a href="rpirena?old">No thanks, back to the Plots</a>.
</ul>
<pre>
EOT
ps axfu | grep -v ' 0.0 *0 *0 .*]$'
cat <<EOT
</pre>
</body>
</html>
EOT