clean up ansible-pull logging and lock against concurrent runs
This commit is contained in:
@@ -36,6 +36,8 @@ HPF_ANS_activate="${HPF_ANS_ansible_venv}/bin/activate"
|
|||||||
HPF_ANS_bin="\${HOME}/bin"
|
HPF_ANS_bin="\${HOME}/bin"
|
||||||
HPF_ANS_ansible_pull_sh="${HPF_ANS_bin}/ansible-pull.sh"
|
HPF_ANS_ansible_pull_sh="${HPF_ANS_bin}/ansible-pull.sh"
|
||||||
|
|
||||||
|
ANSIBLE_PULL_SH_LOG_DIR="/var/log/ansible-pull.sh"
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
#### FUNCTIONS
|
#### FUNCTIONS
|
||||||
@@ -143,5 +145,9 @@ as_hpf_ans "rm \"${HPF_ANS_ansible_pull_sh}\" 2>/dev/null"
|
|||||||
as_hpf_ans "curl -o \"${HPF_ANS_ansible_pull_sh}\" \"${GIT_REPO_ansible_pull_sh}\""
|
as_hpf_ans "curl -o \"${HPF_ANS_ansible_pull_sh}\" \"${GIT_REPO_ansible_pull_sh}\""
|
||||||
as_hpf_ans "chown hpf-ans:hpf-ans \"${HPF_ANS_ansible_pull_sh}\"; chmod u=rwx,go= \"${HPF_ANS_ansible_pull_sh}\""
|
as_hpf_ans "chown hpf-ans:hpf-ans \"${HPF_ANS_ansible_pull_sh}\"; chmod u=rwx,go= \"${HPF_ANS_ansible_pull_sh}\""
|
||||||
|
|
||||||
|
# Make sure log directory exists
|
||||||
|
mkdir -p "${ANSIBLE_PULL_SH_LOG_DIR}"
|
||||||
|
chown hpf-ans:root "${ANSIBLE_PULL_SH_LOG_DIR}"; chmod ug=rwx,o= "${ANSIBLE_PULL_SH_LOG_DIR}"
|
||||||
|
|
||||||
# Run ansible-pull to finish up
|
# Run ansible-pull to finish up
|
||||||
as_hpf_ans "bin/ansible-pull.sh bootstrap.yml"
|
as_hpf_ans "bin/ansible-pull.sh bootstrap.yml"
|
||||||
|
|||||||
+15
-1
@@ -114,4 +114,18 @@
|
|||||||
backup: true
|
backup: true
|
||||||
become: no
|
become: no
|
||||||
|
|
||||||
#### - Create crontab entry for production branch
|
- name: Make sure log directory exists
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /var/log/ansible-pull.sh
|
||||||
|
state: directory
|
||||||
|
owner: hpf-ans
|
||||||
|
group: root
|
||||||
|
mode: ug=rwx,o=
|
||||||
|
|
||||||
|
# - name: Create ansible-pull.sh crontab entry
|
||||||
|
# ansible.builtin.cron:
|
||||||
|
# name: "ansible-pull"
|
||||||
|
# minute: "*/27"
|
||||||
|
# job: $HOME/bin/ansible-pull.sh
|
||||||
|
# backup: true
|
||||||
|
# become: no
|
||||||
|
|||||||
@@ -4,21 +4,24 @@
|
|||||||
|
|
||||||
. "${HOME}/.ansible-venv/bin/activate"
|
. "${HOME}/.ansible-venv/bin/activate"
|
||||||
|
|
||||||
|
SCRIPT_NAME="$(basename "${0}")"
|
||||||
GIT_REPO_BASE="https://gitea.admin-a.hpetersenfamily.com/heath/ansible"
|
GIT_REPO_BASE="https://gitea.admin-a.hpetersenfamily.com/heath/ansible"
|
||||||
GIT_REPO="${GIT_REPO_BASE}.git"
|
GIT_REPO="${GIT_REPO_BASE}.git"
|
||||||
LOG_FILE="/var/log/ansible-pull.sh.log"
|
LOG_DIR="/var/log/ansible-pull.sh"
|
||||||
|
LOG_FILE="${LOG_DIR}/ansible-pull.sh.log"
|
||||||
LOCK_FILE="/tmp/ansible-pull.sh.lock"
|
LOCK_FILE="/tmp/ansible-pull.sh.lock"
|
||||||
|
|
||||||
# - Redirect all further output to the log file and create a lock file
|
# - Redirect all further output to the log file
|
||||||
exec >>"${LOG_FILE}" 2>&1 9>"${LOCK_FILE}"
|
exec >>"${LOG_FILE}" 2>&1
|
||||||
|
|
||||||
# - Log that we've gotten this far
|
# - Log that we've gotten this far
|
||||||
echo
|
echo -n "$(basename "${0}"): $(date "+%Y-%m-%d %H:%M:%S")"
|
||||||
echo "$(basename "${0}"): $(date "+%Y-%m-%d %H:%M:%S")"
|
|
||||||
echo "----------"
|
|
||||||
|
|
||||||
# - If we can't lock the lock file, don't proceed
|
# - If we can't lock the lock file, don't proceed
|
||||||
if ! flock -n 9; then echo "ERROR - Another copy of ansible-pull.sh is already running! Exiting..." ; exit 1 ; fi
|
exec 9>"${LOCK_FILE}"
|
||||||
|
if ! flock -n 9 ; then echo " - ERROR - Another copy of ${SCRIPT_NAME} is already running! Exiting..." ; exit 1 ; fi
|
||||||
|
|
||||||
# - Do our work
|
# - Do our work
|
||||||
|
echo
|
||||||
ansible-pull --only-if-changed --url "${GIT_REPO}" --checkout main "${@}"
|
ansible-pull --only-if-changed --url "${GIT_REPO}" --checkout main "${@}"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user