Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- get_now () {
- now=`date +%H%M`
- now_date=`date +%m%d%Y`
- }
- get_now
- log=daily-refresh-$now_date.log
- touch $log
- let do_wait=FALSE
- let unattended=FALSE
- let time_enforce=FALSE
- let wait_prod=FALSE
- let no_refresh=FALSE
- mailid="5189294515@vtext.com"
- while getopts "j: w p: u t d " options; do
- case $options in
- j ) job=$OPTARG
- ;;
- w ) do_wait=TRUE
- ;;
- p ) procpid=$OPTARG
- ;;
- u ) unattended=TRUE
- ;;
- t ) time_enforce=TRUE
- ;;
- d ) no_refresh=TRUE
- ;;
- \? ) echo "bad arg"
- usage
- ;;
- * ) echo "bad arg"
- usage
- ;;
- esac
- done
- usage () {
- echo "
- Aris GC Automated Controller
- Usage:
- -j <job> Sets the job, etl_daily or etl_weekly
- -w Wait for existing GC job to finish
- -p <pid> Pid of existing GC job to watch
- -u Unattended mode, assumes YES to confirmation DANGEROUS!
- -t Enforce Production Time Slots (RECOMENDED!)
- -d Dont refresh, just run $job
- Refresh will ALWAYS run prior to the job running unless -d is specified
- "
- }
- wlog () {
- echo $1- >> $log
- }
- confirm () {
- get_now
- echo "Nightly Refresh/Daily Script Started at $now on $now_date"
- echo "Writing information to refresh-$now_date.log"
- echo "After Refresh, We will be Running an $job "
- if [ $do_wait = "TRUE" ]; then echo "Waiting for $procpid"
- fi
- if [ $time_enforce = "TRUE" ] ; then echo "We WILL be enforcing production Times"
- fi
- if [ $no_refresh = "TRUE" ] ; then echo "We WILL NOT be refreshing"
- fi
- echo "Are the above commands correct? (y/n)"
- if [ $unattended != TRUE ]; then
- read BUF1
- if [ $BUF1 != y ]; then
- echo "Cancelled on User Request!"
- exit -1
- fi
- fi
- if [ $no_refresh != TRUE ] ; then
- refresh
- fi
- job
- }
- refresh () {
- if [ $do_wait == "TRUE" ]; then
- echo "Waiting for $procpid before Refreshing and running an $job"
- wlog "Waiting for $procpid"
- while ps -p $procpid > /dev/null; do sleep 60; done
- wlog "$procpid no longer running, waiting 2 minutes for sanity, then running."
- echo "$procpid no longer running, waiting 2 minutes for sanity, then running."
- echo "$procpid finished, 20 minute sleep" | mail -s "Wait for $procpid, 20 minute timeout before REFRESHING!" $mailid
- sleep 20
- fi
- if [ $time_enforce == "TRUE" ]; then
- get_now
- while [ $now -lt 2200 ] && [ $now -gt 0900 ]; do
- wlog "NOTICE: It is now $now , OUTSIDE production hours trying again in 1800 secs"
- echo "(Refresh) Outside Production Hours, Waiting"
- sleep 18
- get_now
- done
- echo "Starting ARIS Refresh at $now" | mail -s "Wait Complete, Starting Refresh" $mailid
- fi
- if [ -e /opt/aris/integration/bin/tmp/master_dwdb.gc.lock ]; then
- echo "something is running, or a left lock, exiting"
- wlog "ERROR: Lockfile found"
- exit -1
- fi
- get_now
- echo "Starting KVDS Refresh"
- wlog "START: Starting KVDS Refresh at $now"
- sudo -u groundcontrol /opt/aris/integration/ground_control/refresh.py -i refresh_kvds
- if [ -e /opt/aris/integration/bin/tmp/master_dwdb.gc.lock ]; then
- echo "something is running, or a left lock, exiting"
- wlog "ERROR: Lockfile found"
- exit -1
- fi
- get_now
- echo "Starting ETL-TXDB"
- wlog "DONE: KVDS at $now"
- wlog "START: ETL-TXDB at $now"
- sudo -u groundcontrol /opt/aris/integration/ground_control/refresh.py -i post_etl_txdb_refresh
- get_now
- wlog "DONE: ETL-TXDB at $now"
- if [ -e /opt/aris/integration/bin/tmp/views_txdb.gc.lock ]; then
- echo "something is running, or a left lock, exiting"
- wlog "ERROR: Lockfile found"
- exit -1
- fi
- if [ -e /opt/aris/integration/bin/tmp/master_dwdb.gc.lock ]; then
- echo "something is running, or a left lock, exiting"
- wlog "ERROR: Lockfile found"
- exit -1
- fi
- get_now
- wlog "START: KM jobs at $now in BACKGROUND"
- nohup /home/jmarkowitz/km_jobs.sh &
- #sleep 30
- get_now
- }
- job () {
- get_now
- if [ $do_wait == "TRUE" ]; then
- echo "Waiting for $procpid before Refreshing and running an $job"
- wlog "Waiting for $procpid"
- while ps -p $procpid > /dev/null; do sleep 60; done
- wlog "$procpid no longer running, waiting 2 minutes for sanity, then running."
- echo "$procpid no longer running, waiting 2 minutes for sanity, then running."
- echo "$procpid finished, 20 minute sleep" | mail -s "Wait for $procpid, 20 minute timeout before $job" $mailid
- sleep 20
- fi
- get_now
- if [ $time_enforce == "TRUE" ]; then
- while [ $now -lt 2230 ] && [ $now -gt 0700 ]; do
- wlog "NOTICE: $job OUTSIDE production hours, waiting 30 seconds then trying again"
- echo "Waiting for production hours to start $job , it is $now which is not between 2230 and 0700"
- sleep 30
- get_now
- done
- fi
- wlog "Starting $job at $now"
- echo "Starting $job at $now" | mail -s "$job started" $mailid
- sudo -u groundcontrol /opt/aris/integration/ground_control/refresh.py $job
- exit 0
- }
- usage
- confirm
Add Comment
Please, Sign In to add comment