From 661d0126fc611dfd8ef51c1531d604be37b66726 Mon Sep 17 00:00:00 2001 From: Oleg Sheynin Date: Mon, 17 Apr 2023 21:43:39 -0400 Subject: [PATCH] ops initial --- md_recorder_start.sh | 121 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 md_recorder_start.sh diff --git a/md_recorder_start.sh b/md_recorder_start.sh new file mode 100644 index 0000000..4ea7f48 --- /dev/null +++ b/md_recorder_start.sh @@ -0,0 +1,121 @@ +#!/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