preparing to schedule ansible-pull.sh

This commit is contained in:
2026-07-26 12:03:03 -05:00
parent e1592fca85
commit 8b50cacb1b
2 changed files with 44 additions and 37 deletions
+19 -11
View File
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# - Process command line
GIT_REPO_BRANCH="production"
@@ -14,10 +14,18 @@ while [ $# -gt 0 ]; do
GIT_REPO_BRANCH="$1"
shift 1
;;
--)
shift 1
break
;;
*)
echo "$0: ERROR - Invalid argument." ; exit 2
;;
esac
done
# - Include ansible virtual environment
# - Include ansible virtual environment (in case not already done - we don't know how we're being run)
VIRTUAL_ENV_DISABLE_PROMPT=true
. "${HOME}/.ansible-venv/bin/activate"
SCRIPT_NAME="$(basename "${0}")"
@@ -27,17 +35,17 @@ LOG_DIR="/var/log/ansible-pull.sh"
LOG_FILE="${LOG_DIR}/ansible-pull.sh.log"
LOCK_FILE="/tmp/ansible-pull.sh.lock"
# - Redirect all further output to the log file
#???????????????????????????????? change the following to lock the log file?
# - If we can't lock the lock file, don't proceed
if ! exec 9>"${LOCK_FILE}" ; then echo "ERROR - Unable to open the lock file (${LOCK_FILE})! Exiting..." ; exit 10 ; fi
if ! flock -n 9 ; then echo "ERROR - Another copy of ${SCRIPT_NAME} is already running! Exiting..." ; exit 11 ; fi
# - Append all further STDOUT and STDERR to the log file
exec >>"${LOG_FILE}" 2>&1
# - Log that we've gotten this far
echo -n "$(basename "${0}"): $(date "+%Y-%m-%d %H:%M:%S")"
# - If we can't lock the lock file, don't proceed
exec 9>"${LOCK_FILE}"
if ! flock -n 9 ; then echo " - ERROR - Another copy of ${SCRIPT_NAME} is already running! Exiting..." ; exit 1 ; fi
echo "$(basename "${0}"): $(date "+%Y-%m-%d %H:%M:%S")"
# - Do our work
echo
ansible-pull --only-if-changed --url "${GIT_REPO}" --checkout "${GIT_REPO_BRANCH}" "${@}"
ansible-pull --only-if-changed --url "${GIT_REPO}" --checkout "${GIT_REPO_BRANCH}" "${@}"