#!/usr/bin/env bash
#
# Runs the tower ingest in a screen session named 'tower_influxdb_ingest'.
#
# If a screen session is already running with that name, exit, otherwise start
# a new detached screen session named 'tower_influxdb_ingest'.
#
NAME=tower_influxdb_ingest
PYENV=/opt/metobs/aoss_tower
#SRC=/mnt/data/ingest/rig_tower/rig_tower.dat
# LOGFN=$HOME/log/tower_db_ingest.log
# TODO: Add proper logging

SCRN=$(screen -list | grep $NAME | awk '{print $1}')
if [ -n "$SCRN" ]; then
    echo Screen already running: $SCRN
else
    screen -S $NAME -d -m $PYENV/bin/python -m aosstower.level_00.influxdb --host metobs01.ssec.wisc.edu -vvv --ldmp RIGTower
    #screen -S $NAME -d -m "$PYENV/bin/python -m aosstower.l00.influxdb --host metobs01.ssec.wisc.edu -vvv -t $SRC > /home/metobs/log/${NAME}.log"
    echo Started in screen $(screen -list | grep $NAME | awk '{print $1}')
fi