Enable logging on error

This commit is contained in:
Jose
2019-11-23 03:39:50 -04:00
parent 6cbd299024
commit df05aa8876
3 changed files with 17 additions and 26 deletions

View File

@@ -3,6 +3,7 @@
====================== ======================
Version Description Version Description
1.0.16......Enable logging on error.
1.0.15......Ability to restore .tgz archives on ZFS, be more verbose. 1.0.15......Ability to restore .tgz archives on ZFS, be more verbose.
1.0.14......Destroy ZFS dataset before rename. 1.0.14......Destroy ZFS dataset before rename.
1.0.13......Add ability to enable ZFS easily. 1.0.13......Add ability to enable ZFS easily.

View File

@@ -510,15 +510,13 @@ jail_backup()
cd ${CWDIR}/jails && tar ${EXCLUDE} -zcf ${JAIL_NAME}-${DATE}.tgz ${JAIL_NAME} && mv ${JAIL_NAME}-${DATE}.tgz ${CWDIR}/backups cd ${CWDIR}/jails && tar ${EXCLUDE} -zcf ${JAIL_NAME}-${DATE}.tgz ${JAIL_NAME} && mv ${JAIL_NAME}-${DATE}.tgz ${CWDIR}/backups
fi fi
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to backup '${JAIL_NAME}' container." error_notify "Failed to backup '${JAIL_NAME}' container."
exit 1
else else
echo "Exported '${JAIL_NAME}' successfully." echo "Exported '${JAIL_NAME}' successfully."
exit 0 exit 0
fi fi
else else
echo "Container '${JAIL_NAME}' does not exist." error_notify "Container '${JAIL_NAME}' does not exist."
exit 1
fi fi
else else
exit 0 exit 0
@@ -555,13 +553,11 @@ jail_restore()
tar -xf ${CWDIR}/backups/${BACKUP_FILE} --strip-components 1 -C ${CWDIR}/jails/${NAME_TRIM} ${NAME_TRIM}/jail.conf tar -xf ${CWDIR}/backups/${BACKUP_FILE} --strip-components 1 -C ${CWDIR}/jails/${NAME_TRIM} ${NAME_TRIM}/jail.conf
tar -xf ${CWDIR}/backups/${BACKUP_FILE} --strip-components 2 -C ${CWDIR}/jails/${NAME_TRIM}/root ${NAME_TRIM}/root tar -xf ${CWDIR}/backups/${BACKUP_FILE} --strip-components 2 -C ${CWDIR}/jails/${NAME_TRIM}/root ${NAME_TRIM}/root
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to extract files from '${NAME_TRIM}' archive."
zfs destroy -r ${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME_TRIM} zfs destroy -r ${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME_TRIM}
exit 1 error_notify "Failed to extract files from '${NAME_TRIM}' archive."
fi fi
else else
echo "Unknown archive format." error_notify "Unknown archive format."
exit 1
fi fi
fi fi
else else
@@ -569,8 +565,7 @@ jail_restore()
tar -xf ${CWDIR}/backups/${BACKUP_FILE} -C ${CWDIR}/jails tar -xf ${CWDIR}/backups/${BACKUP_FILE} -C ${CWDIR}/jails
fi fi
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to restore '${NAME_TRIM}' container." error_notify "Failed to restore '${NAME_TRIM}' container."
exit 1
else else
mkdir -p ${CWDIR}/jails/${NAME_TRIM}/root/.bastille mkdir -p ${CWDIR}/jails/${NAME_TRIM}/root/.bastille
mkdir -p ${CWDIR}/jails/${NAME_TRIM}/root/.template mkdir -p ${CWDIR}/jails/${NAME_TRIM}/root/.template
@@ -578,16 +573,13 @@ jail_restore()
exit 0 exit 0
fi fi
else else
echo "Container '${NAME_TRIM}' directory/dataset already exist." error_notify "Container '${NAME_TRIM}' directory/dataset already exist."
exit 1
fi fi
else else
echo "Jails directory/dataset does not exist." error_notify "Jails directory/dataset does not exist."
exit 1
fi fi
else else
echo "Archive '${BACKUP_FILE}' does not exist." error_notify "Archive '${BACKUP_FILE}' does not exist."
exit 1
fi fi
} }
@@ -630,9 +622,11 @@ zfs_activate()
echo "Creating a new ZFS dataset for '${BASTILLE_DIR}'" echo "Creating a new ZFS dataset for '${BASTILLE_DIR}'"
zfs create ${bastille_zfs_options} ${bastille_zfs_zpool}/${bastille_zfs_prefix} zfs create ${bastille_zfs_options} ${bastille_zfs_zpool}/${bastille_zfs_prefix}
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to enable ZFS, reverting changes." MSG="Failed to enable ZFS, reverting changes."
echo "${MSG}"
zfs destroy ${bastille_zfs_zpool}/${bastille_zfs_prefix} zfs destroy ${bastille_zfs_zpool}/${bastille_zfs_prefix}
mv ${CWDIR}.old ${CWDIR} mv ${CWDIR}.old ${CWDIR}
logger -t "${SCRIPTNAME}" "${MSG}"
else else
echo "Synchronizing '${BASTILLE_DIR}' data on new dataset" echo "Synchronizing '${BASTILLE_DIR}' data on new dataset"
rsync -a ${CWDIR}.old/ ${CWDIR}/ rsync -a ${CWDIR}.old/ ${CWDIR}/
@@ -642,22 +636,18 @@ zfs_activate()
echo "Bastille ZFS is already configured." echo "Bastille ZFS is already configured."
exit 0 exit 0
else else
echo -e "ERROR: ${bastille_zfs_zpool}/${BASTILLE_DIR} is not a ZFS pool/dataset." error_notify "ERROR: ${bastille_zfs_zpool}/${BASTILLE_DIR} is not a ZFS pool/dataset."
exit 1
fi fi
fi fi
else else
echo -e "ERROR: ${bastille_zfs_zpool} is not a ZFS pool/dataset." error_notify "ERROR: ${bastille_zfs_zpool} is not a ZFS pool/dataset."
exit 1
fi fi
else else
echo "Bastille ZPOOL is not set." error_notify "Bastille ZPOOL is not set."
exit 1
fi fi
echo "ZFS Enabled for ${PRDNAME} Extension successfully." echo "ZFS Enabled for ${PRDNAME} Extension successfully."
else else
echo "Bastille ZFS option is not set." error_notify "Bastille ZFS option is not set."
exit 1
fi fi
} }

View File

@@ -1 +1 @@
1.0.15 1.0.16