Project

General

Profile

Download (12.8 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 [ $? = 0 ]; then
50
		kldunload zfs
51
	fi
52
fi
53

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
322
# Create uploadbar tmp directory
323
/bin/mkdir -p /tmp/uploadbar
324
/bin/chmod 0777 /tmp/uploadbar
325

    
326
echo -n "."
327
DISABLESYSLOGCLOG=`/usr/bin/grep -c disablesyslogclog /cf/conf/config.xml`
328
ENABLEFIFOLOG=`/usr/bin/grep -c usefifolog /cf/conf/config.xml`
329
LOG_FILES="system filter dhcpd vpn pptps poes l2tps openvpn portalauth ipsec ppp relayd wireless lighttpd ntpd gateways resolver routing"
330

    
331
DEFAULT_LOG_FILE_SIZE=`/usr/local/bin/xmllint --xpath 'string(//pfsense/syslog/logfilesize)' /conf/config.xml`
332
if [ ! ${DEFAULT_LOG_FILE_SIZE} ]; then
333
	DEFAULT_LOG_FILE_SIZE=511488
334
fi
335

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

    
351
# change permissions on newly created fifolog files.
352
/bin/chmod 0600 /var/log/*.log
353

    
354
echo -n "."
355
if [ ! "$PLATFORM" = "jail" ]; then
356
	DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
357
	if [ "$DEVFS" = "0" ]; then
358
		mount_devfs devfs /dev
359
	fi
360
fi
361

    
362
# Create an initial utmp file
363
cd $varrunpath && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
364

    
365
echo -n "."
366
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
367
/etc/rc.d/ldconfig start 2>/dev/null
368

    
369
# Make sure /etc/rc.conf doesn't exist.
370
if [ -f /etc/rc.conf ]; then
371
    /bin/rm -rf /etc/rc.conf
372
fi
373

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

    
383
	# Fire up unionfs if mount points exist.
384
	if [ -f /dist/uniondirs ]; then
385
		echo -n "."
386
		/etc/rc.d/unionfs start
387
	fi
388
fi
389

    
390
echo "done."
391

    
392
# Recreate capabilities DB
393
/usr/bin/cap_mkdb /etc/login.conf
394

    
395
# Run the php.ini setup file and populate
396
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
397
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
398
/usr/local/sbin/php-fpm -c /usr/local/lib/php.ini -y /usr/local/lib/php-fpm.conf -RD 2>&1 >/dev/null
399

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

    
405
# Launch external configuration loader for supported platforms
406
if [ "$PLATFORM" = "pfSense" ]; then
407
	/usr/local/sbin/fcgicli -f /etc/ecl.php
408
fi
409

    
410
if [ -f /etc/rc.custom_boot_early ]; then
411
	/bin/echo -n "Launching /etc/rc.custom_boot_early...";
412
	/etc/rc.custom_boot_early
413
	echo "Done"
414
fi
415

    
416
export fcgipath=/var/run/php-fpm.socket
417
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
418

    
419
# let the PHP-based configuration subsystem set up the system now
420
echo -n "Launching the init system..."
421
/bin/rm -f /cf/conf/backup/backup.cache
422
/bin/rm -f /root/lighttpd*
423
/usr/bin/touch $varrunpath/booting
424
/etc/rc.bootup
425

    
426
# /etc/rc.bootup unset $g['booting'], and removes file
427
# Be sure the file is removed to not create troubles after
428
if [ -f $varrunpath/booting ]; then
429
	/bin/rm $varrunpath/booting
430
fi
431

    
432
# If a shell was selected from recovery 
433
# console then just drop to the shell now.
434
if [ -f "/tmp/donotbootup" ]; then
435
	echo "Dropping to recovery shell."
436
	exit 0
437
fi
438

    
439
echo -n "Starting CRON... "
440
cd /tmp && /usr/sbin/cron -s 2>/dev/null
441
echo "done."
442

    
443
# Start packages
444
/usr/local/sbin/fcgicli -f /etc/rc.start_packages
445

    
446
/bin/rm -rf /usr/local/pkg/pf/CVS
447

    
448
# Start ping handler every 240 seconds
449
/usr/local/bin/minicron 240 $varrunpath/ping_hosts.pid /usr/local/bin/ping_hosts.sh
450

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

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

    
457
/bin/chmod a+rw /tmp/.
458

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

    
468
# Log product version to syslog
469
BUILDTIME=`cat /etc/version.buildtime`
470
ARCH=`uname -m`
471
echo "$product ($PLATFORM) $version $ARCH $BUILDTIME"
472

    
473
echo "Bootup complete"
474

    
475
/usr/local/bin/beep.sh start 2>&1 >/dev/null
476

    
477
# Reset the cache.  read-only requires this.
478
/bin/rm -f /tmp/config.cache
479

    
480
exit 0
(29-29/103)