summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@also>2011-08-05 01:44:39 +0200
committertv <tv@also>2011-08-05 01:44:39 +0200
commit8756170315ade841957f6e13c35ee52ab8d26107 (patch)
treefe27b18c091d994cc99d7d11d2fc7464277f2999
parente63c33ccfbb7d5cbb63f321b01183c5d6659c059 (diff)
parent49b7d9c8265fdc044020dcf6b6ca2a392777d22f (diff)
Merge branch 'master' of github.com:krebscode/painload
-rwxr-xr-xstreams/streams51
1 files changed, 37 insertions, 14 deletions
diff --git a/streams/streams b/streams/streams
index eb1e6674..c5e9e471 100755
--- a/streams/streams
+++ b/streams/streams
@@ -1,6 +1,10 @@
#! /bin/bash
HERE=$(dirname $(readlink -f $0))
URLS=`cat $HERE/stream.db`
+CURRENT_STREAM="no stream" #will be set when calling `status`
+if [ ! `id -u` -eq "0" ]; then
+ exec sudo "$0" "$@"
+fi
#if [ ! `id -u` -eq "0" ]; then
# echo "we are going sudo..."
@@ -11,7 +15,7 @@ function start() {
# start the given stream von $1
REQ=$1
tmux start-server
- if status; then
+ if status &>/dev/null ; then
echo "!! Stream already running!"
exit 1
fi
@@ -30,15 +34,39 @@ function start() {
function stop()
{
#stops every stream
- tmux kill-session -t streams || echo "!! killing session failed"
+ if status &>/dev/null; then
+ status | cut -d\ -f2 | xargs printf "** killing %s\n"
+ tmux kill-session -t streams 2>/dev/null || echo "!! killing session failed"
+ else
+ echo "** no stream running";
+ return 1
+ fi
}
function status()
{
- tmux has-session -t streams 2>/dev/null
- RET=$?
- tmux list-sessions 2>/dev/null
- return $RET
+ #tmux has-session -t streams 2>/dev/null
+ #RET=$?
+
+ #tmux list-sessions 2>/dev/null
+ #return $RET
+ EV="`ps -ef | grep tmux`"
+ if echo "$URLS" | while read URL NAME; do
+ if [ "`echo "$EV" | grep \"$URL\"`" ] ;then
+ echo "** $NAME running ($URL)"
+ exit 1
+ fi
+ done; then
+ echo "** no stream running"
+ return 1
+ else
+ return 0
+ fi
+}
+function current()
+{
+
+ return 1
}
function list()
{
@@ -74,18 +102,13 @@ case "$1" in
stop)
stop
;;
- restart)
+ (switch|restart)
stop
start $2
;;
status)
- if status; then
- echo "** stream running"
- exit 0
- else
- echo "** Stream not running"
- exit 1
- fi
+ status
+ exit $?
;;
list)
list