added variables for logfile and haproxy configcheck

This commit is contained in:
panda 2022-01-16 02:15:16 +01:00
parent bbff12393a
commit 4804361292

View file

@ -8,6 +8,9 @@ ssh-add "{{ hap_git_key }}"
git_repo="{{ hap_git_repo }}" git_repo="{{ hap_git_repo }}"
folder_dest="{{ hap_git_dest }}" folder_dest="{{ hap_git_dest }}"
hap_folder="{{ hap_git_folder }}" hap_folder="{{ hap_git_folder }}"
hap_path="{{ hap_git_bin }}"
logfile="{{ hap_git_logfile }}"
#update the status of the repo (without pulling or modifing): #update the status of the repo (without pulling or modifing):
git -C $folder_dest fetch git -C $folder_dest fetch
@ -18,14 +21,34 @@ git_after=$(git -C $folder_dest rev-parse @{u})
#compare the status before and after the fetch, if it's different it mwans there are change in the repo. so we'll need to pull it and update the files: #compare the status before and after the fetch, if it's different it mwans there are change in the repo. so we'll need to pull it and update the files:
if [ "$git_before" != "$git_after" ]; then if [ "$git_before" != "$git_after" ]; then
echo "differensies" echo "$(date +"%Y-%m-%d_%H:%M:%S") - INFO - the repo has been modified, doing my thing" | tee -a $logfile
git -C $folder_dest pull --ff-only git -C $folder_dest pull --ff-only >/dev/null 2>&1
cp $folder_dest/haproxy.cfg $hap_folder/haproxy.cfg echo "$(date +"%Y-%m-%d_%H:%M:%S") - INFO - testing newer haproxy configfile" | tee -a $logfile
systemctl restart haproxy
#test the new configfile, if it's ok then update haproxy config and restart the service
if $hap_path -c -V -f $folder_dest/haproxy.cfg >/dev/null 2>&1; then
echo "$(date +"%Y-%m-%d_%H:%M:%S") - INFO - haproxy file syntax is ok, deploying in production" | tee -a $logfile
cp $folder_dest/haproxy.cfg $hap_folder/haproxy.cfg
systemctl restart haproxy
else
echo "$(date +"%Y-%m-%d_%H:%M:%S") - ERROR - the test of the new haproxy configfile FAILED!" | tee -a $logfile
fi
echo "- - -" | tee -a $logfile
fi fi
#to keep the local version always the same as the repo's one, in this block we check if the local and repo's file are different, if they are we rewrite the local one because we want the changes to come only from the repo
if ! cmp $folder_dest/haproxy.cfg $hap_folder/haproxy.cfg >/dev/null 2>&1 if ! cmp $folder_dest/haproxy.cfg $hap_folder/haproxy.cfg >/dev/null 2>&1
then then
cp $folder_dest/haproxy.cfg $hap_folder/haproxy.cfg echo "$(date +"%Y-%m-%d_%H:%M:%S") - WARNING - the local and repo's versions of the configfile differs, resyncing" | tee -a $logfile
systemctl restart haproxy if $hap_path -c -V -f $folder_dest/haproxy.cfg >/dev/null 2>&1; then
echo "$(date +"%Y-%m-%d_%H:%M:%S") - INFO - !diff local remote! resyncing - haproxy file syntax is ok, deploying in production" | tee -a $logfile
cp $folder_dest/haproxy.cfg $hap_folder/haproxy.cfg
systemctl restart haproxy
else
echo "$(date +"%Y-%m-%d_%H:%M:%S") - ERROR - !diff local remote! resyncing - the test of the new haproxy configfile FAILED!" | tee -a $logfile
fi
fi fi