Add ability to enable ZFS easily

This commit is contained in:
Jose
2019-11-22 06:29:34 -04:00
parent 25f55af3ec
commit 13f1739f96
6 changed files with 119 additions and 5 deletions
+1
View File
@@ -3,6 +3,7 @@
====================== ======================
Version Description Version Description
1.0.13......Add ability to enable ZFS easily.
1.0.12......Change tar archive extension. 1.0.12......Change tar archive extension.
1.0.11......Backup and Restore implementation changes. 1.0.11......Backup and Restore implementation changes.
1.0.10......Cosmetic changes and version number adjust. 1.0.10......Cosmetic changes and version number adjust.
+93 -1
View File
@@ -564,6 +564,76 @@ jail_restore()
fi fi
} }
zfs_activate()
{
# Check if ZFS is already configured.
BASTILLE_DIR=$(echo ${CWDIR} | grep -o '[^/]*$')
if zfs list "${bastille_zfs_zpool}/${BASTILLE_DIR}" > /dev/null 2>&1; then
echo "Bastille ZFS is already configured."
exit 0
else
BASTILLE_DIRS="cache jails logs releases templates"
for dir in ${BASTILLE_DIRS}; do
if [ -d "${CWDIR}/${dir}" ]; then
# Stop if any of the listed dirs already exist.
echo "Bastille has been bootstrapped already, aborting."
exit 0
fi
done
fi
echo "Enabling ZFS on ${PRDNAME} Extension..."
# Confirm before conversion.
while :
do
read -p "Do you really wish to enable ZFS for ${PRDNAME} Extension? [y/N]:" yn
case ${yn} in
[Yy]) break;;
[Nn]) exit 0;;
esac
done
echo "Proceeding..."
if [ "${bastille_zfs_enable}" = "YES" ]; then
if [ ! -z "${bastille_zfs_zpool}" ]; then
if zfs list "${bastille_zfs_zpool}" > /dev/null 2>&1; then
if ! zfs list "${bastille_zfs_zpool}/${BASTILLE_DIR}" > /dev/null 2>&1; then
echo "Renaming existing '${BASTILLE_DIR}' directory"
mv ${CWDIR} ${CWDIR}.old
echo "Creating a new ZFS dataset for '${BASTILLE_DIR}'"
zfs create ${bastille_zfs_options} ${bastille_zfs_zpool}/${bastille_zfs_prefix}
if [ $? -ne 0 ]; then
echo "Failed to enable ZFS, reverting changes."
mv ${CWDIR}.old ${CWDIR}
zfs destroy ${bastille_zfs_zpool}/${bastille_zfs_prefix}
else
echo "Synchronizing '${BASTILLE_DIR}' data on new dataset"
rsync -a ${CWDIR}.old/ ${CWDIR}/
fi
else
if zfs list "${bastille_zfs_zpool}/${BASTILLE_DIR}" > /dev/null 2>&1; then
echo "Bastille ZFS is already configured."
exit 0
else
echo -e "ERROR: ${bastille_zfs_zpool}/${BASTILLE_DIR} is not a ZFS pool/dataset."
exit 1
fi
fi
else
echo -e "ERROR: ${bastille_zfs_zpool} is not a ZFS pool/dataset."
exit 1
fi
else
echo "Bastille ZPOOL is not set."
exit 1
fi
echo "ZFS Enabled for ${PRDNAME} Extension successfully."
else
echo "Bastille ZFS option is not set."
exit 1
fi
}
pkg_upgrade() pkg_upgrade()
{ {
# Re-fetch bastille package and extract. # Re-fetch bastille package and extract.
@@ -741,6 +811,26 @@ rc_params()
if ! sysrc -qn bastille_enable >/dev/null 2>&1; then if ! sysrc -qn bastille_enable >/dev/null 2>&1; then
sysrc bastille_enable="NO" >/dev/null 2>&1 sysrc bastille_enable="NO" >/dev/null 2>&1
fi fi
# Check if sane ZFS is enabled in this setup.
if [ "${bastille_zfs_enable}" = "YES" ]; then
if [ ! -z "${bastille_zfs_zpool}" ]; then
if zfs list "${bastille_zfs_zpool}" > /dev/null 2>&1; then
BASTILLE_DIR=$(echo ${CWDIR} | grep -o '[^/]*$')
if zfs list "${bastille_zfs_zpool}/${BASTILLE_DIR}" > /dev/null 2>&1; then
sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="YES" >/dev/null 2>&1
else
sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="AVA" >/dev/null 2>&1
fi
else
sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="ERR" >/dev/null 2>&1
fi
else
sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="NO" >/dev/null 2>&1
fi
else
sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="NO" >/dev/null 2>&1
fi
} }
bastille_start() bastille_start()
@@ -804,7 +894,7 @@ bastille_init()
# Run-time configuration. # Run-time configuration.
runtime_config runtime_config
while getopts ":ospruxUvgtBRh" option; do while getopts ":ospruxUvgtBRZh" option; do
case ${option} in case ${option} in
[h]) echo "Usage: ${SCRIPTNAME} -[option] | [container]"; [h]) echo "Usage: ${SCRIPTNAME} -[option] | [container]";
echo "Options:" echo "Options:"
@@ -817,6 +907,7 @@ while getopts ":ospruxUvgtBRh" option; do
echo " -t Disable the addon GUI." echo " -t Disable the addon GUI."
echo " -B Backup a ${PRDNAME} container." echo " -B Backup a ${PRDNAME} container."
echo " -R Restore a ${PRDNAME} container." echo " -R Restore a ${PRDNAME} container."
echo " -Z Activate ZFS for ${PRDNAME} Extension."
echo " -x Reset ${PRDNAME}/Extension config." echo " -x Reset ${PRDNAME}/Extension config."
echo " -U Uninstall ${PRDNAME} (Extension files only)." echo " -U Uninstall ${PRDNAME} (Extension files only)."
echo " -h Display this help message."; exit 0;; echo " -h Display this help message."; exit 0;;
@@ -832,6 +923,7 @@ while getopts ":ospruxUvgtBRh" option; do
[t]) gui_disable; exit 0 ;; # For disable the addon gui. [t]) gui_disable; exit 0 ;; # For disable the addon gui.
[B]) jail_backup;; [B]) jail_backup;;
[R]) jail_restore;; [R]) jail_restore;;
[Z]) zfs_activate;;
[?]) echo "Invalid option, -h for usage."; exit 1;; [?]) echo "Invalid option, -h for usage."; exit 1;;
esac esac
done done
+15
View File
@@ -58,6 +58,7 @@ $jail_dir = "{$rootfolder}/jails";
$image_dir = "ext/bastille/images"; $image_dir = "ext/bastille/images";
$thick_jail = exec("/usr/local/bin/bastille create | grep -wo '\[option\]'"); $thick_jail = exec("/usr/local/bin/bastille create | grep -wo '\[option\]'");
$reldir = "{$rootfolder}/releases"; $reldir = "{$rootfolder}/releases";
$zfs_support = exec("/bin/cat {$configfile} | /usr/bin/grep 'ZFS_SUPPORT=' | /usr/bin/cut -d'\"' -f2");
// Ensure the root directory is configured. // Ensure the root directory is configured.
if ($rootfolder == "") if ($rootfolder == "")
@@ -77,6 +78,20 @@ function is_dir_empty($reldir) {
return (count(scandir($reldir)) == 2); return (count(scandir($reldir)) == 2);
} }
// Check for sane ZFS settings.
function get_state_zfs() {
global $zfs_support;
if ($zfs_support == "YES"):
return $getinfo['zfs'] = gettext("Enabled");
elseif ($zfs_support == "AVA"):
return $getinfo['zfs'] = gettext("Available but not enabled");
elseif ($zfs_support == "ERR"):
return $getinfo['zfs'] = gettext("Invalid ZFS configuration");
else:
return $getinfo['zfs'] = gettext("Disabled");
endif;
}
// Get all base releases list. // Get all base releases list.
function get_all_release_list() { function get_all_release_list() {
global $rootfolder; global $rootfolder;
+5 -3
View File
@@ -118,15 +118,17 @@ else {
if ($_POST) { if ($_POST) {
unset($input_errors); unset($input_errors);
if (isset($_POST['saveParam']) && $_POST['saveParam']) { // saveParam s/n/v: [[outputs.influxdb]]#urls outputsinfluxdburls ["http://192.168.1.XYZ:8086"] if (isset($_POST['saveParam']) && $_POST['saveParam']) { // saveParam s/n/v
$buttonTag = explode("#", $_POST['saveParam']); // buttonTag[0] = section, buttonTag[1] = paramName $buttonTag = explode("#", $_POST['saveParam']); // buttonTag[0] = section, buttonTag[1] = paramName
$hashTag = str_replace(["[", "]", ".", "#"], "", $buttonTag[0]); // create destination to jump to after post $hashTag = str_replace(["[", "]", ".", "#"], "", $buttonTag[0]); // create destination to jump to after post
$nameTag = str_replace(["[", "]", ".", "#"], "", $_POST['saveParam']); // nameTag = <input title='$nameTag + addParam' ... /> $nameTag = str_replace(["[", "]", ".", "#"], "", $_POST['saveParam']); // nameTag = <input title='$nameTag + addParam' ... />
$configArray[$buttonTag[0]][$buttonTag[1]] = $_POST[$nameTag]; // save param to section $configArray[$buttonTag[0]][$buttonTag[1]] = $_POST[$nameTag]; // save param to section
# $savemsg .= "saveParam s/n/v: ".$_POST['saveParam']." ".$nameTag." ".$_POST[$nameTag]; #$savemsg .= "saveParam s/n/v: ".$_POST['saveParam']." ".$nameTag." ".$_POST[$nameTag];
} }
if (empty($input_errors) && !isset($_POST['loadConfig'])) saveConfigFile($configFile, $configArray, $hashTag); if (empty($input_errors) && !isset($_POST['loadConfig'])) saveConfigFile($configFile, $configArray, $hashTag);
# Run bastille-init to update config.
exec("bastille-init");
} }
bindtextdomain("xigmanas", $textdomain); bindtextdomain("xigmanas", $textdomain);
+4
View File
@@ -270,6 +270,10 @@ $(document).ready(function(){
<tr> <tr>
<td class="vncellt"><?=gtext("Extension version");?></td> <td class="vncellt"><?=gtext("Extension version");?></td>
<td class="vtable"><span name="getinfo_ext" id="getinfo_ext"><?=get_version_ext()?></span></td> <td class="vtable"><span name="getinfo_ext" id="getinfo_ext"><?=get_version_ext()?></span></td>
</tr>
<tr>
<td class="vncellt"><?=gtext("ZFS support");?></td>
<td class="vtable"><span name="getinfo_zfs" id="getinfo_zfs"><?=get_state_zfs()?></span></td>
</tr> </tr>
<?php html_filechooser("backup_path", gtext("Backup directory"), $backup_path, gtext("Directory to store containers backup archives, use as file chooser for restoring from file."), $backup_path, true, 60);?> <?php html_filechooser("backup_path", gtext("Backup directory"), $backup_path, gtext("Directory to store containers backup archives, use as file chooser for restoring from file."), $backup_path, true, 60);?>
</table> </table>
+1 -1
View File
@@ -1 +1 @@
1.0.12 1.0.13