Project

General

Profile

Download (12.6 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
# Read product_name from $g, defaults to pfSense
29
# Use php -n here because we are not ready to load extensions yet
30
product=$(/usr/local/bin/php -n /usr/local/sbin/read_global_var product_name pfSense)
31

    
32
# Setup dumpdev/ddb/savecore"
33
echo "Configuring crash dumps..."
34
if [ "$PLATFORM" = "${product}" ]; then
35
	/etc/rc.dumpon
36
fi
37

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

    
43
if [ -e /root/force_fsck ]; then
44
	echo "Forcing filesystem(s) check..."
45
	/sbin/fsck -y -F -t ufs
46
fi
47

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

    
66
	if [ ${FSCK_ACTION_NEEDED} = 1 ]; then
67
		echo "WARNING: Trying to recover filesystem from inconsistency..."
68
		/sbin/fsck -yF
69
	fi
70

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

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

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

    
98
	USE_MFS_TMPVAR=$(/usr/local/sbin/read_xml_tag.sh boolean system/use_mfs_tmpvar)
99
	if [ "${PLATFORM}" = "nanobsd" ] || [ "${USE_MFS_TMPVAR}" = "true" ]; then
100
		/etc/rc.embedded
101
	fi
102
fi
103

    
104
/bin/rm -f /root/force_fsck
105
/bin/rm -f /root/TRIM_set
106
/bin/rm -f /root/TRIM_unset
107

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

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

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

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

    
146
if [ "$PLATFORM" = "${product}" ] && [ "${USE_MFS_TMPVAR}" != "true" ]; then
147
	/sbin/mdmfs -S -M -s 4m md $varrunpath
148
fi
149

    
150
# Use php -n here because we are not ready to load extensions yet
151
hideplatform=$(/usr/local/bin/php -n /usr/local/sbin/read_global_var hideplatform)
152
if [ "$hideplatform" = "true" ]; then
153
	platformbanner="" # hide the platform
154
else
155
	platformbanner=" on the '${PLATFORM}' platform"
156
fi
157

    
158
echo
159
cat /etc/ascii-art/pfsense-logo-small.txt
160
echo
161
echo
162
echo "Welcome to ${product} ${version} ${platformbanner} ..."
163
echo
164

    
165
/sbin/conscontrol mute off >/dev/null
166

    
167
if [ "$PLATFORM" = "${product}" ]; then
168
	# If use MFS var is disabled, move files back to place
169
	if [ "${USE_MFS_TMPVAR}" != "true" -a -d /root/var/db/pkg ]; then
170
		rm -rf /var/db/pkg 2>/dev/null
171
		rm -rf /var/cache/pkg 2>/dev/null
172
		mv /root/var/db/pkg /var/db
173
		mv /root/var/cache/pkg /var/cache
174
	# If use MFS var is enabled, move files to a safe place
175
	elif [ "${USE_MFS_TMPVAR}" = "true" -a ! -d /root/var/db/pkg ]; then
176
		/bin/mkdir -p /root/var/db /root/var/cache
177
		mv /var/db/pkg /root/var/db
178
		mv /var/cache/pkg /root/var/cache
179
		ln -sf ../../root/var/db/pkg /var/db/pkg
180
		ln -sf ../../root/var/cache/pkg /var/cache/pkg
181
	fi
182

    
183
	SWAPDEVICE=`/bin/cat /etc/fstab | /usr/bin/grep swap | /usr/bin/cut -f1`
184
	/sbin/swapon -a 2>/dev/null >/dev/null
185
	/etc/rc.savecore
186
elif [ "${PLATFORM}" = "nanobsd" ]; then
187
	/bin/mkdir -p /var/db /var/cache
188
	ln -sf ../../root/var/db/pkg /var/db/pkg
189
	ln -sf ../../root/var/cache/pkg /var/cache/pkg
190
fi
191

    
192
if [ "$PLATFORM" = "cdrom" ] ; then
193
	echo -n "Mounting unionfs directories..."
194
	/bin/mkdir /tmp/unionfs
195
	/bin/mkdir /tmp/unionfs/usr
196
	/bin/mkdir /tmp/unionfs/root
197
	/bin/mkdir /tmp/unionfs/sbin
198
	/bin/mkdir /tmp/unionfs/bin
199
	/bin/mkdir /tmp/unionfs/boot
200
	/bin/mkdir /tmp/unionfs/confdefault
201
	/sbin/mount_unionfs /tmp/unionfs/usr /usr/
202
	/sbin/mount_unionfs /tmp/unionfs/root /root/
203
	/sbin/mount_unionfs /tmp/unionfs/bin /bin/
204
	/sbin/mount_unionfs /tmp/unionfs/sbin /sbin/
205
	/sbin/mount_unionfs /tmp/unionfs/boot /boot/
206
	/sbin/mount_unionfs /tmp/unionfs/confdefault /conf.default/
207
	echo "done."
208
fi
209

    
210
# make some directories in /var
211
/bin/mkdir -p $varrunpath /var/log /var/etc /var/db/entropy /var/db/rrd /var/at/jobs/ /var/empty 2>/dev/null
212
/bin/rm -rf $varrunpath/*
213
if [ "$PLATFORM" != "${product}" ]; then
214
	/bin/rm /var/log/* 2>/dev/null
215
fi
216

    
217
# Cleanup configuration files from previous instance
218
/bin/rm -rf /var/etc/*
219

    
220
# Workaround for ipsec symlinks, otherwise it's going to break
221
# strongswan pkg upgrade
222

    
223
if [ -L /usr/local/etc/ipsec.d ]; then
224
	rm -f /usr/local/etc/ipsec.d
225
fi
226
if [ -L /usr/local/etc/ipsec.conf ]; then
227
	rm -f /usr/local/etc/ipsec.conf
228
fi
229
if [ -L /usr/local/etc/strongswan.d ]; then
230
	rm -f /usr/local/etc/strongswan.d
231
fi
232
if [ -L /usr/local/etc/strongswan.conf ]; then
233
	rm -f /usr/local/etc/strongswan.conf
234
fi
235

    
236
echo -n "Creating symlinks..."
237
# Repair symlinks if they are broken
238
if [ -f /etc/newsyslog.conf ]; then
239
	/bin/rm -f /etc/newsyslog.conf
240
fi
241
if [ ! -L /etc/syslog.conf ]; then
242
	/bin/rm -rf /etc/syslog.conf
243
	if [ ! -f /var/etc/syslog.conf ]; then
244
		touch /var/etc/syslog.conf
245
	fi
246
	/bin/ln -s /var/etc/syslog.conf /etc/syslog.conf
247
fi
248

    
249
# Repair symlinks if they are broken
250
if [ ! -L /etc/hosts ]; then
251
	/bin/rm -rf /etc/hosts
252
	/bin/ln -s /var/etc/hosts /etc/hosts
253
fi
254

    
255
if [ ! -L /etc/resolv.conf ]; then
256
	/bin/rm -rf /etc/resolv.conf
257
	/bin/ln -s /var/etc/resolv.conf /etc/resolv.conf
258
fi
259

    
260
if [ ! -L /etc/resolvconf.conf ]; then
261
	/bin/rm -rf /etc/resolvconf.conf
262
	/bin/ln -s /var/etc/resolvconf.conf /etc/resolvconf.conf
263
fi
264

    
265
# Setup compatibility link for packages that
266
# have trouble overriding the PREFIX configure
267
# argument since we build our packages in a
268
# separated PREFIX area
269
# Only create if symlink does not exist.
270
if [ ! -h /tmp/tmp ]; then
271
	/bin/ln -hfs / /tmp/tmp
272
fi
273

    
274
# Make sure our /tmp is 777 + Sticky
275
if [ ! "$PLATFORM" = "cdrom" ] ; then
276
	/bin/rm -rf /tmp/*
277
fi
278
/bin/chmod 1777 /tmp
279

    
280
if [ ! "$PLATFORM" = "cdrom" ] ; then
281
	# Malloc debugging check
282
	if [ -L /etc/malloc.conf ]; then
283
		#ln -s aj /etc/malloc.conf
284
		/bin/rm /etc/malloc.conf
285
	fi
286
fi
287

    
288
if [ ! -L /etc/dhclient.conf ]; then
289
	/bin/rm -rf /etc/dhclient.conf
290
fi
291

    
292
if [ ! -d /var/tmp ]; then
293
	/bin/mkdir -p /var/tmp
294
fi
295

    
296
set -T
297
trap "echo 'Reboot interrupted'; exit 1" 3
298

    
299
# Remove old nameserver resolution files
300
/bin/rm -f /var/etc/nameserver*
301

    
302
echo -n "."
303
DISABLESYSLOGCLOG=$(/usr/local/sbin/read_xml_tag.sh boolean system/disablesyslogclog)
304
ENABLEFIFOLOG=$(/usr/local/sbin/read_xml_tag.sh boolean system/usefifolog)
305
LOG_FILES="system filter dhcpd vpn pptps poes l2tps openvpn portalauth ipsec ppp relayd wireless lighttpd ntpd gateways resolver routing"
306

    
307
DEFAULT_LOG_FILE_SIZE=$(/usr/local/sbin/read_xml_tag.sh string syslog/logfilesize)
308
DEFAULT_LOG_FILE_SIZE=${DEFAULT_LOG_FILE_SIZE:-"511488"}
309

    
310
for logfile in $LOG_FILES; do
311
	if [ "$DISABLESYSLOGCLOG" = "true" ]; then
312
		/usr/bin/touch /var/log/$logfile.log
313
	else
314
		if [ ! -f /var/log/$logfile.log ]; then
315
			if [ "$ENABLEFIFOLOG" = "true" ]; then
316
				# generate fifolog files
317
				/usr/sbin/fifolog_create -s ${DEFAULT_LOG_FILE_SIZE} /var/log/$logfile.log
318
			else
319
				/usr/local/sbin/clog -i -s ${DEFAULT_LOG_FILE_SIZE} /var/log/$logfile.log
320
			fi
321
		fi
322
	fi
323
done
324

    
325
# change permissions on newly created fifolog files.
326
/bin/chmod 0600 /var/log/*.log
327

    
328
echo -n "."
329
DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
330
if [ "$DEVFS" = "0" ]; then
331
	mount_devfs devfs /dev
332
fi
333

    
334
# Create an initial utmp file
335
cd $varrunpath && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
336

    
337
echo -n "."
338
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
339
/etc/rc.d/ldconfig start 2>/dev/null
340

    
341
# Launching kbdmux(4)
342
if [ -f "/dev/kbdmux0" ]; then
343
	echo -n "."
344
	/usr/sbin/kbdcontrol -k /dev/kbdmux0 < /dev/console
345
	[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
346
	[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
347
fi
348

    
349
# Fire up unionfs if mount points exist.
350
if [ -f /dist/uniondirs ]; then
351
	echo -n "."
352
	/etc/rc.d/unionfs start
353
fi
354

    
355
echo "done."
356

    
357
# Recreate capabilities DB
358
/usr/bin/cap_mkdb /etc/login.conf
359

    
360
# Second upgrade stage
361
/usr/local/sbin/${product}-upgrade -y -b 2
362

    
363
# Run the php.ini setup file and populate
364
# /usr/local/etc/php.ini
365
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
366
/usr/local/sbin/php-fpm -c /usr/local/etc/php.ini -y /usr/local/lib/php-fpm.conf -RD 2>&1 >/dev/null
367

    
368
# Launch external configuration loader for supported platforms
369
if [ "$PLATFORM" = "nanobsd" ]; then
370
	/usr/local/sbin/fcgicli -f /etc/ecl.php
371
fi
372

    
373
# Launch external configuration loader for supported platforms
374
if [ "$PLATFORM" = "${product}" ]; then
375
	/usr/local/sbin/fcgicli -f /etc/ecl.php
376
fi
377

    
378
if [ -f /etc/rc.custom_boot_early ]; then
379
	/bin/echo -n "Launching /etc/rc.custom_boot_early...";
380
	/etc/rc.custom_boot_early
381
	echo "Done"
382
fi
383

    
384
export fcgipath=/var/run/php-fpm.socket
385
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
386

    
387
# let the PHP-based configuration subsystem set up the system now
388
echo -n "Launching the init system..."
389
/bin/rm -f /cf/conf/backup/backup.cache
390
/bin/rm -f /root/lighttpd*
391
/usr/bin/touch $varrunpath/booting
392

    
393
if [ "${PLATFORM}" = "nanobsd" ]; then
394
	# XXX This script does need all filesystems rw!!!!
395
	# Put this workaround for now until better ways are found.
396
	/sbin/mount -u -f -r -o sync,noatime /
397
	/sbin/mount -u -f -r -o sync,noatime /cf
398
fi
399

    
400
/etc/rc.bootup
401

    
402
# /etc/rc.bootup unset $g['booting'], and removes file
403
# Be sure the file is removed to not create troubles after
404
if [ -f $varrunpath/booting ]; then
405
	/bin/rm $varrunpath/booting
406
fi
407

    
408
echo -n "Starting CRON... "
409
cd /tmp && /usr/sbin/cron -s 2>/dev/null
410
echo "done."
411

    
412
# Start packages
413
/usr/local/sbin/fcgicli -f /etc/rc.start_packages
414

    
415
/bin/rm -rf /usr/local/pkg/pf/CVS
416

    
417
# Start ping handler every 240 seconds
418
/usr/local/bin/minicron 240 $varrunpath/ping_hosts.pid /usr/local/bin/ping_hosts.sh
419

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

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

    
426
/bin/chmod a+rw /tmp/.
427

    
428
# Check for GEOM mirrors
429
GMIRROR_STATUS=`/sbin/gmirror status`
430
if [ "${GMIRROR_STATUS}" != "" ]; then
431
	# Using a flag file at bootup saves an expensive exec/check on each page load.
432
	/usr/bin/touch /var/run/gmirror_active
433
	# Setup monitoring/notifications
434
	/usr/local/bin/minicron 60 /var/run/gmirror_status_check.pid /usr/local/sbin/gmirror_status_check.php
435
fi
436

    
437
/usr/local/sbin/${product}-upgrade -y -b 3
438

    
439
# Log product version to syslog
440
BUILDTIME=`cat /etc/version.buildtime`
441
ARCH=`uname -m`
442
echo "$product ($PLATFORM) $version $ARCH $BUILDTIME"
443

    
444
echo "Bootup complete"
445

    
446
/usr/local/bin/beep.sh start 2>&1 >/dev/null
447

    
448
# Reset the cache.  read-only requires this.
449
/bin/rm -f /tmp/config.cache
450

    
451
exit 0
(29-29/105)