From e92e83d4e2e3465bca9ca6d3cc4f746ef6566476 Mon Sep 17 00:00:00 2001 From: jim-p Date: Mon, 11 Mar 2013 22:16:18 -0400 Subject: [PATCH] Add the ability for full installs to optionally use RAM disks for /tmp and /var, and to allow selecting a size for /tmp and /var RAM disks on both Full installs and NanoBSD. I think I caught most of the edge cases for transitioning into and out of RAM disk mode, and preserving data across reboots as is done on NanoBSD (RRD, DHCP leases, pkg/pbi info). --- etc/inc/rrd.inc | 8 +- etc/inc/services.inc | 22 +++--- etc/rc | 35 +++++---- etc/rc.embedded | 30 +++---- etc/rc.reboot | 8 +- etc/rc.shutdown | 8 +- usr/local/www/diag_nanobsd.php | 44 +---------- usr/local/www/system_advanced_misc.php | 103 +++++++++++++++++++++++++ 8 files changed, 170 insertions(+), 88 deletions(-) diff --git a/etc/inc/rrd.inc b/etc/inc/rrd.inc index 6f443968b4..2566b8d179 100644 --- a/etc/inc/rrd.inc +++ b/etc/inc/rrd.inc @@ -78,6 +78,10 @@ function restore_rrd() { } unlink($xml_file); } + /* If this backup is still there on a full install, but we aren't going to use ram disks, remove the archive since this is a transition. */ + if (($g['platform'] == "pfSense") && !isset($config['system']['use_mfs_tmpvar'])) { + unlink_if_exists("{$g['cf_conf_path']}/rrd.tgz"); + } return true; } return false; @@ -270,9 +274,7 @@ function enable_rrd_graphing() { chown($rrddbpath, "nobody"); if ($g['booting']) { - if ($g['platform'] != "pfSense") { - restore_rrd(); - } + restore_rrd(); } /* db update script */ diff --git a/etc/inc/services.inc b/etc/inc/services.inc index 03325cddbd..81d2ee6994 100644 --- a/etc/inc/services.inc +++ b/etc/inc/services.inc @@ -358,18 +358,20 @@ function services_dhcpdv4_configure() { $is_olsr_enabled = true; if ($g['booting']) { - if ($g['platform'] != "pfSense") { - /* restore the leases, if we have them */ - if (file_exists("{$g['cf_conf_path']}/dhcpleases.tgz")) { - $dhcprestore = ""; - $dhcpreturn = ""; - exec("cd /;LANG=C /usr/bin/tar -xzf {$g['cf_conf_path']}/dhcpleases.tgz 2>&1", $dhcprestore, $dhcpreturn); - $dhcprestore = implode(" ", $dhcprestore); - if($dhcpreturn <> 0) { - log_error(sprintf(gettext('DHCP leases restore failed exited with %1$s, the error is: %2$s%3$s'), $dhcpreturn, $dhcprestore, "\n")); - } + /* restore the leases, if we have them */ + if (file_exists("{$g['cf_conf_path']}/dhcpleases.tgz")) { + $dhcprestore = ""; + $dhcpreturn = ""; + exec("cd /;LANG=C /usr/bin/tar -xzf {$g['cf_conf_path']}/dhcpleases.tgz 2>&1", $dhcprestore, $dhcpreturn); + $dhcprestore = implode(" ", $dhcprestore); + if($dhcpreturn <> 0) { + log_error(sprintf(gettext('DHCP leases restore failed exited with %1$s, the error is: %2$s%3$s'), $dhcpreturn, $dhcprestore, "\n")); } } + /* If this backup is still there on a full install, but we aren't going to use ram disks, remove the archive since this is a transition. */ + if (($g['platform'] == "pfSense") && !isset($config['system']['use_mfs_tmpvar'])) { + unlink_if_exists("{$g['cf_conf_path']}/dhcpleases.tgz"); + } } $syscfg = $config['system']; diff --git a/etc/rc b/etc/rc index 73674eaca2..9b049f162e 100755 --- a/etc/rc +++ b/etc/rc @@ -73,27 +73,22 @@ if [ "$PLATFORM" = "pfSense" ]; then fi fi -if [ "$PLATFORM" = "cdrom" ]; then +if [ "${PLATFORM}" = "cdrom" ]; then /etc/rc.cdrom -fi - -if [ "$PLATFORM" = "embedded" ]; then - export PKG_TMPDIR=/root/ - /etc/rc.embedded -fi - -if [ "$PLATFORM" = "nanobsd" ]; then - export PKG_TMPDIR=/root/ - /etc/rc.embedded -fi - -# Mount /. If it fails run a fsck. -if [ ! "$PLATFORM" = "cdrom" ] ; then +else + # Mount /. If it fails run a fsck. if [ "$PLATFORM" = "nanobsd" ]; then + export PKG_TMPDIR=/root/ /sbin/mount -uw / || (/sbin/fsck -fy; /sbin/mount -uw /) else /sbin/mount -a || (/sbin/fsck -fy; /sbin/mount -a) fi + + USE_MFS_TMPVAR=`/usr/bin/grep -c use_mfs_tmpvar /cf/conf/config.xml` + if [ "${PLATFORM}" = "nanobsd" ] || [ "${PLATFORM}" = "embedded" ] || [ ${USE_MFS_TMPVAR} -gt 0 ]; then + /etc/rc.embedded + fi + # If /conf is a directory, convert it to a symlink to /cf/conf if [ -d "/conf" ]; then # If item is not a symlink then rm and recreate @@ -165,7 +160,7 @@ if [ "$PLATFORM" = "cdrom" ] ; then # do nothing for cdrom platform elif [ "$PLATFORM" = "embedded" ] ; then # do nothing for embedded platform -elif [ "$PLATFORM" = "nanobsd" ] ; then +elif [ "$PLATFORM" = "nanobsd" ] || [ ${USE_MFS_TMPVAR} -gt 0 ]; then # Ensure that old-style PKG packages can be persistent across reboots /bin/mkdir -p /root/var/db/pkg /bin/rm -rf /var/db/pkg @@ -180,6 +175,14 @@ else SWAPDEVICE=`/bin/cat /etc/fstab | /usr/bin/grep swap | /usr/bin/cut -f1` /sbin/swapon -a 2>/dev/null >/dev/null /etc/rc.savecore + + if [ -d /root/var/db/pkg ]; then + # User must have just disabled RAM disks, move these back into place. + /bin/mkdir -p /var/db/pkg + /bin/mv /root/var/db/pkg /var/db/pkg + /bin/mkdir -p /var/db/pbi + /bin/mv /root/var/db/pkg /var/db/pbi + fi fi if [ "$PLATFORM" = "cdrom" ] ; then diff --git a/etc/rc.embedded b/etc/rc.embedded index ada4558696..426495fa73 100755 --- a/etc/rc.embedded +++ b/etc/rc.embedded @@ -4,27 +4,27 @@ # For pfSense # Size of /tmp -tmpsize="40m" +USE_MFS_TMP_SIZE=`/usr/bin/grep use_mfs_tmp_size /cf/conf/config.xml | /usr/bin/cut -f2 -d'>' | /usr/bin/cut -f1 -d'<'` +if [ ${USE_MFS_TMP_SIZE} -gt 0 ]; then + tmpsize="${USE_MFS_TMP_SIZE}m" +else + tmpsize="40m" +fi # Size of /var -varsize="60m" +USE_MFS_VAR_SIZE=`/usr/bin/grep use_mfs_var_size /cf/conf/config.xml | /usr/bin/cut -f2 -d'>' | /usr/bin/cut -f1 -d'<'` +if [ ${USE_MFS_VAR_SIZE} -gt 0 ]; then + varsize="${USE_MFS_VAR_SIZE}m" +else + varsize="60m" +fi # Run some initialization routines [ -f /etc/rc.d/uzip ] && /etc/rc.d/uzip start -echo -n "Setting up embedded specific environment..." -# Initialize MFS for /tmp. Partly taken from /etc/rc.d/var -if (/bin/mkdir -p /tmp/.diskless 2> /dev/null); then - rmdir /tmp/.diskless -else - mdmfs -S -M -s ${tmpsize} md /tmp -fi -# Initialize MFS for /var. Partly taken from /etc/rc.d/var -if (/bin/mkdir -p /var/.diskless 2> /dev/null); then - rmdir /var/.diskless -else - mdmfs -S -M -s ${varsize} md /var -fi +echo -n "Setting up memory disks..." +mdmfs -S -M -s ${tmpsize} md /tmp +mdmfs -S -M -s ${varsize} md /var # Create some needed directories /bin/mkdir -p /var/db diff --git a/etc/rc.reboot b/etc/rc.reboot index 4bb28a196f..afdc93cf00 100755 --- a/etc/rc.reboot +++ b/etc/rc.reboot @@ -14,7 +14,13 @@ sleep 1 PLATFORM=`cat /etc/platform` if [ "$PLATFORM" = "pfSense" ]; then rm -rf /tmp/* -else +fi + +USE_MFS_TMPVAR=`/usr/bin/grep -c use_mfs_tmpvar /cf/conf/config.xml` +DISK_NAME=`/bin/df /var/db/rrd | /usr/bin/tail -1 | /usr/bin/awk '{print $1;}'` +DISK_TYPE=`/usr/bin/basename ${DISK_NAME} | /usr/bin/cut -c1-2` +# If we are not on a full install, or if the full install wants RAM disks, or if the full install _was_ using RAM disks, but isn't for the next boot... +if [ "${PLATFORM}" != "pfSense" ] || [ ${USE_MFS_TMPVAR} -gt 0 ] || [ "${DISK_TYPE}" = "md" ]; then /etc/rc.backup_rrd.sh /etc/rc.backup_dhcpleases.sh fi diff --git a/etc/rc.shutdown b/etc/rc.shutdown index c7e8b25bcd..c63e5e5288 100755 --- a/etc/rc.shutdown +++ b/etc/rc.shutdown @@ -25,7 +25,13 @@ export PATH PLATFORM=`cat /etc/platform` if [ "$PLATFORM" = "pfSense" ]; then find -x /tmp/* -type f -exec rm -f {} \; -else +fi + +USE_MFS_TMPVAR=`/usr/bin/grep -c use_mfs_tmpvar /cf/conf/config.xml` +DISK_NAME=`/bin/df /var/db/rrd | /usr/bin/tail -1 | /usr/bin/awk '{print $1;}'` +DISK_TYPE=`/usr/bin/basename ${DISK_NAME} | /usr/bin/cut -c1-2` +# If we are not on a full install, or if the full install wants RAM disks, or if the full install _was_ using RAM disks, but isn't for the next boot... +if [ "${PLATFORM}" != "pfSense" ] || [ ${USE_MFS_TMPVAR} -gt 0 ] || [ "${DISK_TYPE}" = "md" ]; then /etc/rc.backup_rrd.sh /etc/rc.backup_dhcpleases.sh fi diff --git a/usr/local/www/diag_nanobsd.php b/usr/local/www/diag_nanobsd.php index 80bb87eb7a..df3a7e4990 100755 --- a/usr/local/www/diag_nanobsd.php +++ b/usr/local/www/diag_nanobsd.php @@ -99,15 +99,6 @@ EOF; nanobsd_detect_slice_info(); } -if (isset($_POST['rrdbackup'])) { - $config['system']['rrdbackup'] = $_POST['rrdbackup']; - install_cron_job("/etc/rc.backup_rrd.sh", ($config['system']['rrdbackup'] > 0), $minute="0", "*/{$config['system']['rrdbackup']}"); -} -if (isset($_POST['dhcpbackup'])) { - $config['system']['dhcpbackup'] = $_POST['dhcpbackup']; - install_cron_job("/etc/rc.backup_dhcpleases.sh", ($config['system']['dhcpbackup'] > 0), $minute="0", "*/{$config['system']['dhcpbackup']}"); -} - if ($_POST['changero']) { if (is_writable("/")) { conf_mount_ro(); @@ -240,42 +231,11 @@ if ($savemsg) - + -
- - -
- -
-
+ Advanced, Miscellaneous tab")?>. - - - - - - -
- -
-
- - - -  
-   diff --git a/usr/local/www/system_advanced_misc.php b/usr/local/www/system_advanced_misc.php index 93d8461ec0..cbbd6f60a2 100644 --- a/usr/local/www/system_advanced_misc.php +++ b/usr/local/www/system_advanced_misc.php @@ -68,6 +68,9 @@ $pconfig['crypto_hardware'] = $config['system']['crypto_hardware']; $pconfig['thermal_hardware'] = $config['system']['thermal_hardware']; $pconfig['schedule_states'] = isset($config['system']['schedule_states']); $pconfig['kill_states'] = isset($config['system']['kill_states']); +$pconfig['use_mfs_tmpvar'] = isset($config['system']['use_mfs_tmpvar']); +$pconfig['use_mfs_tmp_size'] = $config['system']['use_mfs_tmp_size']; +$pconfig['use_mfs_var_size'] = $config['system']['use_mfs_var_size']; $pconfig['powerd_ac_mode'] = "hadp"; if (!empty($config['system']['powerd_ac_mode'])) @@ -97,6 +100,12 @@ if ($_POST) { if (!empty($_POST['thermal_hardware']) && !array_key_exists($_POST['thermal_hardware'], $thermal_hardware_modules)) $input_errors[] = gettext("Please select a valid Thermal Hardware Sensor."); + if (!empty($_POST['use_mfs_tmp_size']) && !is_numeric($_POST['use_mfs_tmp_size']) && ($_POST['use_mfs_tmp_size'] <= 40)) + $input_errors[] = gettext("/tmp Size should not be less than 40MB."); + + if (!empty($_POST['use_mfs_var_size']) && !is_numeric($_POST['use_mfs_var_size']) && ($_POST['use_mfs_var_size'] <= 60)) + $input_errors[] = gettext("/var Size should not be less than 60MB."); + if (!$input_errors) { if($_POST['harddiskstandby'] <> "") { @@ -198,6 +207,23 @@ if ($_POST) { else unset($config['system']['kill_states']); + if($_POST['use_mfs_tmpvar'] == "yes") + $config['system']['use_mfs_tmpvar'] = true; + else + unset($config['system']['use_mfs_tmpvar']); + + $config['system']['use_mfs_tmp_size'] = $_POST['use_mfs_tmp_size']; + $config['system']['use_mfs_var_size'] = $_POST['use_mfs_var_size']; + + if (isset($_POST['rrdbackup'])) { + $config['system']['rrdbackup'] = $_POST['rrdbackup']; + install_cron_job("/etc/rc.backup_rrd.sh", ($config['system']['rrdbackup'] > 0), $minute="0", "*/{$config['system']['rrdbackup']}"); + } + if (isset($_POST['dhcpbackup'])) { + $config['system']['dhcpbackup'] = $_POST['dhcpbackup']; + install_cron_job("/etc/rc.backup_dhcpleases.sh", ($config['system']['dhcpbackup'] > 0), $minute="0", "*/{$config['system']['dhcpbackup']}"); + } + write_config(); $retval = 0; @@ -246,6 +272,19 @@ function maxmss_checked(obj) { else jQuery('#maxmss').attr('disabled','true'); } +function tmpvar_checked(obj) { + if (obj.checked) { + jQuery('#use_mfs_tmp_size').attr('disabled',false); + jQuery('#use_mfs_var_size').attr('disabled',false); + jQuery('#rrdbackup').attr('disabled',false); + jQuery('#dhcpbackup').attr('disabled',false); + } else { + jQuery('#use_mfs_tmp_size').attr('disabled','true'); + jQuery('#use_mfs_var_size').attr('disabled','true'); + jQuery('#rrdbackup').attr('disabled','true'); + jQuery('#dhcpbackup').attr('disabled','true'); + } +} //]]>
@@ -509,6 +548,70 @@ function maxmss_checked(obj) { "This option overrides that behavior by not clearing states for existing connections."); ?> + + + + + + + + onclick="tmpvar_checked(this)" /> +
+ + + + + + + + " class="formfld unknown" /> MB +
+ + + + + + + " class="formfld unknown" /> MB +
+ + + + + + + + +
+ +
+
+ + + + + + + +
+ +
+
+ +