#!/bin/bash Script="${0} ${*}" function usage { echo "Usage: ${0} --inst_set= [--restart] [--sleep_sec=]" exit 1 } for arg in "${@}" do case ${arg} in --restart) Restart=Y shift ;; --inst_set=*) InstrSet="${arg#*=}" shift ;; --sleep_sec=*) SleepSec="${arg#*=}" shift ;; -*|--*) usage ;; *) ;; esac done if [ "${InstrSet}" == "" ] then usage fi if [ "${SleepSec}" == "" ] then SleepSec=3 fi RootDir=/home/cvtt/prod ConfigFile="${RootDir}/md_recorder/config/md_recorder.cfg" declare -A InstrSetInstrs InstrSetInstrs[1]=PAIR-BTC-USD InstrSetInstrs[2]=PAIR-ETH-USD InstrSetInstrs[3]=PAIR-DOGE-USD,PAIR-AVAX-USD,PAIR-USDT-USD,PAIR-MATIC-USD InstrSetInstrs[4]=PAIR-BCH-USD,PAIR-LTC-USD,PAIR-UNI-USD,PAIR-AAVE-USD,PAIR-LINK-USD,PAIR-SOL-USD Instruments=${InstrSetInstrs[${InstrSet}]} if [ "${Instruments}" == "" ] then echo "Unrecognized instrument settings: ${InstrSet}" usage fi Script="${Script} - (${Instruments})" AdminPort="720${InstrSet}" LogFile="${RootDir}/mmaker/logs/$(date '+%Y%m%d_%H%M%S').influx_rec.coinbs_${InstrSet}.log" Exchange=COINBASE export PYTHONPATH=${RootDir} Cmd="nohup" Cmd="${Cmd} python3" Cmd="${Cmd} ${RootDir}/cvttpy/apps/md_recorder.py" Cmd="${Cmd} --config=${ConfigFile}" Cmd="${Cmd} --active_exchanges=${Exchange}" Cmd="${Cmd} --instruments=${Instruments}" Cmd="${Cmd} --admin_port=${AdminPort}" Cmd="${Cmd} --log_level=INFO" Cmd="${Cmd} --log_file=${LogFile}" Cmd="${Cmd} &" function check_it { if !(timeout 3 curl -s localhost:${AdminPort}/ping > /dev/null) then echo "${Script} doesn't respond. restarting..." pids=$(ps -ef | grep "admin_port=${AdminPort}" | grep -v grep | tr -s ' ' |cut -d' ' -f2) echo pids=${pids} if [ "${pids}" != "" ] then kill -9 ${pids} fi echo ${Cmd} eval ${Cmd} && sleep 10 fi } pids=$(ps -ef |grep "inst_set=${InstrSet}" |grep $(basename ${0}) |grep -v ${$} |grep -v grep |tr -s ' ' |cut -d' ' -f2) if [ "${Restart}" == "Y" ] then if [ "${pids}" != "" ] then echo "Killing ${pids} ..." kill -9 ${pids} fi while (timeout 3 curl -s localhost:${AdminPort}/ping > /dev/null) do echo "Shutting down localhost:${AdminPort}/shutdown ..." timeout 10 curl -s localhost:${AdminPort}/shutdown done else if [ "${pids}" != "" ] then echo "${0} is already running. pids=(${pids}). Use --restart" exit 0 fi fi while true do check_it echo "${Script} is checked" | /usr/bin/ts '[%Y-%m-%d %H:%M:%S]' sleep ${SleepSec} done