Advertisement
Guest User

Untitled

a guest
Dec 19th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.92 KB | None | 0 0
  1. #!/bin/sh
  2. # To be run from cron to only do highstates if a salt-call is not currently running.
  3. # Also moves the /tmp/highstate.cron file to /tmp/highstate.back so that the current - and one prior - outputs are available
  4. testflag=
  5. while getopts 'htl:' OPTION; do
  6.   case $OPTION in
  7.      h)     printf "Usage: %s: [-t (test run only)] [-h (prints this help)] [-l (set log level (debug|warning|info) Default is error)]\n" $(basename $0) >&2; exit 2 ;;
  8.      t)     testflag=" test=True" ;;
  9.      l)     LOG_LEVEL="$OPTARG" ;;
  10.      \?)    echo "Invalid option: -$OPTARG" >&2 ;;
  11.      :)     echo "Missing option argument for -$OPTARG" >&2; exit 1;;
  12.   esac
  13.   shift $((OPTIND -1))
  14. done
  15.  
  16. ################################################################################
  17. # TEMPORARY UNTIL BLABLABLA CAN BE RESOLVED:
  18. # MOVE TMP?????? FILES FROM /usr/local/saltstack/clones/ to /tmp/ where tmpwatch can clean them.
  19. /opt/ns/scripts/sudotry /bin/nice -n +10 /bin/mv -f -- /usr/local/saltstack/clones/tmp?????? /tmp/ > /dev/null 2>&1
  20. ################################################################################
  21.  
  22. RUNNING_STATES=$(/opt/ns/scripts/sudotry salt-call --out=txt --local state.running)
  23.  
  24. if [[ $LOG_LEVEL == "debug" ]] || [[ $LOG_LEVEL == "warning" ]] || [[ $LOG_LEVEL == "info" ]];
  25.    then
  26.       LOG_LEVEL=$LOG_LEVEL
  27.    else
  28.       LOG_LEVEL="error"
  29. fi
  30.  
  31. for i in {1..5}; do
  32.   if [[ $RUNNING_STATES =~ (state.highstate|state.apply|state.sls) ]]; then
  33.     logger -t "highstate.sh" "Failed to run highstate.sh.  There was already a job running. Attempt $i"
  34.     sleep 5;
  35.   else
  36.     /usr/bin/[ -f /tmp/highstate.cron ] && /opt/ns/scripts/sudotry /bin/mv -f /tmp/highstate.cron /tmp/highstate.back
  37.     logger -t "highstate.sh" "Beginning state.highstate run."
  38.     /opt/ns/scripts/sudotry /bin/nice -n +10 /usr/bin/salt-call state.highstate queue=True${testflag} --log-file=/tmp/highstate.cron --log-file-level=$LOG_LEVEL
  39.     break
  40.   fi
  41. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement