Project

General

Profile

Download (12.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 check..."
41
	/sbin/fsck -y -t ufs /
42
	if [ "$PLATFORM" = "nanobsd" ]; then
43
		/sbin/fsck -y -t ufs /cf
44
	fi
45
fi
46

    
47
if [ "${PLATFORM}" = "nanobsd" ]; then
48
	kldstat -qm zfs
49
	if [ $? -eq 0 ]; then
50
		kldunload zfs
51
	fi
52
fi
53

    
54
# Mount memory file system if it exists
55
echo "Mounting filesystems..."
56

    
57
# Handle ZFS read-only case
58
if [ "$PLATFORM" = "pfSense" ]; then
59
	kldstat -qm zfs
60
	if [ $? -eq 0 ]; then
61
		ZFSFSAVAILABLE=$(/sbin/zfs mount 2>/dev/null | wc -l)
62
		if [ $ZFSFSAVAILABLE -eq 0 ]; then
63
			kldunload zfs
64
		elif [ -f /usr/bin/grep ]; then
65
			ZFSROOT=`/sbin/zfs mount | /usr/bin/grep ' /$' | /usr/bin/cut -d ' ' -f 1`
66
			if [ "$ZFSROOT" != "" ]; then
67
				/sbin/zfs set readonly=off $ZFSROOT
68
			fi
69
		fi
70
	fi
71
fi
72

    
73
if [ "${PLATFORM}" = "cdrom" ]; then
74
	/etc/rc.cdrom
75
else
76
	# Mount /. If it fails run a fsck.
77
	if [ "$PLATFORM" = "nanobsd" ]; then
78
		export PKG_TMPDIR=/root/
79
		/sbin/mount -uw / 2>/dev/null
80
		mount_rc=$?
81
		attempts=0
82
		while [ ${mount_rc} -ne 0 -a ${attempts} -lt 3 ]; do
83
			/sbin/fsck -y /
84
			/sbin/fsck -y /cf
85
			/sbin/mount -uw / 2>/dev/null
86
			mount_rc=$?
87
			attempts=$((attempts+1))
88
		done
89
	else
90
		/sbin/mount -a 2>/dev/null
91
		mount_rc=$?
92
		attempts=0
93
		while [ ${mount_rc} -ne 0 -a ${attempts} -lt 3 ]; do
94
			/sbin/fsck -y /
95
			/sbin/mount -a 2>/dev/null
96
			mount_rc=$?
97
			attempts=$((attempts+1))
98
		done
99
	fi
100

    
101
	# If /conf is a directory, convert it to a symlink to /cf/conf
102
	if [ -d "/conf" ]; then
103
		# If item is not a symlink then rm and recreate
104
		CONFPOINTSTO=`readlink /conf` 
105
		if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then 
106
			/bin/rm -rf /conf
107
			/bin/ln -s /cf/conf /conf
108
		fi
109
	fi
110

    
111
	if [ ! "$PLATFORM" = "jail" ]; then
112
		# Check to see if a compact flash mountpoint exists
113
		# If it fails to mount then run a fsck -y
114
		if grep -q cf /etc/fstab; then
115
			/sbin/mount -w /cf 2>/dev/null
116
			/sbin/mount -uw /cf 2>/dev/null
117
			mount_rc=$?
118
			attempts=0
119
			while [ ${mount_rc} -ne 0 -a ${attempts} -lt 3 ]; do
120
				/sbin/umount /cf
121
				/sbin/fsck -y /cf
122
				/sbin/mount -w /cf 2>/dev/null
123
				mount_rc=$?
124
				attempts=$((attempts+1))
125
			done
126
		fi
127
	fi
128

    
129
	USE_MFS_TMPVAR=`/usr/bin/grep -c use_mfs_tmpvar /cf/conf/config.xml`
130
	if [ "${PLATFORM}" = "nanobsd" ] || [ ${USE_MFS_TMPVAR} -gt 0 ]; then
131
		/etc/rc.embedded
132
	fi
133
fi
134

    
135
/bin/rm -f /root/force_fsck
136
/bin/rm -f /root/TRIM_set
137
/bin/rm -f /root/TRIM_unset
138

    
139
# Disable APM on ATA drives. Leaving this on will kill drives long-term, especially laptop drives, by generating excessive Load Cycles.
140
if [ -f /etc/rc.disable_hdd_apm ]; then
141
	/etc/rc.disable_hdd_apm
142
fi
143

    
144
#Eject CD devices on 3G modems
145
MANUFACTURER="huawei|zte"
146
CDDEVICE=`dmesg |egrep -ie "($MANUFACTURER)" | awk -F: '/cd/ {print $1}'`
147
if [ "$CDDEVICE" != "" ]; then
148
	cdcontrol -f /dev/"$CDDEVICE" eject
149
fi
150

    
151
# sync pw database after mount.
152
rm -f /etc/spwd.db.tmp
153
/usr/sbin/pwd_mkdb -d /etc/ /etc/master.passwd
154

    
155
product=`/usr/bin/grep product_name /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
156
hideplatform=`/usr/bin/grep hideplatform /etc/inc/globals.inc | /usr/bin/wc -l`
157
varrunpath=`/usr/bin/grep varrun_path /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
158

    
159
if [ "$PLATFORM" = "pfSense" ] && [ ${USE_MFS_TMPVAR} -eq 0 ]; then
160
	/sbin/mdmfs -S -M -s 4m md $varrunpath
161
fi
162

    
163
if [ "$hideplatform" -gt "0" ]; then
164
	platformbanner="" # hide the platform
165
else
166
	platformbanner=" on the '${PLATFORM}' platform"
167
fi
168

    
169
echo
170
cat /etc/ascii-art/pfsense-logo-small.txt
171
echo
172
echo
173
echo "Welcome to ${product} ${version} ${platformbanner} ..."
174
echo
175

    
176
if [ ! "$PLATFORM" = "jail" ]; then
177
	# Enable console output if its muted.
178
	/sbin/conscontrol mute off >/dev/null
179
fi
180

    
181
if [ "$PLATFORM" = "cdrom" ] ; then
182
	# do nothing for cdrom platform
183
elif [ "$PLATFORM" = "nanobsd" ] || [ ${USE_MFS_TMPVAR} -gt 0 ]; then
184
	# Ensure that old-style PKG packages can be persistent across reboots
185
	/bin/mkdir -p /root/var/db/pkg
186
	/bin/rm -rf /var/db/pkg
187
	/bin/ln -s /root/var/db/pkg/ /var/db/pkg
188
	# Ensure that PBI packages can be persistent across reboots
189
	/bin/mkdir -p /root/var/db/pbi
190
	/bin/rm -rf /var/db/pbi
191
	/bin/ln -s /root/var/db/pbi/ /var/db/pbi
192
elif [ "$PLATFORM" = "jail" ]; then
193
	# do nothing for jail platform
194
else
195
	SWAPDEVICE=`/bin/cat /etc/fstab | /usr/bin/grep swap | /usr/bin/cut -f1`
196
	/sbin/swapon -a 2>/dev/null >/dev/null
197
	/etc/rc.savecore
198

    
199
	if [ -d /root/var/db/pkg ]; then
200
		# User must have just disabled RAM disks, move these back into place.
201
		/bin/mkdir -p /var/db/pkg
202
		/bin/mv /root/var/db/pkg /var/db/pkg
203
		/bin/mkdir -p /var/db/pbi
204
		/bin/mv /root/var/db/pbi /var/db/pbi
205
	fi
206
fi
207

    
208
# Copy PBI keys
209
if ls /usr/local/share/pbi-keys/*.ssl >/dev/null 2>&1; then
210
	if [ ! -d "/var/db/pbi/keys" ]; then
211
		mkdir -p /var/db/pbi/keys
212
	fi
213
	cp -f /usr/local/share/pbi-keys/*.ssl /var/db/pbi/keys
214
fi
215

    
216
if [ "$PLATFORM" = "cdrom" ] ; then
217
	echo -n "Mounting unionfs directories..."
218
	/bin/mkdir /tmp/unionfs
219
	/bin/mkdir /tmp/unionfs/usr
220
	/bin/mkdir /tmp/unionfs/root
221
	/bin/mkdir /tmp/unionfs/sbin
222
	/bin/mkdir /tmp/unionfs/bin
223
	/bin/mkdir /tmp/unionfs/boot
224
	/bin/mkdir /tmp/unionfs/confdefault
225
	/sbin/mount_unionfs /tmp/unionfs/usr /usr/
226
	/sbin/mount_unionfs /tmp/unionfs/root /root/
227
	/sbin/mount_unionfs /tmp/unionfs/bin /bin/		
228
	/sbin/mount_unionfs /tmp/unionfs/sbin /sbin/	
229
	/sbin/mount_unionfs /tmp/unionfs/boot /boot/
230
	/sbin/mount_unionfs /tmp/unionfs/confdefault /conf.default/
231
	echo "done."
232
fi
233

    
234
# make some directories in /var
235
/bin/mkdir -p $varrunpath /var/log /var/etc /var/db/entropy /var/db/rrd /var/at/jobs/ /var/empty 2>/dev/null
236
/bin/rm -rf $varrunpath/*
237
if [ "$PLATFORM" != "pfSense" ]; then
238
	/bin/rm /var/log/* 2>/dev/null
239
fi
240

    
241
# Cleanup configuration files from previous instance
242
/bin/rm -rf /var/etc/*
243
/bin/rm -rf /var/tmp/*
244

    
245
echo -n "Creating symlinks..."
246
# Make sure symlink is correct on nanobsd
247
if [ "$PLATFORM" = "nanobsd" ] ; then
248
	/bin/rm /conf
249
	/bin/ln -s /cf/conf/ /conf
250
fi
251

    
252
# Repair symlinks if they are broken
253
if [ -f /etc/newsyslog.conf ]; then
254
	/bin/rm -f /etc/newsyslog.conf
255
fi
256
if [ ! -L /etc/syslog.conf ]; then
257
	/bin/rm -rf /etc/syslog.conf
258
	if [ ! -f /var/etc/syslog.conf ]; then
259
		touch /var/etc/syslog.conf
260
	fi
261
	/bin/ln -s /var/etc/syslog.conf /etc/syslog.conf
262
fi
263

    
264
# Repair symlinks if they are broken
265
if [ ! -L /etc/hosts ]; then
266
	/bin/rm -rf /etc/hosts
267
	/bin/ln -s /var/etc/hosts /etc/hosts
268
fi
269

    
270
if [ ! -L /etc/resolv.conf ]; then
271
    /bin/rm -rf /etc/resolv.conf
272
    /bin/ln -s /var/etc/resolv.conf /etc/resolv.conf
273
fi
274

    
275
if [ ! -L /etc/resolvconf.conf ]; then
276
    /bin/rm -rf /etc/resolvconf.conf
277
    /bin/ln -s /var/etc/resolvconf.conf /etc/resolvconf.conf
278
fi
279

    
280
# Setup compatibility link for packages that
281
# have trouble overriding the PREFIX configure
282
# argument since we build our packages in a
283
# separated PREFIX area
284
# Only create if symlink does not exist. 
285
if [ ! -h /tmp/tmp ]; then
286
    /bin/ln -hfs / /tmp/tmp
287
fi
288

    
289
# Make sure our /tmp is 777 + Sticky
290
if [ ! "$PLATFORM" = "cdrom" ] ; then
291
	/bin/rm -rf /tmp/*
292
fi
293
/bin/chmod 1777 /tmp
294

    
295
if [ ! "$PLATFORM" = "cdrom" ] ; then
296
	# Malloc debugging check
297
	if [ -L /etc/malloc.conf ]; then
298
	    #ln -s aj /etc/malloc.conf
299
		/bin/rm /etc/malloc.conf
300
	fi
301
fi
302

    
303
if [ ! -L /etc/dhclient.conf ]; then
304
    /bin/rm -rf /etc/dhclient.conf
305
fi
306

    
307
if [ ! -d /var/tmp ]; then
308
	/bin/mkdir -p /var/tmp
309
fi
310

    
311
if [ ! -d /cf/conf/backup/ ]; then
312
	/bin/mkdir -p /cf/conf/backup/ 
313
fi
314

    
315
set -T
316
trap "echo 'Reboot interrupted'; exit 1" 3
317

    
318
# Remove old nameserver resolution files
319
/bin/rm -f /var/etc/nameserver*
320

    
321
echo -n "."
322
DISABLESYSLOGCLOG=`/usr/bin/grep -c disablesyslogclog /cf/conf/config.xml`
323
ENABLEFIFOLOG=`/usr/bin/grep -c usefifolog /cf/conf/config.xml`
324
LOG_FILES="system filter dhcpd vpn pptps poes l2tps openvpn portalauth ipsec ppp relayd wireless lighttpd ntpd gateways resolver routing"
325

    
326
DEFAULT_LOG_FILE_SIZE=`/usr/local/bin/xmllint --xpath 'string(//pfsense/syslog/logfilesize)' /conf/config.xml`
327
if [ ! ${DEFAULT_LOG_FILE_SIZE} ]; then
328
	DEFAULT_LOG_FILE_SIZE=511488
329
fi
330

    
331
for logfile in $LOG_FILES; do
332
	if [ "$DISABLESYSLOGCLOG" -gt "0" ]; then 
333
		/usr/bin/touch /var/log/$logfile.log
334
	else 
335
		if [ ! -f /var/log/$logfile.log ]; then
336
			if [ "$ENABLEFIFOLOG" -gt "0" ]; then
337
				# generate fifolog files
338
				/usr/sbin/fifolog_create -s ${DEFAULT_LOG_FILE_SIZE} /var/log/$logfile.log
339
			else 
340
				/usr/local/sbin/clog -i -s ${DEFAULT_LOG_FILE_SIZE} /var/log/$logfile.log
341
			fi
342
		fi
343
	fi 
344
done
345

    
346
# change permissions on newly created fifolog files.
347
/bin/chmod 0600 /var/log/*.log
348

    
349
echo -n "."
350
if [ ! "$PLATFORM" = "jail" ]; then
351
	DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
352
	if [ "$DEVFS" = "0" ]; then
353
		mount_devfs devfs /dev
354
	fi
355
fi
356

    
357
# Create an initial utmp file
358
cd $varrunpath && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
359

    
360
echo -n "."
361
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
362
/etc/rc.d/ldconfig start 2>/dev/null
363

    
364
# Make sure /etc/rc.conf doesn't exist.
365
if [ -f /etc/rc.conf ]; then
366
    /bin/rm -rf /etc/rc.conf
367
fi
368

    
369
if [ ! "$PLATFORM" = "jail" ]; then
370
	# Launching kbdmux(4)
371
	if [ -f "/dev/kbdmux0" ]; then
372
		echo -n "."
373
		/usr/sbin/kbdcontrol -k /dev/kbdmux0 < /dev/console
374
		[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
375
		[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
376
	fi
377

    
378
	# Fire up unionfs if mount points exist.
379
	if [ -f /dist/uniondirs ]; then
380
		echo -n "."
381
		/etc/rc.d/unionfs start
382
	fi
383
fi
384

    
385
echo "done."
386

    
387
# Recreate capabilities DB
388
/usr/bin/cap_mkdb /etc/login.conf
389

    
390
# Run the php.ini setup file and populate
391
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
392
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
393
/usr/local/sbin/php-fpm -c /usr/local/lib/php.ini -y /usr/local/lib/php-fpm.conf -RD 2>&1 >/dev/null
394

    
395
# Launch external configuration loader for supported platforms
396
if [ "$PLATFORM" = "nanobsd" ]; then
397
	/usr/local/sbin/fcgicli -f /etc/ecl.php
398
fi
399

    
400
# Launch external configuration loader for supported platforms
401
if [ "$PLATFORM" = "pfSense" ]; then
402
	/usr/local/sbin/fcgicli -f /etc/ecl.php
403
fi
404

    
405
if [ -f /etc/rc.custom_boot_early ]; then
406
	/bin/echo -n "Launching /etc/rc.custom_boot_early...";
407
	/etc/rc.custom_boot_early
408
	echo "Done"
409
fi
410

    
411
export fcgipath=/var/run/php-fpm.socket
412
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
413

    
414
# let the PHP-based configuration subsystem set up the system now
415
echo -n "Launching the init system..."
416
/bin/rm -f /cf/conf/backup/backup.cache
417
/bin/rm -f /root/lighttpd*
418
/usr/bin/touch $varrunpath/booting
419
/etc/rc.bootup
420

    
421
# /etc/rc.bootup unset $g['booting'], and removes file
422
# Be sure the file is removed to not create troubles after
423
if [ -f $varrunpath/booting ]; then
424
	/bin/rm $varrunpath/booting
425
fi
426

    
427
# If a shell was selected from recovery 
428
# console then just drop to the shell now.
429
if [ -f "/tmp/donotbootup" ]; then
430
	echo "Dropping to recovery shell."
431
	exit 0
432
fi
433

    
434
echo -n "Starting CRON... "
435
cd /tmp && /usr/sbin/cron -s 2>/dev/null
436
echo "done."
437

    
438
# Start packages
439
/usr/local/sbin/fcgicli -f /etc/rc.start_packages
440

    
441
/bin/rm -rf /usr/local/pkg/pf/CVS
442

    
443
# Start ping handler every 240 seconds
444
/usr/local/bin/minicron 240 $varrunpath/ping_hosts.pid /usr/local/bin/ping_hosts.sh
445

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

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

    
452
/bin/chmod a+rw /tmp/.
453

    
454
# Check for GEOM mirrors
455
GMIRROR_STATUS=`/sbin/gmirror status`
456
if [ "${GMIRROR_STATUS}" != "" ]; then
457
	# Using a flag file at bootup saves an expensive exec/check on each page load.
458
	/usr/bin/touch /var/run/gmirror_active
459
	# Setup monitoring/notifications
460
	/usr/local/bin/minicron 60 /var/run/gmirror_status_check.pid /usr/local/sbin/gmirror_status_check.php
461
fi
462

    
463
# Log product version to syslog
464
BUILDTIME=`cat /etc/version.buildtime`
465
ARCH=`uname -m`
466
echo "$product ($PLATFORM) $version $ARCH $BUILDTIME"
467

    
468
echo "Bootup complete"
469

    
470
/usr/local/bin/beep.sh start 2>&1 >/dev/null
471

    
472
# Reset the cache.  read-only requires this.
473
/bin/rm -f /tmp/config.cache
474

    
475
exit 0
(29-29/103)