Project

General

Profile

Download (11.7 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/bin/sh
2

    
3
# $Id$
4

    
5
# /etc/rc - master bootup script, invokes php setup
6
# part of pfSense by Scott Ullrich
7
# Copyright (C) 2004-2010 Scott Ullrich, All rights reserved.
8
# originally based on m0n0wall (http://neon1.net/m0n0wall)
9
# Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
# All rights reserved.
11

    
12
#/bin/stty status '^T'
13
#/bin/stty susp '^-' intr '^-' quit '^-'
14

    
15
#trap : 2
16
#trap : 3
17

    
18
HOME=/
19
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
20
export HOME PATH
21

    
22
# Set our operating platform
23
PLATFORM=`/bin/cat /etc/platform`
24

    
25
# Set our current version
26
version=`/bin/cat /etc/version`
27

    
28
# Setup dumpdev/ddb/savecore"
29
echo "Configuring crash dumps..."
30
if [ "$PLATFORM" = "pfSense" ]; then
31
	/etc/rc.dumpon
32
fi
33

    
34
# Setup ddb on all platforms. On full install it will save the dump, on NanoBSD it will print to console and auto-reboot.
35
if [ ! -z "`sysctl -Nq debug.ddb.scripting.scripts`" ]; then
36
	/sbin/ddb /etc/ddb.conf
37
fi
38

    
39
if [ -e /root/force_fsck ]; then
40
	echo "Forcing filesystem(s) check..."
41
	/sbin/fsck -y -F -t ufs
42
fi
43

    
44
if [ ! "${PLATFORM}" = "cdrom" ]; then
45
	/sbin/fsck -p -F
46
	FSCK_ACTION_NEEDED=0
47
	case $? in
48
	0)
49
		echo "Filesystems are clean, continuing..."
50
		echo "Mounting filesystems..."
51
		;;
52
	8)
53
		echo "Preen mode recommended running a check that will be performed now."
54
		FSCK_ACTION_NEEDED=1
55
		;;
56
	*)
57
		echo "Stopping boot is recommended due to  filesystem manual action needed, nevertheless it will be tried to repair the filesystem."
58
		FSCK_ACTION_NEEDED=1
59
		;;
60
	esac
61

    
62
	if [ ${FSCK_ACTION_NEEDED} = 1 ]; then
63
		echo "WARNING: Trying to recover filesystem from inconsistency..."
64
		/sbin/fsck -yF
65
	fi
66

    
67
	/sbin/mount -a 2>/dev/null
68
	mount_rc=$?
69
	attempts=0
70
	while [ ${mount_rc} -ne 0 -a ${attempts} -lt 3 ]; do
71
		/sbin/fsck -yF
72
		/sbin/mount -a 2>/dev/null
73
		mount_rc=$?
74
		attempts=$((attempts+1))
75
	done
76

    
77
	if [ "${PLATFORM}" = "nanobsd" ]; then
78
		# XXX This script does need all filesystems rw!!!!
79
		# Put this workaround for now until better ways are found.
80
		/sbin/mount -u -w -o sync,noatime /
81
		/sbin/mount -u -w -o sync,noatime /cf
82
	fi
83

    
84
	# If /conf is a directory, convert it to a symlink to /cf/conf
85
	if [ -d "/conf" ]; then
86
		# If item is not a symlink then rm and recreate
87
		CONFPOINTSTO=`readlink /conf`
88
		if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then
89
			/bin/rm -rf /conf
90
			/bin/ln -s /cf/conf /conf
91
		fi
92
	fi
93

    
94
	USE_MFS_TMPVAR=`/usr/bin/grep -c use_mfs_tmpvar /cf/conf/config.xml`
95
	if [ "${PLATFORM}" = "nanobsd" ] || [ ${USE_MFS_TMPVAR} -gt 0 ]; then
96
		/etc/rc.embedded
97
	fi
98
fi
99

    
100
/bin/rm -f /root/force_fsck
101
/bin/rm -f /root/TRIM_set
102
/bin/rm -f /root/TRIM_unset
103

    
104
if [ "${PLATFORM}" = "nanobsd" ]; then
105
	/sbin/kldstat -qm zfs
106
	if [ $? -eq 0 ]; then
107
		/sbin/kldunload zfs
108
	fi
109
elif [ "$PLATFORM" = "pfSense" ]; then
110
	# Handle ZFS read-only case
111
	/sbin/kldstat -qm zfs
112
	if [ $? -eq 0 ]; then
113
		ZFSFSAVAILABLE=$(/sbin/zfs mount 2>/dev/null | wc -l)
114
		if [ $ZFSFSAVAILABLE -eq 0 ]; then
115
			/sbin/kldunload zfs
116
		elif [ -f /usr/bin/grep ]; then
117
			ZFSROOT=`/sbin/zfs mount | /usr/bin/grep ' /$' | /usr/bin/cut -d ' ' -f 1`
118
			if [ "$ZFSROOT" != "" ]; then
119
				/sbin/zfs set readonly=off $ZFSROOT
120
			fi
121
		fi
122
	fi
123
elif [ "${PLATFORM}" = "cdrom" ]; then
124
	/etc/rc.cdrom
125
fi
126

    
127
# Disable APM on ATA drives. Leaving this on will kill drives long-term, especially laptop drives, by generating excessive Load Cycles.
128
if [ -f /etc/rc.disable_hdd_apm ]; then
129
	/etc/rc.disable_hdd_apm
130
fi
131

    
132
# Eject CD devices on 3G modems
133
MANUFACTURER="huawei|zte"
134
CDDEVICE=`dmesg |egrep -ie "($MANUFACTURER)" | awk -F: '/cd/ {print $1}'`
135
if [ "$CDDEVICE" != "" ]; then
136
	cdcontrol -f /dev/"$CDDEVICE" eject
137
fi
138

    
139
product=`/usr/bin/grep product_name /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
140
hideplatform=`/usr/bin/grep hideplatform /etc/inc/globals.inc | /usr/bin/wc -l`
141
varrunpath=`/usr/bin/grep varrun_path /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
142

    
143
if [ "$PLATFORM" = "pfSense" ] && [ ${USE_MFS_TMPVAR} -eq 0 ]; then
144
	/sbin/mdmfs -S -M -s 4m md $varrunpath
145
fi
146

    
147
if [ "$hideplatform" -gt "0" ]; then
148
	platformbanner="" # hide the platform
149
else
150
	platformbanner=" on the '${PLATFORM}' platform"
151
fi
152

    
153
echo
154
cat /etc/ascii-art/pfsense-logo-small.txt
155
echo
156
echo
157
echo "Welcome to ${product} ${version} ${platformbanner} ..."
158
echo
159

    
160
/sbin/conscontrol mute off >/dev/null
161

    
162
if [ "$PLATFORM" = "cdrom" ] ; then
163
	# do nothing for cdrom platform
164
elif [ "$PLATFORM" = "nanobsd" ] || [ ${USE_MFS_TMPVAR} -gt 0 ]; then
165
	# Ensure that old-style PKG packages can be persistent across reboots
166
	/bin/mkdir -p /root/var/db/pkg
167
	/bin/rm -rf /var/db/pkg
168
	/bin/ln -s /root/var/db/pkg/ /var/db/pkg
169
else
170
	SWAPDEVICE=`/bin/cat /etc/fstab | /usr/bin/grep swap | /usr/bin/cut -f1`
171
	/sbin/swapon -a 2>/dev/null >/dev/null
172
	/etc/rc.savecore
173

    
174
	if [ -d /root/var/db/pkg ]; then
175
		# User must have just disabled RAM disks, move these back into place.
176
		/bin/mkdir -p /var/db/pkg
177
		/bin/mv /root/var/db/pkg /var/db/pkg
178
	fi
179
fi
180

    
181
if [ "$PLATFORM" = "cdrom" ] ; then
182
	echo -n "Mounting unionfs directories..."
183
	/bin/mkdir /tmp/unionfs
184
	/bin/mkdir /tmp/unionfs/usr
185
	/bin/mkdir /tmp/unionfs/root
186
	/bin/mkdir /tmp/unionfs/sbin
187
	/bin/mkdir /tmp/unionfs/bin
188
	/bin/mkdir /tmp/unionfs/boot
189
	/bin/mkdir /tmp/unionfs/confdefault
190
	/sbin/mount_unionfs /tmp/unionfs/usr /usr/
191
	/sbin/mount_unionfs /tmp/unionfs/root /root/
192
	/sbin/mount_unionfs /tmp/unionfs/bin /bin/
193
	/sbin/mount_unionfs /tmp/unionfs/sbin /sbin/
194
	/sbin/mount_unionfs /tmp/unionfs/boot /boot/
195
	/sbin/mount_unionfs /tmp/unionfs/confdefault /conf.default/
196
	echo "done."
197
fi
198

    
199
# make some directories in /var
200
/bin/mkdir -p $varrunpath /var/log /var/etc /var/db/entropy /var/db/rrd /var/at/jobs/ /var/empty 2>/dev/null
201
/bin/rm -rf $varrunpath/*
202
if [ "$PLATFORM" != "pfSense" ]; then
203
	/bin/rm /var/log/* 2>/dev/null
204
fi
205

    
206
# Cleanup configuration files from previous instance
207
/bin/rm -rf /var/etc/*
208

    
209
echo -n "Creating symlinks..."
210
# Repair symlinks if they are broken
211
if [ -f /etc/newsyslog.conf ]; then
212
	/bin/rm -f /etc/newsyslog.conf
213
fi
214
if [ ! -L /etc/syslog.conf ]; then
215
	/bin/rm -rf /etc/syslog.conf
216
	if [ ! -f /var/etc/syslog.conf ]; then
217
		touch /var/etc/syslog.conf
218
	fi
219
	/bin/ln -s /var/etc/syslog.conf /etc/syslog.conf
220
fi
221

    
222
# Repair symlinks if they are broken
223
if [ ! -L /etc/hosts ]; then
224
	/bin/rm -rf /etc/hosts
225
	/bin/ln -s /var/etc/hosts /etc/hosts
226
fi
227

    
228
if [ ! -L /etc/resolv.conf ]; then
229
	/bin/rm -rf /etc/resolv.conf
230
	/bin/ln -s /var/etc/resolv.conf /etc/resolv.conf
231
fi
232

    
233
if [ ! -L /etc/resolvconf.conf ]; then
234
	/bin/rm -rf /etc/resolvconf.conf
235
	/bin/ln -s /var/etc/resolvconf.conf /etc/resolvconf.conf
236
fi
237

    
238
# Setup compatibility link for packages that
239
# have trouble overriding the PREFIX configure
240
# argument since we build our packages in a
241
# separated PREFIX area
242
# Only create if symlink does not exist.
243
if [ ! -h /tmp/tmp ]; then
244
	/bin/ln -hfs / /tmp/tmp
245
fi
246

    
247
# Make sure our /tmp is 777 + Sticky
248
if [ ! "$PLATFORM" = "cdrom" ] ; then
249
	/bin/rm -rf /tmp/*
250
fi
251
/bin/chmod 1777 /tmp
252

    
253
if [ ! "$PLATFORM" = "cdrom" ] ; then
254
	# Malloc debugging check
255
	if [ -L /etc/malloc.conf ]; then
256
		#ln -s aj /etc/malloc.conf
257
		/bin/rm /etc/malloc.conf
258
	fi
259
fi
260

    
261
if [ ! -L /etc/dhclient.conf ]; then
262
	/bin/rm -rf /etc/dhclient.conf
263
fi
264

    
265
if [ ! -d /var/tmp ]; then
266
	/bin/mkdir -p /var/tmp
267
fi
268

    
269
set -T
270
trap "echo 'Reboot interrupted'; exit 1" 3
271

    
272
# Remove old nameserver resolution files
273
/bin/rm -f /var/etc/nameserver*
274

    
275
echo -n "."
276
DISABLESYSLOGCLOG=`/usr/bin/grep -c disablesyslogclog /cf/conf/config.xml`
277
ENABLEFIFOLOG=`/usr/bin/grep -c usefifolog /cf/conf/config.xml`
278
LOG_FILES="system filter dhcpd vpn pptps poes l2tps openvpn portalauth ipsec ppp relayd wireless lighttpd ntpd gateways resolver routing"
279

    
280
DEFAULT_LOG_FILE_SIZE=`/usr/local/bin/xmllint --xpath 'string(//pfsense/syslog/logfilesize)' /conf/config.xml`
281
if [ ! ${DEFAULT_LOG_FILE_SIZE} ]; then
282
	DEFAULT_LOG_FILE_SIZE=511488
283
fi
284

    
285
for logfile in $LOG_FILES; do
286
	if [ "$DISABLESYSLOGCLOG" -gt "0" ]; then
287
		/usr/bin/touch /var/log/$logfile.log
288
	else
289
		if [ ! -f /var/log/$logfile.log ]; then
290
			if [ "$ENABLEFIFOLOG" -gt "0" ]; then
291
				# generate fifolog files
292
				/usr/sbin/fifolog_create -s ${DEFAULT_LOG_FILE_SIZE} /var/log/$logfile.log
293
			else
294
				/usr/local/sbin/clog -i -s ${DEFAULT_LOG_FILE_SIZE} /var/log/$logfile.log
295
			fi
296
		fi
297
	fi
298
done
299

    
300
# change permissions on newly created fifolog files.
301
/bin/chmod 0600 /var/log/*.log
302

    
303
echo -n "."
304
DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
305
if [ "$DEVFS" = "0" ]; then
306
	mount_devfs devfs /dev
307
fi
308

    
309
# Create an initial utmp file
310
cd $varrunpath && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
311

    
312
echo -n "."
313
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
314
/etc/rc.d/ldconfig start 2>/dev/null
315

    
316
# Launching kbdmux(4)
317
if [ -f "/dev/kbdmux0" ]; then
318
	echo -n "."
319
	/usr/sbin/kbdcontrol -k /dev/kbdmux0 < /dev/console
320
	[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
321
	[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
322
fi
323

    
324
# Fire up unionfs if mount points exist.
325
if [ -f /dist/uniondirs ]; then
326
	echo -n "."
327
	/etc/rc.d/unionfs start
328
fi
329

    
330
echo "done."
331

    
332
# Recreate capabilities DB
333
/usr/bin/cap_mkdb /etc/login.conf
334

    
335
# Finish update
336
if [ -f /cf/conf/upgrade_in_progress ]; then
337
	echo "Running second stage of upgrade process..."
338
	/usr/local/sbin/pfsense-upgrade.sh -y
339
fi
340

    
341
# Run the php.ini setup file and populate
342
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
343
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
344
/usr/local/sbin/php-fpm -c /usr/local/lib/php.ini -y /usr/local/lib/php-fpm.conf -RD 2>&1 >/dev/null
345

    
346
# Launch external configuration loader for supported platforms
347
if [ "$PLATFORM" = "nanobsd" ]; then
348
	/usr/local/sbin/fcgicli -f /etc/ecl.php
349
fi
350

    
351
# Launch external configuration loader for supported platforms
352
if [ "$PLATFORM" = "pfSense" ]; then
353
	/usr/local/sbin/fcgicli -f /etc/ecl.php
354
fi
355

    
356
if [ -f /etc/rc.custom_boot_early ]; then
357
	/bin/echo -n "Launching /etc/rc.custom_boot_early...";
358
	/etc/rc.custom_boot_early
359
	echo "Done"
360
fi
361

    
362
export fcgipath=/var/run/php-fpm.socket
363
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
364

    
365
# let the PHP-based configuration subsystem set up the system now
366
echo -n "Launching the init system..."
367
/bin/rm -f /cf/conf/backup/backup.cache
368
/bin/rm -f /root/lighttpd*
369
/usr/bin/touch $varrunpath/booting
370

    
371
if [ "${PLATFORM}" = "nanobsd" ]; then
372
	# XXX This script does need all filesystems rw!!!!
373
	# Put this workaround for now until better ways are found.
374
	/sbin/mount -u -f -r -o sync,noatime /
375
	/sbin/mount -u -f -r -o sync,noatime /cf
376
fi
377

    
378
/etc/rc.bootup
379

    
380
# /etc/rc.bootup unset $g['booting'], and removes file
381
# Be sure the file is removed to not create troubles after
382
if [ -f $varrunpath/booting ]; then
383
	/bin/rm $varrunpath/booting
384
fi
385

    
386
echo -n "Starting CRON... "
387
cd /tmp && /usr/sbin/cron -s 2>/dev/null
388
echo "done."
389

    
390
# Start packages
391
/usr/local/sbin/fcgicli -f /etc/rc.start_packages
392

    
393
/bin/rm -rf /usr/local/pkg/pf/CVS
394

    
395
# Start ping handler every 240 seconds
396
/usr/local/bin/minicron 240 $varrunpath/ping_hosts.pid /usr/local/bin/ping_hosts.sh
397

    
398
# Start account expire handler every hour
399
/usr/local/bin/minicron 3600 $varrunpath/expire_accounts.pid '/usr/local/sbin/fcgicli -f /etc/rc.expireaccounts'
400

    
401
# Start alias url updater every 24 hours
402
/usr/local/bin/minicron 86400 $varrunpath/update_alias_url_data.pid '/usr/local/sbin/fcgicli -f /etc/rc.update_alias_url_data'
403

    
404
/bin/chmod a+rw /tmp/.
405

    
406
# Check for GEOM mirrors
407
GMIRROR_STATUS=`/sbin/gmirror status`
408
if [ "${GMIRROR_STATUS}" != "" ]; then
409
	# Using a flag file at bootup saves an expensive exec/check on each page load.
410
	/usr/bin/touch /var/run/gmirror_active
411
	# Setup monitoring/notifications
412
	/usr/local/bin/minicron 60 /var/run/gmirror_status_check.pid /usr/local/sbin/gmirror_status_check.php
413
fi
414

    
415
# Log product version to syslog
416
BUILDTIME=`cat /etc/version.buildtime`
417
ARCH=`uname -m`
418
echo "$product ($PLATFORM) $version $ARCH $BUILDTIME"
419

    
420
echo "Bootup complete"
421

    
422
/usr/local/bin/beep.sh start 2>&1 >/dev/null
423

    
424
# Reset the cache.  read-only requires this.
425
/bin/rm -f /tmp/config.cache
426

    
427
exit 0
(29-29/105)