From 4f16dd2ed136f7f237c34635e03ef4ea3496cdf9 Mon Sep 17 00:00:00 2001 From: Gilles Grandou Date: Fri, 10 Sep 2021 10:30:01 +0200 Subject: [PATCH] run: add start/stop/restart/status commands --- run | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/run b/run index 3cba054..f447606 100755 --- a/run +++ b/run @@ -1,6 +1,59 @@ -#!/bin/bash -e - -make +#!/bin/bash dev=/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A500DA2H-if00-port0 -./tic2mqtt -a -t $dev -h doctor -v "$@" +rundir=$(realpath $(dirname $0)) + +cmd="" +quiet="" + +while [ $# -gt 0 ]; do + case "$1" in + start) cmd=$1;; + stop) cmd=$1;; + restart) cmd=$1;; + status) cmd=$1;; + -q) quiet=$1;; + --quiet) quiet=$1;; + *) echo "usage: $0 [start|stop|restart|status] [-q|--quiet]" + exit 1 + ;; + esac + shift +done + +is_running=$(tmux has -t tic2mqtt 2> /dev/null && echo yes) + +case "$cmd" in + start) + if [ -n "$is_running" ]; then + echo "tic2mqtt already running. aborting" + exit 1 + fi + make -s + test -z $quiet && echo "starting tic2mqtt" + tmux new -s tic2mqtt -d "./tic2mqtt -a -t $dev -h doctor -v" + test -z $quiet && tmux ls + ;; + stop) + if [ ! -n "$is_running" ]; then + test -z $quiet && echo "no tic2mqtt running. nothing to stop" + exit 0 + fi + test -z $quiet && echo "killing tic2mqtt" + tmux kill-session -t tic2mqtt + ;; + restart) + $0 $quiet stop + $0 $quiet start + ;; + status) + if [ -n "$is_running" ]; then + tmux ls | grep tic2mqtt + else + echo "no tic2mqtt running" + fi + ;; + *) + echo "usage: $0 [start|stop]" + ;; +esac