Menu

[r3118]: / trunk / etc / rc  Maximize  Restore  History

Download this file

164 lines (135 with data), 4.0 kB

#!/bin/sh
#
# /etc/rc
#part of FreeNAS (http://www.freenas.org)
#Copyright (C) 2005-2008 Olivier Cochard-Labbe <olivier@freenas.org>.
#All rights reserved.
#
#Based on m0n0wall (http://m0n0.ch/wall)
#Copyright (C) 2003-2006 Manuel Kasper <mk@neon1.net>.
#All rights reserved.

stty status '^T'

# Set shell to ignore SIGINT (2), but not children;
# shell catches SIGQUIT (3) and returns to single user.
#
trap : 2
trap "echo 'Boot interrupted'; exit 1" 3

HOME=/
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin

export HOME PATH

# Get operating platform
PLATFORM=`cat /etc/platform`

case ${PLATFORM} in
	i386-full)
		# If running from full, mount the root (/) in read-write.
		mount -u -o rw /;
		;;
	*)
		# If running from liveCD or embedded, mount the root (ramdisk) in read-write.
		mount -u -o rw /dev/md0 /;
		;;
esac

# Create required directories in /var
for dir in /var/run /var/log /var/log/samba /var/etc /var/etc/ssh /var/etc/ssl/private /var/etc/private /var/etc/iscsi /var/db /var/mount /var/empty  /var/cron /var/cron/tabs; do
	[ ! -d "${dir}" ] && mkdir -p ${dir} 
done

# If the file /etc/cfdevice exists (which means a 'full' release), and symlink /var/etc/cfdevice doesn't exist.. create it
if [ -f "/etc/cfdevice" ] && [ ! -h /var/etc/cfdevice ] ; then
	ln -s /etc/cfdevice /var/etc/cfdevice
fi

# If the firmware.lock file exists, delete it (if not, all WebGUI pages will be redirected to upgrade page)
if [ -f "/etc/cfdevice" ] ; then
	rm -f /var/run/firmware.lock
fi

# Make spool directories (for afpd) if they don't exist
if [ ! -d "/var/spool" ]; then
	mkdir -p /var/spool
	mkdir -p /var/spool/lock
fi

# Generate circular logfiles if necessary
if [ ! -e /var/log/system.log ]; then
	clog -i -s 262144 /var/log/system.log
fi
if [ ! -e /var/log/ftp.log ]; then
	clog -i -s 32768 /var/log/ftp.log
fi
if [ ! -e /var/log/rsyncd.log ]; then
	clog -i -s 32768 /var/log/rsyncd.log
fi
if [ ! -e /var/log/sshd.log ]; then
	clog -i -s 32768 /var/log/sshd.log
fi
if [ ! -e /var/log/lastlog ]; then
	clog -i -s 32768 /var/log/lastlog
fi
if [ ! -e /var/log/smartd.log ]; then
	clog -i -s 32768 /var/log/smartd.log
fi
if [ ! -e /var/log/daemon.log ]; then
	clog -i -s 32768 /var/log/daemon.log
fi
chmod 0600 /var/log/*.log

adjkerntz -i

# Create an initial utmp file
cd /var/run && cp /dev/null utmp && chmod 0644 utmp

# Create symlink for lighttpd file upload if it doesn't exist
if [ ! -h "/var/tmp" ]; then
	ln -s /ftmp /var/tmp
fi

# Configure the shared library cache
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib

# Let the other functions know we're booting
touch /var/etc/booting

if [ "$1" = autoboot ]; then
	autoboot=yes
	_boot="faststart"
	rc_fast=yes        # run_rc_command(): do fast booting
else
	autoboot=no
	_boot="start"
fi

. /etc/rc.subr
echo "Loading configuration files."
load_rc_config 'XXX'

skip="-s nostart"
if [ `/sbin/sysctl -n security.jail.jailed` -eq 1 ]; then
	skip="$skip -s nojail"
	if [ "$early_late_divider" = "mountcritlocal" ]; then
		early_late_divider=NETWORKING
	fi
fi

# Do a first pass to get everything up to $early_late_divider so that
# we can do a second pass that includes $local_startup directories
#
files=`rcorder ${skip} /etc/rc.d/* 2>/dev/null`

for _rc_elem in ${files}; do
	run_rc_script ${_rc_elem} ${_boot}

	case "$_rc_elem" in
	*/${early_late_divider})	break ;;
	esac
done

unset files local_rc

# Now that disks are mounted, for each dir in $local_startup
# search for init scripts that use the new rc.d semantics
#
case ${local_startup} in
[Nn][Oo] | '') ;;
*)	find_local_scripts_new ;;
esac

files=`rcorder ${skip} /etc/rc.d/* ${local_rc} 2>/dev/null`
_skip_early=1
for _rc_elem in ${files}; do
	case "$_skip_early" in
	1)	case "$_rc_elem" in
		*/${early_late_divider})	_skip_early=0 ;;
		esac
		continue
		;;
	esac

	run_rc_script ${_rc_elem} ${_boot}
done

# Let the other functions know we've finished booting
rm -f /var/etc/booting > /dev/null 2>&1

echo ''
date
exit 0
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.