Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # To be run from cron to only do highstates if a salt-call is not currently running.
- # Also moves the /tmp/highstate.cron file to /tmp/highstate.back so that the current - and one prior - outputs are available
- testflag=
- while getopts 'htl:' OPTION; do
- case $OPTION in
- 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 ;;
- t) testflag=" test=True" ;;
- l) LOG_LEVEL="$OPTARG" ;;
- \?) echo "Invalid option: -$OPTARG" >&2 ;;
- :) echo "Missing option argument for -$OPTARG" >&2; exit 1;;
- esac
- shift $((OPTIND -1))
- done
- ################################################################################
- # TEMPORARY UNTIL BLABLABLA CAN BE RESOLVED:
- # MOVE TMP?????? FILES FROM /usr/local/saltstack/clones/ to /tmp/ where tmpwatch can clean them.
- /opt/ns/scripts/sudotry /bin/nice -n +10 /bin/mv -f -- /usr/local/saltstack/clones/tmp?????? /tmp/ > /dev/null 2>&1
- ################################################################################
- RUNNING_STATES=$(/opt/ns/scripts/sudotry salt-call --out=txt --local state.running)
- if [[ $LOG_LEVEL == "debug" ]] || [[ $LOG_LEVEL == "warning" ]] || [[ $LOG_LEVEL == "info" ]];
- then
- LOG_LEVEL=$LOG_LEVEL
- else
- LOG_LEVEL="error"
- fi
- for i in {1..5}; do
- if [[ $RUNNING_STATES =~ (state.highstate|state.apply|state.sls) ]]; then
- logger -t "highstate.sh" "Failed to run highstate.sh. There was already a job running. Attempt $i"
- sleep 5;
- else
- /usr/bin/[ -f /tmp/highstate.cron ] && /opt/ns/scripts/sudotry /bin/mv -f /tmp/highstate.cron /tmp/highstate.back
- logger -t "highstate.sh" "Beginning state.highstate run."
- /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
- break
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement