run: add log command
This commit is contained in:
		
							
								
								
									
										21
									
								
								run
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								run
									
									
									
									
									
								
							@@ -2,6 +2,7 @@
 | 
			
		||||
 | 
			
		||||
dev=/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A500DA2H-if00-port0
 | 
			
		||||
rundir=$(realpath $(dirname $0))
 | 
			
		||||
session="tic2mqtt"
 | 
			
		||||
 | 
			
		||||
cmd=""
 | 
			
		||||
quiet=""
 | 
			
		||||
@@ -12,16 +13,17 @@ while [ $# -gt 0 ]; do
 | 
			
		||||
      stop)    cmd=$1;;
 | 
			
		||||
      restart) cmd=$1;;
 | 
			
		||||
      status)  cmd=$1;;
 | 
			
		||||
      log)     cmd=$1;;
 | 
			
		||||
      -q)      quiet=$1;;
 | 
			
		||||
      --quiet) quiet=$1;;
 | 
			
		||||
      *)       echo "usage: $0 [start|stop|restart|status] [-q|--quiet]"
 | 
			
		||||
      *)       echo "usage: $0 [start|stop|restart|status|log] [-q|--quiet]"
 | 
			
		||||
               exit 1
 | 
			
		||||
               ;;
 | 
			
		||||
    esac
 | 
			
		||||
    shift
 | 
			
		||||
done
 | 
			
		||||
 | 
			
		||||
is_running=$(tmux has -t tic2mqtt 2> /dev/null && echo yes)
 | 
			
		||||
is_running=$(tmux has -t $session 2> /dev/null && echo yes)
 | 
			
		||||
 | 
			
		||||
case "$cmd" in
 | 
			
		||||
    start)
 | 
			
		||||
@@ -31,7 +33,7 @@ case "$cmd" in
 | 
			
		||||
        fi
 | 
			
		||||
        make -s
 | 
			
		||||
        test -z $quiet && echo "starting tic2mqtt"
 | 
			
		||||
        tmux new -s tic2mqtt -d "./tic2mqtt -a -t $dev -h doctor -v"
 | 
			
		||||
        tmux new -s $session -d "./tic2mqtt -a -t $dev -h doctor -v"
 | 
			
		||||
        test -z $quiet && tmux ls
 | 
			
		||||
        ;;
 | 
			
		||||
    stop)
 | 
			
		||||
@@ -40,7 +42,7 @@ case "$cmd" in
 | 
			
		||||
            exit 0
 | 
			
		||||
        fi
 | 
			
		||||
        test -z $quiet && echo "killing tic2mqtt"
 | 
			
		||||
        tmux kill-session -t tic2mqtt
 | 
			
		||||
        tmux kill-session -t $session
 | 
			
		||||
        ;;
 | 
			
		||||
    restart)
 | 
			
		||||
        $0 $quiet stop
 | 
			
		||||
@@ -48,7 +50,16 @@ case "$cmd" in
 | 
			
		||||
        ;;
 | 
			
		||||
    status)
 | 
			
		||||
        if [ -n "$is_running" ]; then
 | 
			
		||||
            tmux ls | grep tic2mqtt
 | 
			
		||||
            tmux ls | grep $session
 | 
			
		||||
        else
 | 
			
		||||
            echo "no tic2mqtt running"
 | 
			
		||||
        fi
 | 
			
		||||
        ;;
 | 
			
		||||
    log)
 | 
			
		||||
        if [ -n "$is_running" ]; then
 | 
			
		||||
            tmux capture -b $session -p -S - | head -15
 | 
			
		||||
            echo "[...]"
 | 
			
		||||
            tmux capture -b $session -p -E -
 | 
			
		||||
        else
 | 
			
		||||
            echo "no tic2mqtt running"
 | 
			
		||||
        fi
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user