diff options
author | makefu <github@syntax-fehler.de> | 2011-08-04 19:51:53 +0200 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2011-08-04 19:51:53 +0200 |
commit | e14c7902515b32ac454327cc621dba0f37bedf93 (patch) | |
tree | 7461e1b105cb0f5e2e6a1e5e01fc211f7f5d3a48 | |
parent | 557844ecfba1f60cc7cfa50b2a2eb62749c8ba8c (diff) |
streams/streams fixed status
added 'switch' command (same as restart)
fixed stop, now telling which stream has been stopped
status now tells which stream is running/ which url
-rwxr-xr-x | streams/streams | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/streams/streams b/streams/streams index a8408b4a..034d68a1 100755 --- a/streams/streams +++ b/streams/streams @@ -1,12 +1,16 @@ #! /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 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 @@ -25,15 +29,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() { @@ -53,18 +81,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 |