cleaning
This commit is contained in:
Executable
+125
@@ -0,0 +1,125 @@
|
||||
#!/bin/bash
|
||||
|
||||
date_to_load=${1} # YYYY-MM-DD
|
||||
|
||||
DockerRegistry=cloud21.cvtt.vpn:5500
|
||||
DockerImage=${DockerRegistry}/alpaca_md_day #:latest
|
||||
LastDayFile=/home/cvtt/prod/logs/last_alpaca_hist_day
|
||||
ContainerName=alpaca_md_day
|
||||
|
||||
is_container_running() {
|
||||
local container_name=$1
|
||||
|
||||
if [ "$(docker ps --filter "name=^/${container_name}$" --filter "status=running" -q)" ]; then
|
||||
return 0 # true
|
||||
else
|
||||
return 1 # false
|
||||
fi
|
||||
}
|
||||
|
||||
export CalendarURL=https://trading-calendar.cvtt.net/api/v1/markets/hours?mic=XNYS
|
||||
|
||||
is_business_day() {
|
||||
dt=${1}
|
||||
|
||||
open_time=$(curl -s "${CalendarURL}&start=${dt}&end=${dt}" | jq '.[] | .open_time')
|
||||
if [ -n "${open_time}" ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
|
||||
}
|
||||
export -f is_business_day
|
||||
|
||||
get_prev_business_day() {
|
||||
Start=${1}
|
||||
while true; do
|
||||
if is_business_day ${Start}; then
|
||||
break
|
||||
fi
|
||||
echo "${Start} is not business day in US" >&2
|
||||
Start=$(date -d "${Start} - 1 day" "+%Y-%m-%d")
|
||||
done
|
||||
echo ${Start}
|
||||
}
|
||||
export -f get_prev_business_day
|
||||
|
||||
if [ -z ${date_to_load} ] ; then
|
||||
echo "Date is not specified. Yesterday data has priority. Running historical container will be stopped"
|
||||
Cmd="docker stop ${ContainerName}"
|
||||
echo ${Cmd} && eval ${Cmd}
|
||||
Cmd="docker kill ${ContainerName}"
|
||||
echo ${Cmd} && eval ${Cmd}
|
||||
Cmd="docker rm -f ${ContainerName}"
|
||||
echo ${Cmd} && eval ${Cmd}
|
||||
|
||||
Cmd="docker ps"
|
||||
echo ${Cmd} && eval ${Cmd}
|
||||
|
||||
if is_container_running "$ContainerName"; then
|
||||
echo "Container ${ContainerName} is still running."
|
||||
exit 3
|
||||
fi
|
||||
else
|
||||
date_to_load=$(date -d ${date_to_load} '+%Y-%m-%d') #expected format
|
||||
echo "Historical run ${date_to_load}"
|
||||
if is_container_running "$ContainerName"; then
|
||||
echo "Container ${ContainerName} is already running."
|
||||
exit 3
|
||||
fi
|
||||
if [ "${date_to_load}" == "next" ] ; then
|
||||
if [ ! -e ${LastDayFile} ]; then
|
||||
echo "File ${LastDayFile} does not exist. Will try to use prev file."
|
||||
if [ ! -e ${LastDayFile}.prev ]; then
|
||||
echo "File ${LastDayFile}.prev does not exist. Aborted."
|
||||
exit 2
|
||||
fi
|
||||
mv ${LastDayFile}.prev ${LastDayFile}
|
||||
fi
|
||||
last_date=$(cat ${LastDayFile} | xargs)
|
||||
if [ -z "${last_date}" ] ; then
|
||||
echo "File ${LastDayFile} returned an empty last day. Will try to use prev file."
|
||||
if [ ! -e ${LastDayFile}.prev ]; then
|
||||
echo "File ${LastDayFile}.prev does not exist. Aborted."
|
||||
exit 2
|
||||
fi
|
||||
mv ${LastDayFile}.prev ${LastDayFile}
|
||||
last_date=$(cat ${LastDayFile} | xargs)
|
||||
if [ -z "${last_date}" ] ; then
|
||||
echo "Unable to obtain last_date. Aborted"
|
||||
exit 3
|
||||
fi
|
||||
echo "No last date_to_load in ${LastDayFile}"
|
||||
exit 1
|
||||
fi
|
||||
mv ${LastDayFile} ${LastDayFile}.prev
|
||||
date_to_load=$(date -d "${last_date} - 1 day" "+%Y-%m-%d")
|
||||
fi
|
||||
fi
|
||||
if [ -n "${date_to_load}" ]; then
|
||||
date_to_load=$(get_prev_business_day ${date_to_load})
|
||||
echo "Historical Data for ${date_to_load}"
|
||||
fi
|
||||
|
||||
Cmd="docker run"
|
||||
Cmd="${Cmd} --pull=always"
|
||||
Cmd="${Cmd} --network=host"
|
||||
Cmd="${Cmd} --name=${ContainerName}"
|
||||
Cmd="${Cmd} --rm"
|
||||
Cmd="${Cmd} ${DockerImage}"
|
||||
Cmd="${Cmd} ${date_to_load}"
|
||||
|
||||
echo $Cmd
|
||||
eval $Cmd
|
||||
|
||||
if [ "$?" != "0" ] ; then
|
||||
exit 1 # if killed we do not save last day
|
||||
fi
|
||||
|
||||
# truncate to avoid false positive
|
||||
date_to_load=$(echo "${date_to_load}" | xargs)
|
||||
if [ -n "${date_to_load}" ]; then
|
||||
echo "Saving date_to_load to ${LastDayFile}"
|
||||
echo ${date_to_load} > ${LastDayFile}
|
||||
fi
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
|
||||
ValidJobs=('BNBFUT_CLD21' 'BNBSPOT_CLD21' 'COINBASE_CLD21' 'BNBFUT_CVTTDATA' 'BNBSPOT_CVTTDATA' 'COINBASE_CVTTDATA')
|
||||
# runs on host to start container
|
||||
usage() {
|
||||
echo "Usage: $0 <job_name; one of (${ValidJobs[@]})> [image_tag]"
|
||||
exit 1
|
||||
}
|
||||
|
||||
is_valid() {
|
||||
local job=$1
|
||||
for valid_job in "${ValidJobs[@]}";
|
||||
do
|
||||
# echo "job=$job valid_job=$valid_job"
|
||||
if [[ "${job}" == "${valid_job}" ]]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
is_container_running() {
|
||||
local container_name=$1
|
||||
|
||||
if [ "$(docker ps --filter "name=^/${container_name}$" --filter "status=running" -q)" ]; then
|
||||
return 0 # true
|
||||
else
|
||||
return 1 # false
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
job=${1}
|
||||
if ! is_valid "${job}"; then
|
||||
usage
|
||||
fi
|
||||
|
||||
ImageTag=${2}
|
||||
if [ "${ImageTag}" == "" ] ; then
|
||||
ImageTag="1.6.9"
|
||||
fi
|
||||
|
||||
DockerImage=cloud21.cvtt.vpn:5500/md_recorder:${ImageTag}
|
||||
ContainerName="md_recorder.${job}"
|
||||
|
||||
if is_container_running "$ContainerName"; then
|
||||
echo "Container ${ContainerName} is already running. Aborted."
|
||||
exit
|
||||
fi
|
||||
|
||||
|
||||
Cmd="docker run"
|
||||
Cmd+=" -d"
|
||||
Cmd+=" --rm"
|
||||
Cmd+=" --network=host"
|
||||
# Cmd+=" --pull=always"
|
||||
Cmd+=" --name=${ContainerName}"
|
||||
Cmd+=" -v /home/cvtt/.creds:/.creds"
|
||||
Cmd+=" -v /home/cvtt/prod/data:/app/data"
|
||||
Cmd+=" -v /home/cvtt/prod/logs:/logs"
|
||||
Cmd+=" -e CONFIG_SERVICE=cloud16.cvtt.vpn:6789"
|
||||
Cmd+=" ${DockerImage}"
|
||||
Cmd+=" ${job}"
|
||||
|
||||
echo ${Cmd}
|
||||
eval ${Cmd}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 <instance (CLD21,CVTTDATA)> [<admin_port (def. 7225)>]"
|
||||
exit 1
|
||||
}
|
||||
|
||||
ValidInstances=('CLD21' 'CVTTDATA')
|
||||
is_valid() {
|
||||
local inst=$1
|
||||
for valid_inst in "${ValidInstances[@]}";
|
||||
do
|
||||
if [[ "$inst" == "$valid_inst" ]]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
is_container_running() {
|
||||
local container_name=$1
|
||||
|
||||
if [ "$(docker ps --filter "name=^/${container_name}$" --filter "status=running" -q)" ]; then
|
||||
return 0 # true
|
||||
else
|
||||
return 1 # false
|
||||
fi
|
||||
}
|
||||
|
||||
Instance=${1}
|
||||
if ! is_valid "${Instance}"; then
|
||||
usage
|
||||
fi
|
||||
|
||||
AdminPort=7225
|
||||
if [ "${2}" != "" ]; then
|
||||
AdminPort=${2}
|
||||
fi
|
||||
|
||||
ContainerName="md_recorder_monitor.${Instance}"
|
||||
|
||||
if is_container_running "$ContainerName"; then
|
||||
echo "Container ${ContainerName} is already running. Aborted."
|
||||
exit
|
||||
fi
|
||||
|
||||
Cmd="docker run"
|
||||
Cmd+=" -d"
|
||||
Cmd+=" --rm"
|
||||
Cmd+=" --network=host"
|
||||
Cmd+=" --pull=always"
|
||||
Cmd+=" --name=${ContainerName}"
|
||||
Cmd+=" -v /home/cvtt/.creds:/.creds"
|
||||
Cmd+=" -v /home/cvtt/prod/logs:/logs"
|
||||
Cmd+=" -e CONFIG_SERVICE=cloud16.cvtt.vpn:6789"
|
||||
Cmd+=" cloud21.cvtt.vpn:5500/md_recorder_monitor:latest"
|
||||
Cmd+=" ${Instance} ${AdminPort}"
|
||||
|
||||
echo ${Cmd}
|
||||
eval ${Cmd}
|
||||
Reference in New Issue
Block a user