Add recipe check auto-update and some corrections

This commit is contained in:
nemo 2019-06-23 16:20:23 +02:00
parent cc4109c11d
commit 2645e5cf95
6 changed files with 63 additions and 6 deletions

View file

@ -13,8 +13,7 @@ If you cannot execute the script, add the 'x' permission for the user (chmod u+x
Not finished, in progress.... Not finished, in progress....
TO DO : TO DO :
- Check if borgbackup is configured (OK, need to be fully tested) - Test the recipe check auto-backup (OK, not fully tested)
- Check if auto-update script is configured
- Others (script design, documentation...) - Others (script design, documentation...)
Checked point : Checked point :
@ -36,4 +35,6 @@ Checked point :
- Check portage configuration (FEATURES, PORTAGE_BINHOST, ACCEPT_LICENSE, USE, CHOST, GRUB_PLATFORMS, CPU_FLAGS_X86 and if GENTOO_MIRRORS includes organization mirror) - Check portage configuration (FEATURES, PORTAGE_BINHOST, ACCEPT_LICENSE, USE, CHOST, GRUB_PLATFORMS, CPU_FLAGS_X86 and if GENTOO_MIRRORS includes organization mirror)
- Check if IPs (scope global) are recorded in IPAM - Check if IPs (scope global) are recorded in IPAM
- Check if the selected Gentoo profile is the expected profile - Check if the selected Gentoo profile is the expected profile
- Check if auto-update script is configured (presence, executable and if cron task is configured)
- Check if auto-backup script is configured (presence, executable, content, connection to remote service, if cron task is configured ...)
- Print additional manuel verification (send reporting mail, if /etc conf file need to be updated, if a new kernel can be installed, if server-side for Icinga, SNMP and Munin are configured) - Print additional manuel verification (send reporting mail, if /etc conf file need to be updated, if a new kernel can be installed, if server-side for Icinga, SNMP and Munin are configured)

View file

@ -55,6 +55,7 @@ export MAIL_ALIAS_CONFIG_CHECK_FAILED=""
export SNMP_CONFIG_CHECK_FAILED="" export SNMP_CONFIG_CHECK_FAILED=""
export POSTFIX_CONFIG_CHECK_FAILED="" export POSTFIX_CONFIG_CHECK_FAILED=""
export AUTOBACKUP_CONFIG_CHECK_FAILED="" export AUTOBACKUP_CONFIG_CHECK_FAILED=""
export AUTOUPDATE_CONFIG_CHECK_FAILED=""
export IPAM_CONFIG_CHECK_FAILED="" export IPAM_CONFIG_CHECK_FAILED=""
export PORTAGE_CONFIG_CHECK_FAILED="" export PORTAGE_CONFIG_CHECK_FAILED=""
export SERVICES_NOT_STARTED_OR_ERROR="" export SERVICES_NOT_STARTED_OR_ERROR=""
@ -132,7 +133,11 @@ print_config_title 'RECIPE GENTOO - CHECK BASIC CONFIG'
#. recipes/recipe_check_eselect.sh #. recipes/recipe_check_eselect.sh
. recipes/recipe_check_portage.sh #. recipes/recipe_check_autobackup_config.sh
. recipes/recipe_check_autoupdate_config.sh
#. recipes/recipe_check_portage.sh
. recipes/recipe_final_summary.sh . recipes/recipe_final_summary.sh

View file

@ -1,6 +1,7 @@
print_config_title 'CHECK AUTO-BACKUP' print_config_title 'CHECK AUTO-BACKUP'
# Check if auto-backup script is present # Check if auto-backup script is present
echo "Check if auto-update script is present"
if [[ -f "${BACKUP_SCRIPT}" ]] if [[ -f "${BACKUP_SCRIPT}" ]]
then then
echo -e "${GREEN}The auto-backup script is present : check OK${NC}\n" echo -e "${GREEN}The auto-backup script is present : check OK${NC}\n"
@ -10,6 +11,7 @@ else
fi fi
# Check the script (content) # Check the script (content)
echo "Check the script (content)"
grep -q 'borg prune -v backup@loth.grifon.fr' ${BACKUP_SCRIPT} grep -q 'borg prune -v backup@loth.grifon.fr' ${BACKUP_SCRIPT}
RCa=${?} # First Return Code RCa=${?} # First Return Code
grep -q 'borg create --info .* backup@loth.grifon.fr:$(hostname -s)::$(date +%F)' ${BACKUP_SCRIPT} grep -q 'borg create --info .* backup@loth.grifon.fr:$(hostname -s)::$(date +%F)' ${BACKUP_SCRIPT}
@ -25,6 +27,7 @@ fi
# Check if the script is executable # Check if the script is executable
echo "Check if the script is executable"
if [[ -x "${BACKUP_SCRIPT}" ]] if [[ -x "${BACKUP_SCRIPT}" ]]
then then
echo -e "${GREEN}The auto-backup script is executable : check OK${NC}\n" echo -e "${GREEN}The auto-backup script is executable : check OK${NC}\n"
@ -34,6 +37,7 @@ else
fi fi
# Check the ssh connection to the backup server # Check the ssh connection to the backup server
echo "Check the ssh connection to the backup server"
ssh -q ${BACKUP_REMOTE_USER}@${BACKUP_REMOTE_SERVER} exit ssh -q ${BACKUP_REMOTE_USER}@${BACKUP_REMOTE_SERVER} exit
if [[ ${?} -ne 0 ]] if [[ ${?} -ne 0 ]]
then then
@ -45,6 +49,7 @@ else
fi fi
# Check if the remote repertory exist and is writable # Check if the remote repertory exist and is writable
echo "Check if the remote repertory exist and is writable"
ssh ${BACKUP_REMOTE_USER}@${BACKUP_REMOTE_SERVER} "test -w ${BACKUP_REMOTE_REPERTORY}/$(hostname -s)" &>/dev/null ssh ${BACKUP_REMOTE_USER}@${BACKUP_REMOTE_SERVER} "test -w ${BACKUP_REMOTE_REPERTORY}/$(hostname -s)" &>/dev/null
if [[ ${?} -ne 0 ]] if [[ ${?} -ne 0 ]]
then then
@ -56,6 +61,7 @@ else
fi fi
# Check if the remote link exist and is writable : when a backup is done, the script set the destination : ~/$(hostname -s) which is a link to ${BACKUP_REMOTE_REPERTORY}/$(hostname -s) # Check if the remote link exist and is writable : when a backup is done, the script set the destination : ~/$(hostname -s) which is a link to ${BACKUP_REMOTE_REPERTORY}/$(hostname -s)
echo "Check if the remote link exist and is writable"
ssh ${BACKUP_REMOTE_USER}@${BACKUP_REMOTE_SERVER} "test -w $(hostname -s)" &>/dev/null ssh ${BACKUP_REMOTE_USER}@${BACKUP_REMOTE_SERVER} "test -w $(hostname -s)" &>/dev/null
if [[ ${?} -ne 0 ]] if [[ ${?} -ne 0 ]]
then then
@ -67,11 +73,12 @@ else
fi fi
# Check if the cron task is configured # Check if the cron task is configured
crontab -l |grep -q '${BACKUP_SCRIPT}' echo "Check if the cron task is configured"
crontab -l 2>/dev/null | grep -q "${BACKUP_SCRIPT}"
RCa=${?} # First Return Code RCa=${?} # First Return Code
grep -q '${BACKUP_SCRIPT}' /etc/cron.d/* grep -q "${BACKUP_SCRIPT}" /etc/cron.d/*
RCb=${?} # Second Return Code RCb=${?} # Second Return Code
grep -q '${BACKUP_SCRIPT}' /etc/crontab grep -q "${BACKUP_SCRIPT}" /etc/crontab
RCc=${?} # Third Return Code RCc=${?} # Third Return Code
if [[ ${RCa} -ne 0 ]] && [[ ${RCb} -ne 0 ]] && [[ ${RCc} -ne 0 ]] if [[ ${RCa} -ne 0 ]] && [[ ${RCb} -ne 0 ]] && [[ ${RCc} -ne 0 ]]
then then

View file

@ -0,0 +1,38 @@
print_config_title 'CHECK AUTO-UPDATE'
# Check if auto-update script is present
echo "Check if auto-update script is present"
if [[ -f "${AUTOUPDATE_SCRIPT}" ]]
then
echo -e "${GREEN}The auto-update script is present : check OK${NC}\n"
else
AUTOUPDATE_CONFIG_CHECK_FAILED=${AUTOUPDATE_CONFIG_CHECK_FAILED}" The auto-update script is NOT on the system;"
echo -e "${RED}The auto-update is NOT on the system : check KO${NC}\n"
fi
# Check if the auto-update script is executable
echo "Check if the auto-update script is executable"
if [[ -x "${AUTOUPDATE_SCRIPT}" ]]
then
echo -e "${GREEN}The auto-update script is executable : check OK${NC}\n"
else
AUTOUPDATE_CONFIG_CHECK_FAILED=${AUTOUPDATE_CONFIG_CHECK_FAILED}" The auto-update script is NOT executable;"
echo -e "${RED}The auto-update script is NOT executable: check KO${NC}\n"
fi
# Check if the auto-update cron task is configured
echo "Check if the cron task is configured"
crontab -l 2>/dev/null | grep -q "${AUTOUPDATE_SCRIPT}"
RCa=${?} # First Return Code
grep -q "${AUTOUPDATE_SCRIPT}" /etc/cron.d/*
RCb=${?} # Second Return Code
grep -q "${AUTOUPDATE_SCRIPT}" /etc/crontab
RCc=${?} # Third Return Code
if [[ ${RCa} -ne 0 ]] && [[ ${RCb} -ne 0 ]] && [[ ${RCc} -ne 0 ]]
then
AUTOUPDATE_CONFIG_CHECK_FAILED=${AUTOUPDATE_CONFIG_CHECK_FAILED}" No cron entry for auto-update, configure it;"
echo -e "${RED}NO cron entry for auto-update : check KO${NC}\n"
# Service started without error
else
echo -e "${GREEN}Cron entry for auto-update exist: check OK${NC}\n"
fi

View file

@ -41,4 +41,8 @@ print_config_title 'FINAL SUMMARY'
[ ! -z "${PORTAGE_CONFIG_CHECK_FAILED}" ] && echo -e "${RED}PORTAGE CONFIG TO CHECK :${NC} ${PORTAGE_CONFIG_CHECK_FAILED}\n" [ ! -z "${PORTAGE_CONFIG_CHECK_FAILED}" ] && echo -e "${RED}PORTAGE CONFIG TO CHECK :${NC} ${PORTAGE_CONFIG_CHECK_FAILED}\n"
[ ! -z "${AUTOBACKUP_CONFIG_CHECK_FAILED}" ] && echo -e "${RED}AUTOBACKUP CONFIG TO CHECK :${NC} ${AUTOBACKUP_CONFIG_CHECK_FAILED}\n"
[ ! -z "${AUTOUPDATE_CONFIG_CHECK_FAILED}" ] && echo -e "${RED}AUTOUPDATE CONFIG TO CHECK :${NC} ${AUTOUPDATE_CONFIG_CHECK_FAILED}\n"
[ ${WRONG_GENTOO_PROFILE_SELECTED} -ne 0 ] && echo -e "${RED}Wrong Gentoo profile selecte :${NC} select ${GENTOO_PROFILE} profile with \"eselect profile list / set [ID]\"\n" [ ${WRONG_GENTOO_PROFILE_SELECTED} -ne 0 ] && echo -e "${RED}Wrong Gentoo profile selecte :${NC} select ${GENTOO_PROFILE} profile with \"eselect profile list / set [ID]\"\n"

View file

@ -150,3 +150,5 @@ export PORTAGE_CPU_FLAGS_X86="mmx mmxext sse sse2 sse3"
export PORTAGE_ORGANIZATION_MIRROR="http://mirror.example.com/gentoo" export PORTAGE_ORGANIZATION_MIRROR="http://mirror.example.com/gentoo"
export PORTAGE_GRUB_PLATFORMS="pc" export PORTAGE_GRUB_PLATFORMS="pc"
# AUTOUPDATE CHECK
export AUTOUPDATE_SCRIPT="/usr/local/sbin/check_updates.sh"