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
# Version patch
29
version_patch="0"
30
if [ -f /etc/version.patch ]; then
31
	version_patch=`/bin/cat /etc/version.patch`
32
fi
33

    
34
if [ "${version_patch}" = "0" ]; then
35
	version_patch=""
36
else
37
	version_patch=" (Patch ${version_patch})"
38
fi
39

    
40
# Read product_name from $g, defaults to pfSense
41
# Use php -n here because we are not ready to load extensions yet
42
product=$(/usr/local/bin/php -n /usr/local/sbin/read_global_var product_name pfSense)
43

    
44
# Setup dumpdev/ddb/savecore"
45
echo "Configuring crash dumps..."
46
if [ "$PLATFORM" = "${product}" ]; then
47
	/etc/rc.dumpon
48
fi
49

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

    
55
if [ -e /root/force_fsck ]; then
56
	echo "Forcing filesystem(s) check..."
57
	/sbin/fsck -y -F -t ufs
58
fi
59

    
60
if [ "${PLATFORM}" != "cdrom" ]; then
61
	FSCK_ACTION_NEEDED=0
62
	/sbin/fsck -p -F
63
	case $? in
64
	0)
65
		echo "Filesystems are clean, continuing..."
66
		echo "Mounting filesystems..."
67
		;;
68
	8)
69
		echo "Preen mode recommended running a check that will be performed now."
70
		FSCK_ACTION_NEEDED=1
71
		;;
72
	*)
73
		echo "Stopping boot is recommended because filesystem manual action is needed, nevertheless automated repair of the filesystem will be attempted."
74
		FSCK_ACTION_NEEDED=1
75
		;;
76
	esac
77

    
78
	if [ ${FSCK_ACTION_NEEDED} = 1 ]; then
79
		echo "WARNING: Trying to recover filesystem from inconsistency..."
80
		/sbin/fsck -yF
81
	fi
82

    
83
	/sbin/mount -a 2>/dev/null
84
	mount_rc=$?
85
	attempts=0
86
	while [ ${mount_rc} -ne 0 -a ${attempts} -lt 3 ]; do
87
		/sbin/fsck -yF
88
		/sbin/mount -a 2>/dev/null
89
		mount_rc=$?
90
		attempts=$((attempts+1))
91
	done
92

    
93
	if [ "${PLATFORM}" = "nanobsd" ]; then
94
		# XXX This script does need all filesystems rw!!!!
95
		# Put this workaround for now until better ways are found.
96
		/sbin/mount -u -w -o sync,noatime /
97
		/sbin/mount -u -w -o sync,noatime /cf
98
	fi
99

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

    
110
	USE_MFS_TMPVAR=$(/usr/local/sbin/read_xml_tag.sh boolean system/use_mfs_tmpvar)
111
	unset MOVE_PKG_DATA
112
	if [ "$PLATFORM" = "${product}" ]; then
113
		# If use MFS var is disabled, move files back to place
114
		if [ "${USE_MFS_TMPVAR}" != "true" -a -f /root/var/db/pkg/local.sqlite ]; then
115
			MOVE_PKG_DATA=1
116
			rm -rf /var/db/pkg 2>/dev/null
117
			rm -rf /var/cache/pkg 2>/dev/null
118
			mv /root/var/db/pkg /var/db
119
			mv /root/var/cache/pkg /var/cache
120
		# If use MFS var is enabled, move files to a safe place
121
		elif [ "${USE_MFS_TMPVAR}" = "true" -a -f /var/db/pkg/local.sqlite ]; then
122
			MOVE_PKG_DATA=1
123
			/bin/mkdir -p /root/var/db /root/var/cache
124
			mv /var/db/pkg /root/var/db
125
			mv /var/cache/pkg /root/var/cache
126
		fi
127
	elif [ "${PLATFORM}" = "nanobsd" ]; then
128
		MOVE_PKG_DATA=1
129
	fi
130

    
131
	if [ "${PLATFORM}" = "nanobsd" ] || [ "${USE_MFS_TMPVAR}" = "true" ]; then
132
		/etc/rc.embedded
133
	fi
134

    
135
	if [ -n "${MOVE_PKG_DATA}" -o "${USE_MFS_TMPVAR}" = "true" ]; then
136
		/bin/mkdir -p /var/db /var/cache
137
		ln -sf ../../root/var/db/pkg /var/db/pkg
138
		ln -sf ../../root/var/cache/pkg /var/cache/pkg
139
	fi
140
fi
141

    
142
/bin/rm -f /root/force_fsck
143
/bin/rm -f /root/TRIM_set
144
/bin/rm -f /root/TRIM_unset
145

    
146
if [ "${PLATFORM}" = "nanobsd" ]; then
147
	/sbin/kldstat -qm zfs
148
	if [ $? -eq 0 ]; then
149
		/sbin/kldunload zfs
150
	fi
151
elif [ "$PLATFORM" = "${product}" ]; then
152
	# Handle ZFS read-only case
153
	/sbin/kldstat -qm zfs
154
	if [ $? -eq 0 ]; then
155
		ZFSFSAVAILABLE=$(/sbin/zfs mount 2>/dev/null | wc -l)
156
		if [ $ZFSFSAVAILABLE -eq 0 ]; then
157
			/sbin/kldunload zfs
158
		elif [ -f /usr/bin/grep ]; then
159
			ZFSROOT=`/sbin/zfs mount | /usr/bin/grep ' /$' | /usr/bin/cut -d ' ' -f 1`
160
			if [ "$ZFSROOT" != "" ]; then
161
				/sbin/zfs set readonly=off $ZFSROOT
162
			fi
163
		fi
164
	fi
165
elif [ "${PLATFORM}" = "cdrom" ]; then
166
	/etc/rc.cdrom
167
fi
168

    
169
# Disable APM on ATA drives. Leaving this on will kill drives long-term, especially laptop drives, by generating excessive Load Cycles.
170
if [ -f /etc/rc.disable_hdd_apm ]; then
171
	/etc/rc.disable_hdd_apm
172
fi
173

    
174
# Eject CD devices on 3G modems
175
MANUFACTURER="huawei|zte"
176
CDDEVICE=`dmesg |egrep -ie "($MANUFACTURER)" | awk -F: '/cd/ {print $1}'`
177
if [ "$CDDEVICE" != "" ]; then
178
	cdcontrol -f /dev/"$CDDEVICE" eject
179
fi
180

    
181
# Use php -n here because we are not ready to load extensions yet
182
varrunpath=$(/usr/local/bin/php -n /usr/local/sbin/read_global_var varrun_path "/var/run")
183

    
184
if [ "$PLATFORM" = "${product}" ] && [ "${USE_MFS_TMPVAR}" != "true" ]; then
185
	/sbin/mdmfs -S -M -s 4m md $varrunpath
186
fi
187

    
188
# Use php -n here because we are not ready to load extensions yet
189
hideplatform=$(/usr/local/bin/php -n /usr/local/sbin/read_global_var hideplatform)
190
if [ "$hideplatform" = "true" ]; then
191
	platformbanner="" # hide the platform
192
else
193
	platformbanner=" on the '${PLATFORM}' platform"
194
fi
195

    
196
echo
197
cat /etc/ascii-art/pfsense-logo-small.txt
198
echo
199
echo
200
echo "Welcome to ${product} ${version}${version_patch}${platformbanner}..."
201
echo
202

    
203
/sbin/conscontrol mute off >/dev/null
204

    
205
if [ "$PLATFORM" = "${product}" ]; then
206
	SWAPDEVICE=`/bin/cat /etc/fstab | /usr/bin/grep swap | /usr/bin/cut -f1`
207
	/sbin/swapon -a 2>/dev/null >/dev/null
208
	/etc/rc.savecore
209
fi
210

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

    
229
# make some directories in /var
230
/bin/mkdir -p $varrunpath /var/log /var/etc /var/db/entropy /var/db/rrd /var/at/jobs/ /var/empty 2>/dev/null
231
/bin/rm -rf $varrunpath/*
232
if [ "$PLATFORM" != "${product}" ]; then
233
	/bin/rm /var/log/* 2>/dev/null
234
fi
235

    
236
# Cleanup configuration files from previous instance
237
/bin/rm -rf /var/etc/*
238

    
239
# Workaround for ipsec symlinks, otherwise it's going to break
240
# strongswan pkg upgrade
241

    
242
if [ -L /usr/local/etc/ipsec.d ]; then
243
	rm -f /usr/local/etc/ipsec.d
244
fi
245
if [ -L /usr/local/etc/ipsec.conf ]; then
246
	rm -f /usr/local/etc/ipsec.conf
247
fi
248
if [ -L /usr/local/etc/strongswan.d ]; then
249
	rm -f /usr/local/etc/strongswan.d
250
fi
251
if [ -L /usr/local/etc/strongswan.conf ]; then
252
	rm -f /usr/local/etc/strongswan.conf
253
fi
254

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

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

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

    
279
if [ ! -L /etc/resolvconf.conf ]; then
280
	/bin/rm -rf /etc/resolvconf.conf
281
	/bin/ln -s /var/etc/resolvconf.conf /etc/resolvconf.conf
282
fi
283

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

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

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

    
307
if [ ! -L /etc/dhclient.conf ]; then
308
	/bin/rm -rf /etc/dhclient.conf
309
fi
310

    
311
if [ ! -d /var/tmp ]; then
312
	/bin/mkdir -p /var/tmp
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/local/sbin/read_xml_tag.sh boolean system/disablesyslogclog)
323
LOG_FILES="system filter dhcpd vpn pptps poes l2tps openvpn portalauth ipsec ppp relayd wireless nginx ntpd gateways resolver routing"
324

    
325
DEFAULT_LOG_FILE_SIZE=$(/usr/local/sbin/read_xml_tag.sh string syslog/logfilesize)
326
DEFAULT_LOG_FILE_SIZE=${DEFAULT_LOG_FILE_SIZE:-"511488"}
327

    
328
for logfile in $LOG_FILES; do
329
	if [ "$DISABLESYSLOGCLOG" = "true" ]; then
330
		/usr/bin/touch /var/log/$logfile.log
331
	else
332
		if [ ! -f /var/log/$logfile.log ]; then
333
			/usr/local/sbin/clog -i -s ${DEFAULT_LOG_FILE_SIZE} /var/log/$logfile.log
334
		fi
335
	fi
336
done
337

    
338
# change permissions on newly created log files.
339
/bin/chmod 0600 /var/log/*.log
340

    
341
echo -n "."
342
DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
343
if [ "$DEVFS" = "0" ]; then
344
	mount_devfs devfs /dev
345
fi
346

    
347
# Create an initial utmp file
348
cd $varrunpath && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
349

    
350
echo -n "."
351
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
352
/etc/rc.d/ldconfig start 2>/dev/null
353

    
354
# Launching kbdmux(4)
355
if [ -f "/dev/kbdmux0" ]; then
356
	echo -n "."
357
	/usr/sbin/kbdcontrol -k /dev/kbdmux0 < /dev/console
358
	[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
359
	[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
360
fi
361

    
362
# Fire up unionfs if mount points exist.
363
if [ -f /dist/uniondirs ]; then
364
	echo -n "."
365
	/etc/rc.d/unionfs start
366
fi
367

    
368
echo "done."
369

    
370
# Recreate capabilities DB
371
/usr/bin/cap_mkdb /etc/login.conf
372

    
373
# Second upgrade stage
374
/usr/local/sbin/${product}-upgrade -y -b 2
375

    
376
# Run the php.ini setup file and populate
377
# /usr/local/etc/php.ini
378
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
379
/usr/local/sbin/php-fpm -c /usr/local/etc/php.ini -y /usr/local/lib/php-fpm.conf -RD 2>&1 >/dev/null
380

    
381
# Launch external configuration loader for supported platforms
382
if [ "$PLATFORM" = "nanobsd" ]; then
383
	/usr/local/sbin/fcgicli -f /etc/ecl.php
384
fi
385

    
386
# Launch external configuration loader for supported platforms
387
if [ "$PLATFORM" = "${product}" ]; then
388
	/usr/local/sbin/fcgicli -f /etc/ecl.php
389
fi
390

    
391
if [ -f /etc/rc.custom_boot_early ]; then
392
	/bin/echo -n "Launching /etc/rc.custom_boot_early...";
393
	/etc/rc.custom_boot_early
394
	echo "Done"
395
fi
396

    
397
export fcgipath=/var/run/php-fpm.socket
398
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
399

    
400
# let the PHP-based configuration subsystem set up the system now
401
echo -n "Launching the init system..."
402
/bin/rm -f /cf/conf/backup/backup.cache
403
/usr/bin/touch $varrunpath/booting
404

    
405
if [ "${PLATFORM}" = "nanobsd" ]; then
406
	# XXX This script does need all filesystems rw!!!!
407
	# Put this workaround for now until better ways are found.
408
	/sbin/mount -u -f -r -o sync,noatime /
409
	/sbin/mount -u -f -r -o sync,noatime /cf
410
fi
411

    
412
/etc/rc.bootup
413

    
414
# /etc/rc.bootup unset $g['booting'], and removes file
415
# Be sure the file is removed to not create troubles after
416
if [ -f $varrunpath/booting ]; then
417
	/bin/rm $varrunpath/booting
418
fi
419

    
420
echo -n "Starting CRON... "
421
cd /tmp && /usr/sbin/cron -s 2>/dev/null
422
echo "done."
423

    
424
# Start packages
425
/usr/local/sbin/fcgicli -f /etc/rc.start_packages
426

    
427
/bin/rm -rf /usr/local/pkg/pf/CVS
428

    
429
# Start ping handler every 240 seconds
430
/usr/local/bin/minicron 240 $varrunpath/ping_hosts.pid /usr/local/bin/ping_hosts.sh
431

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

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

    
438
/bin/chmod a+rw /tmp/.
439

    
440
# Check for GEOM mirrors
441
GMIRROR_STATUS=`/sbin/gmirror status`
442
if [ "${GMIRROR_STATUS}" != "" ]; then
443
	# Using a flag file at bootup saves an expensive exec/check on each page load.
444
	/usr/bin/touch /var/run/gmirror_active
445
	# Setup monitoring/notifications
446
	/usr/local/bin/minicron 60 /var/run/gmirror_status_check.pid /usr/local/sbin/gmirror_status_check.php
447
fi
448

    
449
/usr/local/sbin/${product}-upgrade -y -b 3
450

    
451
# Log product version to syslog
452
BUILDTIME=`cat /etc/version.buildtime`
453
ARCH=`uname -m`
454
echo "$product ($PLATFORM) ${version}${version_patch} $ARCH $BUILDTIME"
455

    
456
echo "Bootup complete"
457

    
458
/usr/local/bin/beep.sh start 2>&1 >/dev/null
459

    
460
# Reset the cache.  read-only requires this.
461
/bin/rm -f /tmp/config.cache
462

    
463
exit 0
(15-15/86)