#!/usr/bin/env bash
#
# Runs the tower ingest in a screen session named 'tower_db_ingest'.
#
# If a screen session is already running with that name, exit, otherwise start
# a new detached screen session named 'tower_db_ingest'.
#
NAME=tower_db_ingest
PYENV=/opt/metobs/aoss_tower
#SRC=/mnt/data/ingest/rig_tower/rig_tower.dat
#DBURL=postgresql://buoy_ingest:bu0y1ngest@tahiti.ssec.wisc.edu/buoy
DBURL=postgresql://metobs_ingest:m3t0b5@metobs01.instrument/metobs
LOGFN=$PYENV/log/tower_db_ingest.log

export PGAPPNAME=tower_db_ingest

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.legacy_db_insert \
                                --loglvl info \
                                --logfn $LOGFN \
                                --ldmp \
                                $DBURL \
                                RIGTower
echo Started in screen $(screen -list | grep $NAME | awk '{print $1}')
fi
