diff options
Diffstat (limited to 'src/etc/pfSense-rc')
-rwxr-xr-x | src/etc/pfSense-rc | 310 |
1 files changed, 102 insertions, 208 deletions
diff --git a/src/etc/pfSense-rc b/src/etc/pfSense-rc index c01dc50..e46ed23 100755 --- a/src/etc/pfSense-rc +++ b/src/etc/pfSense-rc @@ -3,7 +3,7 @@ # pfSense-rc # # part of pfSense (https://www.pfsense.org) -# Copyright (c) 2004-2016 Electric Sheep Fencing, LLC +# Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate) # All rights reserved. # # originally based on m0n0wall (http://neon1.net/m0n0wall) @@ -32,9 +32,6 @@ HOME=/ PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin export HOME PATH -# Set our operating platform -PLATFORM=`/bin/cat /etc/platform` - # Set our current version version=`/bin/cat /etc/version` @@ -56,100 +53,93 @@ product=$(/usr/local/bin/php -n /usr/local/sbin/read_global_var product_name pfS # Setup dumpdev/ddb/savecore" echo "Configuring crash dumps..." -if [ "$PLATFORM" = "${product}" ]; then - /etc/rc.dumpon -fi +/etc/rc.dumpon -# Setup ddb on all platforms. On full install it will save the dump, on NanoBSD it will print to console and auto-reboot. +# Setup ddb on all platforms. if [ ! -z "`sysctl -Nq debug.ddb.scripting.scripts`" ]; then - /sbin/ddb /etc/ddb.conf + /sbin/ddb /etc/${product}-ddb.conf fi -if [ -e /root/force_fsck ]; then - echo "Forcing filesystem(s) check..." - /sbin/fsck -y -F -t ufs +fsck_forced_iterations=`/bin/kenv -q pfsense.fsck.force` +if [ ! -z "${fsck_forced_iterations}" ]; then + echo "Forcing filesystem check (${fsck_forced_iterations} times)..." + while [ ${fsck_forced_iterations} -gt 0 ]; do + /sbin/fsck -y -F -t ufs + fsck_forced_iterations=$((fsck_forced_iterations - 1)) + done fi -if [ "${PLATFORM}" != "cdrom" ]; then - FSCK_ACTION_NEEDED=0 - /sbin/fsck -p -F - case $? in - 0) - echo "Filesystems are clean, continuing..." - echo "Mounting filesystems..." - ;; - 8) - echo "Preen mode recommended running a check that will be performed now." - FSCK_ACTION_NEEDED=1 - ;; - *) - echo "Stopping boot is recommended because filesystem manual action is needed, nevertheless automated repair of the filesystem will be attempted." - FSCK_ACTION_NEEDED=1 - ;; - esac - - if [ ${FSCK_ACTION_NEEDED} = 1 ]; then - echo "WARNING: Trying to recover filesystem from inconsistency..." - /sbin/fsck -yF - fi - +if [ -e /root/force_growfs ]; then + /etc/rc.d/growfs onestart +fi + +FSCK_ACTION_NEEDED=0 +/sbin/fsck -p -F +case $? in +0) + echo "Filesystems are clean, continuing..." + echo "Mounting filesystems..." + ;; +8) + echo "Preen mode recommended running a check that will be performed now." + FSCK_ACTION_NEEDED=1 + ;; +*) + echo "Stopping boot is recommended because filesystem manual action is needed, nevertheless automated repair of the filesystem will be attempted." + FSCK_ACTION_NEEDED=1 + ;; +esac + +if [ ${FSCK_ACTION_NEEDED} = 1 ]; then + echo "WARNING: Trying to recover filesystem from inconsistency..." + /sbin/fsck -yF +fi + +/sbin/mount -a 2>/dev/null +mount_rc=$? +attempts=0 +while [ ${mount_rc} -ne 0 -a ${attempts} -lt 3 ]; do + /sbin/fsck -yF /sbin/mount -a 2>/dev/null mount_rc=$? - attempts=0 - while [ ${mount_rc} -ne 0 -a ${attempts} -lt 3 ]; do - /sbin/fsck -yF - /sbin/mount -a 2>/dev/null - mount_rc=$? - attempts=$((attempts+1)) - done - - if [ "${PLATFORM}" = "nanobsd" ]; then - # XXX This script does need all filesystems rw!!!! - # Put this workaround for now until better ways are found. - /sbin/mount -u -w -o sync,noatime / - /sbin/mount -u -w -o sync,noatime /cf - fi + attempts=$((attempts+1)) +done - # 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 - CONFPOINTSTO=`readlink /conf` - if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then - /bin/rm -rf /conf - /bin/ln -s /cf/conf /conf - 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 + CONFPOINTSTO=`readlink /conf` + if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then + /bin/rm -rf /conf + /bin/ln -s /cf/conf /conf fi +fi - USE_MFS_TMPVAR=$(/usr/local/sbin/read_xml_tag.sh boolean system/use_mfs_tmpvar) - unset MOVE_PKG_DATA - if [ "$PLATFORM" = "${product}" ]; then - # If use MFS var is disabled, move files back to place - if [ "${USE_MFS_TMPVAR}" != "true" -a -f /root/var/db/pkg/local.sqlite ]; then - MOVE_PKG_DATA=1 - rm -rf /var/db/pkg 2>/dev/null - rm -rf /var/cache/pkg 2>/dev/null - mv /root/var/db/pkg /var/db - mv /root/var/cache/pkg /var/cache - # If use MFS var is enabled, move files to a safe place - elif [ "${USE_MFS_TMPVAR}" = "true" -a -f /var/db/pkg/local.sqlite ]; then - MOVE_PKG_DATA=1 - /bin/mkdir -p /root/var/db /root/var/cache - mv /var/db/pkg /root/var/db - mv /var/cache/pkg /root/var/cache - fi - elif [ "${PLATFORM}" = "nanobsd" ]; then - MOVE_PKG_DATA=1 - fi +USE_MFS_TMPVAR=$(/usr/local/sbin/read_xml_tag.sh boolean system/use_mfs_tmpvar) +unset MOVE_PKG_DATA +# If use MFS var is disabled, move files back to place +if [ "${USE_MFS_TMPVAR}" != "true" -a -f /root/var/db/pkg/local.sqlite ]; then + MOVE_PKG_DATA=1 + rm -rf /var/db/pkg 2>/dev/null + rm -rf /var/cache/pkg 2>/dev/null + mv /root/var/db/pkg /var/db + mv /root/var/cache/pkg /var/cache +# If use MFS var is enabled, move files to a safe place +elif [ "${USE_MFS_TMPVAR}" = "true" -a -f /var/db/pkg/local.sqlite ]; then + MOVE_PKG_DATA=1 + /bin/mkdir -p /root/var/db /root/var/cache + mv /var/db/pkg /root/var/db + mv /var/cache/pkg /root/var/cache +fi - if [ "${PLATFORM}" = "nanobsd" ] || [ "${USE_MFS_TMPVAR}" = "true" ]; then - /etc/rc.embedded - fi +if [ "${USE_MFS_TMPVAR}" = "true" ]; then + /etc/rc.embedded +fi - if [ -n "${MOVE_PKG_DATA}" -o "${USE_MFS_TMPVAR}" = "true" ]; then - /bin/mkdir -p /var/db /var/cache - ln -sf ../../root/var/db/pkg /var/db/pkg - ln -sf ../../root/var/cache/pkg /var/cache/pkg - fi +if [ -n "${MOVE_PKG_DATA}" -o "${USE_MFS_TMPVAR}" = "true" ]; then + /bin/mkdir -p /var/db /var/cache + ln -sf ../../root/var/db/pkg /var/db/pkg + ln -sf ../../root/var/cache/pkg /var/cache/pkg fi # Make sure /home exists @@ -160,27 +150,18 @@ fi /bin/rm -f /root/TRIM_set /bin/rm -f /root/TRIM_unset -if [ "${PLATFORM}" = "nanobsd" ]; then - /sbin/kldstat -qm zfs - if [ $? -eq 0 ]; then +# Handle ZFS read-only case +/sbin/kldstat -qm zfs +if [ $? -eq 0 ]; then + ZFSFSAVAILABLE=$(/sbin/zfs mount 2>/dev/null | wc -l) + if [ $ZFSFSAVAILABLE -eq 0 ]; then /sbin/kldunload zfs - fi -elif [ "$PLATFORM" = "${product}" ]; then - # Handle ZFS read-only case - /sbin/kldstat -qm zfs - if [ $? -eq 0 ]; then - ZFSFSAVAILABLE=$(/sbin/zfs mount 2>/dev/null | wc -l) - if [ $ZFSFSAVAILABLE -eq 0 ]; then - /sbin/kldunload zfs - elif [ -f /usr/bin/grep ]; then - ZFSROOT=`/sbin/zfs mount | /usr/bin/grep ' /$' | /usr/bin/cut -d ' ' -f 1` - if [ "$ZFSROOT" != "" ]; then - /sbin/zfs set readonly=off $ZFSROOT - fi + elif [ -f /usr/bin/grep ]; then + ZFSROOT=`/sbin/zfs mount | /usr/bin/grep ' /$' | /usr/bin/cut -d ' ' -f 1` + if [ "$ZFSROOT" != "" ]; then + /sbin/zfs set readonly=off $ZFSROOT fi fi -elif [ "${PLATFORM}" = "cdrom" ]; then - /etc/rc.cdrom fi # Disable APM on ATA drives. Leaving this on will kill drives long-term, especially laptop drives, by generating excessive Load Cycles. @@ -198,57 +179,26 @@ fi # Use php -n here because we are not ready to load extensions yet varrunpath=$(/usr/local/bin/php -n /usr/local/sbin/read_global_var varrun_path "/var/run") -if [ "$PLATFORM" = "${product}" ] && [ "${USE_MFS_TMPVAR}" != "true" ]; then +if [ "${USE_MFS_TMPVAR}" != "true" ]; then /sbin/mdmfs -S -M -s 4m md $varrunpath fi -# Use php -n here because we are not ready to load extensions yet -hideplatform=$(/usr/local/bin/php -n /usr/local/sbin/read_global_var hideplatform) -if [ "$hideplatform" = "true" ]; then - platformbanner="" # hide the platform -else - platformbanner=" on the '${PLATFORM}' platform" -fi - echo cat /usr/local/share/pfSense/ascii-art/pfsense-logo-small.txt echo echo -echo "Welcome to ${product} ${version}${version_patch}${platformbanner}..." +echo "Welcome to ${product} ${version}${version_patch}..." echo /sbin/conscontrol mute off >/dev/null -if [ "$PLATFORM" = "${product}" ]; then - SWAPDEVICE=`/bin/cat /etc/fstab | /usr/bin/grep swap | /usr/bin/cut -f1` - /sbin/swapon -a 2>/dev/null >/dev/null - /etc/rc.savecore -fi - -if [ "$PLATFORM" = "cdrom" ] ; then - echo -n "Mounting unionfs directories..." - /bin/mkdir /tmp/unionfs - /bin/mkdir /tmp/unionfs/usr - /bin/mkdir /tmp/unionfs/root - /bin/mkdir /tmp/unionfs/sbin - /bin/mkdir /tmp/unionfs/bin - /bin/mkdir /tmp/unionfs/boot - /bin/mkdir /tmp/unionfs/confdefault - /sbin/mount_unionfs /tmp/unionfs/usr /usr/ - /sbin/mount_unionfs /tmp/unionfs/root /root/ - /sbin/mount_unionfs /tmp/unionfs/bin /bin/ - /sbin/mount_unionfs /tmp/unionfs/sbin /sbin/ - /sbin/mount_unionfs /tmp/unionfs/boot /boot/ - /sbin/mount_unionfs /tmp/unionfs/confdefault /conf.default/ - echo "done." -fi +SWAPDEVICE=`/bin/cat /etc/fstab | /usr/bin/grep swap | /usr/bin/cut -f1` +/sbin/swapon -a 2>/dev/null >/dev/null +/etc/rc.savecore # make some directories in /var -/bin/mkdir -p $varrunpath /var/log /var/etc /var/db/entropy /var/db/rrd /var/at/jobs/ /var/empty 2>/dev/null +/bin/mkdir -p $varrunpath /var/log /var/etc /var/db/entropy /var/db/rrd /var/at/jobs/ /var/empty /var/log/nginx 2>/dev/null /bin/rm -rf $varrunpath/* -if [ "$PLATFORM" != "${product}" ]; then - /bin/rm /var/log/* 2>/dev/null -fi # Cleanup configuration files from previous instance /bin/rm -rf /var/etc/* @@ -269,58 +219,19 @@ if [ -L /usr/local/etc/strongswan.conf ]; then rm -f /usr/local/etc/strongswan.conf fi -echo -n "Creating symlinks..." -# Repair symlinks if they are broken -if [ -f /etc/newsyslog.conf ]; then - /bin/rm -f /etc/newsyslog.conf -fi -if [ ! -L /etc/syslog.conf ]; then - /bin/rm -rf /etc/syslog.conf - if [ ! -f /var/etc/syslog.conf ]; then - touch /var/etc/syslog.conf +# Remove deprecated symlinks - #5538 +for f in /etc/hosts \ + /etc/resolv.conf \ + /etc/resolvconf.conf \ + /etc/syslog.conf; do + if [ -L "${f}" ]; then + rm -f ${f} fi - /bin/ln -s /var/etc/syslog.conf /etc/syslog.conf -fi - -# Repair symlinks if they are broken -if [ ! -L /etc/hosts ]; then - /bin/rm -rf /etc/hosts - /bin/ln -s /var/etc/hosts /etc/hosts -fi - -if [ ! -L /etc/resolv.conf ]; then - /bin/rm -rf /etc/resolv.conf - /bin/ln -s /var/etc/resolv.conf /etc/resolv.conf -fi - -if [ ! -L /etc/resolvconf.conf ]; then - /bin/rm -rf /etc/resolvconf.conf - /bin/ln -s /var/etc/resolvconf.conf /etc/resolvconf.conf -fi - -# Setup compatibility link for packages that -# have trouble overriding the PREFIX configure -# argument since we build our packages in a -# separated PREFIX area -# Only create if symlink does not exist. -if [ ! -h /tmp/tmp ]; then - /bin/ln -hfs / /tmp/tmp -fi +done # Make sure our /tmp is 777 + Sticky -if [ ! "$PLATFORM" = "cdrom" ] ; then - /bin/rm -rf /tmp/* -fi /bin/chmod 1777 /tmp -if [ ! "$PLATFORM" = "cdrom" ] ; then - # Malloc debugging check - if [ -L /etc/malloc.conf ]; then - #ln -s aj /etc/malloc.conf - /bin/rm /etc/malloc.conf - fi -fi - if [ ! -L /etc/dhclient.conf ]; then /bin/rm -rf /etc/dhclient.conf fi @@ -332,12 +243,9 @@ fi set -T trap "echo 'Reboot interrupted'; exit 1" 3 -# Remove old nameserver resolution files -/bin/rm -f /var/etc/nameserver* - echo -n "." DISABLESYSLOGCLOG=$(/usr/local/sbin/read_xml_tag.sh boolean system/disablesyslogclog) -LOG_FILES="system filter dhcpd vpn pptps poes l2tps openvpn portalauth ipsec ppp relayd wireless nginx ntpd gateways resolver routing" +LOG_FILES="system filter dhcpd vpn poes l2tps openvpn portalauth ipsec ppp relayd wireless nginx ntpd gateways resolver routing" DEFAULT_LOG_FILE_SIZE=$(/usr/local/sbin/read_xml_tag.sh string syslog/logfilesize) DEFAULT_LOG_FILE_SIZE=${DEFAULT_LOG_FILE_SIZE:-"511488"} @@ -404,15 +312,8 @@ ln -sf /etc/ssl/openssl.cnf \ /etc/rc.php_ini_setup 2>/tmp/php_errors.txt /usr/local/sbin/php-fpm -c /usr/local/etc/php.ini -y /usr/local/lib/php-fpm.conf -RD 2>&1 >/dev/null -# Launch external configuration loader for supported platforms -if [ "$PLATFORM" = "nanobsd" ]; then - /usr/local/sbin/fcgicli -f /etc/ecl.php -fi - -# Launch external configuration loader for supported platforms -if [ "$PLATFORM" = "${product}" ]; then - /usr/local/sbin/fcgicli -f /etc/ecl.php -fi +# Launch external configuration loader +/usr/local/sbin/fcgicli -f /etc/ecl.php if [ -f /etc/rc.custom_boot_early ]; then /bin/echo -n "Launching /etc/rc.custom_boot_early..."; @@ -428,13 +329,6 @@ echo -n "Launching the init system..." /bin/rm -f /cf/conf/backup/backup.cache /usr/bin/touch $varrunpath/booting -if [ "${PLATFORM}" = "nanobsd" ]; then - # XXX This script does need all filesystems rw!!!! - # Put this workaround for now until better ways are found. - /sbin/mount -u -f -r -o sync,noatime / - /sbin/mount -u -f -r -o sync,noatime /cf -fi - # Copy custom logo over if it's present if [ -d /usr/local/share/${product}/custom_logos ]; then cp -f /usr/local/share/${product}/custom_logos/*png \ @@ -483,7 +377,7 @@ fi # Log product version to syslog BUILDTIME=`cat /etc/version.buildtime` ARCH=`uname -m` -echo "$product ($PLATFORM) ${version}${version_patch} $ARCH $BUILDTIME" +echo "$product ${version}${version_patch} $ARCH $BUILDTIME" echo "Bootup complete" |