Guest User

Untitled

a guest
Jun 21st, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.15 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. get_now () {
  4. now=`date +%H%M`
  5. now_date=`date +%m%d%Y`
  6. }
  7.  
  8. get_now
  9. log=daily-refresh-$now_date.log
  10. touch $log
  11.  
  12. let do_wait=FALSE
  13. let unattended=FALSE
  14. let time_enforce=FALSE
  15. let wait_prod=FALSE
  16. let no_refresh=FALSE
  17. mailid="5189294515@vtext.com"
  18.  
  19. while getopts "j: w p: u t d " options; do
  20.         case $options in
  21.                 j ) job=$OPTARG
  22.                 ;;
  23.                 w ) do_wait=TRUE
  24.                 ;;
  25.                 p ) procpid=$OPTARG
  26.                 ;;
  27.                 u ) unattended=TRUE
  28.                 ;;
  29.                 t ) time_enforce=TRUE
  30.         ;;
  31.         d ) no_refresh=TRUE
  32.                 ;;
  33.                 \? ) echo "bad arg"
  34.                 usage
  35.                 ;;
  36.                 * ) echo "bad arg"
  37.                 usage
  38.                 ;;
  39.         esac
  40. done
  41.  
  42. usage () {
  43. echo "
  44. Aris GC Automated Controller
  45. Usage:
  46.  
  47. -j <job>        Sets the job, etl_daily or etl_weekly
  48. -w              Wait for existing GC job to finish
  49. -p <pid>        Pid of existing GC job to watch
  50. -u              Unattended mode, assumes YES to confirmation DANGEROUS!
  51. -t              Enforce Production Time Slots (RECOMENDED!)
  52. -d      Dont refresh, just run $job
  53. Refresh will ALWAYS run prior to the job running unless -d is specified
  54. "
  55.  
  56. }
  57.  
  58. wlog () {
  59. echo $1- >> $log
  60. }
  61.  
  62.  
  63. confirm () {
  64.  
  65. get_now
  66. echo "Nightly Refresh/Daily Script Started at $now on $now_date"
  67. echo "Writing information to refresh-$now_date.log"
  68. echo "After Refresh, We will be Running an $job "
  69. if [ $do_wait = "TRUE" ]; then echo "Waiting for $procpid"
  70. fi
  71.  
  72. if [ $time_enforce = "TRUE" ] ; then echo "We WILL be enforcing production Times"
  73. fi
  74.  
  75. if [ $no_refresh = "TRUE" ] ; then echo "We WILL NOT be refreshing"
  76. fi
  77. echo "Are the above commands correct? (y/n)"
  78.  
  79. if [ $unattended != TRUE ]; then
  80.         read BUF1
  81.         if [ $BUF1 != y ]; then
  82.                 echo "Cancelled on User Request!"
  83.                 exit -1
  84.         fi
  85. fi
  86.  
  87. if [ $no_refresh != TRUE ] ; then
  88. refresh
  89. fi
  90.  
  91.  
  92. job
  93.  
  94. }
  95.  
  96.  
  97. refresh () {
  98.  
  99. if [ $do_wait == "TRUE" ]; then
  100. echo "Waiting for $procpid before Refreshing and running an $job"
  101. wlog "Waiting for $procpid"
  102. while ps -p $procpid > /dev/null; do sleep 60; done
  103. wlog "$procpid no longer running, waiting 2 minutes for sanity, then running."
  104. echo "$procpid no longer running, waiting 2 minutes for sanity, then running."
  105. echo "$procpid finished, 20 minute sleep" | mail -s "Wait for $procpid, 20 minute timeout before REFRESHING!" $mailid
  106. sleep 20
  107. fi
  108.  
  109. if [ $time_enforce == "TRUE" ]; then
  110. get_now
  111.         while [ $now -lt 2200 ] && [ $now -gt 0900 ]; do
  112.                 wlog "NOTICE: It is now $now , OUTSIDE production hours trying again in 1800 secs"
  113.                 echo "(Refresh) Outside Production Hours, Waiting"
  114.                 sleep 18
  115.                 get_now
  116.         done
  117. echo "Starting ARIS Refresh at $now" | mail -s "Wait Complete, Starting Refresh" $mailid
  118. fi
  119.  
  120.  
  121. if [ -e /opt/aris/integration/bin/tmp/master_dwdb.gc.lock ]; then
  122.     echo "something is running, or a left lock, exiting"
  123.     wlog "ERROR: Lockfile found"
  124.     exit -1
  125. fi
  126. get_now
  127. echo "Starting KVDS Refresh"
  128. wlog "START: Starting KVDS Refresh at $now"
  129. sudo -u groundcontrol /opt/aris/integration/ground_control/refresh.py -i refresh_kvds
  130.  
  131. if [ -e /opt/aris/integration/bin/tmp/master_dwdb.gc.lock ]; then
  132.     echo "something is running, or a left lock, exiting"
  133.     wlog "ERROR: Lockfile found"
  134.     exit -1
  135. fi
  136.  
  137. get_now
  138. echo "Starting ETL-TXDB"
  139. wlog "DONE: KVDS at $now"
  140. wlog "START: ETL-TXDB at $now"
  141. sudo -u groundcontrol /opt/aris/integration/ground_control/refresh.py -i post_etl_txdb_refresh
  142. get_now
  143. wlog  "DONE: ETL-TXDB at $now"
  144.  
  145. if [ -e /opt/aris/integration/bin/tmp/views_txdb.gc.lock ]; then
  146.     echo "something is running, or a left lock, exiting"
  147.     wlog "ERROR: Lockfile found"
  148.     exit -1
  149. fi
  150. if [ -e /opt/aris/integration/bin/tmp/master_dwdb.gc.lock ]; then
  151.     echo "something is running, or a left lock, exiting"
  152.     wlog "ERROR: Lockfile found"
  153.     exit -1
  154. fi
  155.  
  156. get_now
  157. wlog "START: KM jobs at $now in BACKGROUND"
  158. nohup /home/jmarkowitz/km_jobs.sh &
  159.  
  160. #sleep 30
  161. get_now
  162. }
  163.  
  164. job () {
  165. get_now
  166. if [ $do_wait == "TRUE" ]; then
  167. echo "Waiting for $procpid before Refreshing and running an $job"
  168. wlog "Waiting for $procpid"
  169. while ps -p $procpid > /dev/null; do sleep 60; done
  170. wlog "$procpid no longer running, waiting 2 minutes for sanity, then running."
  171. echo "$procpid no longer running, waiting 2 minutes for sanity, then running."
  172. echo "$procpid finished, 20 minute sleep" | mail -s "Wait for $procpid, 20 minute timeout before $job" $mailid
  173. sleep 20
  174. fi
  175.  
  176. get_now
  177. if [ $time_enforce == "TRUE" ]; then
  178.         while [ $now -lt 2230 ] && [ $now -gt 0700 ]; do
  179.             wlog "NOTICE: $job OUTSIDE production hours, waiting 30 seconds then trying again"
  180.             echo "Waiting for production hours to start $job , it is $now which is not between 2230 and 0700"
  181.             sleep 30
  182.             get_now
  183.         done
  184. fi
  185. wlog "Starting $job at $now"
  186. echo "Starting $job at $now" | mail -s "$job started" $mailid
  187. sudo -u groundcontrol /opt/aris/integration/ground_control/refresh.py $job
  188. exit 0
  189.  
  190. }
  191.  
  192. usage
  193.  
  194. confirm
Add Comment
Please, Sign In to add comment