Project

General

Profile

Download (15 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/bin/sh
2
#
3
# rc
4
#
5
# part of pfSense (https://www.pfsense.org)
6
# Copyright (c) 2004-2016 Electric Sheep Fencing, LLC
7
# All rights reserved.
8
#
9
# originally based on m0n0wall (http://neon1.net/m0n0wall)
10
# Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
# All rights reserved.
12
#
13
# Redistribution and use in source and binary forms, with or without
14
# modification, are permitted provided that the following conditions are met:
15
#
16
# 1. Redistributions of source code must retain the above copyright notice,
17
#    this list of conditions and the following disclaimer.
18
#
19
# 2. Redistributions in binary form must reproduce the above copyright
20
#    notice, this list of conditions and the following disclaimer in
21
#    the documentation and/or other materials provided with the
22
#    distribution.
23
#
24
# 3. All advertising materials mentioning features or use of this software
25
#    must display the following acknowledgment:
26
#    "This product includes software developed by the pfSense Project
27
#    for use in the pfSense® software distribution. (http://www.pfsense.org/).
28
#
29
# 4. The names "pfSense" and "pfSense Project" must not be used to
30
#    endorse or promote products derived from this software without
31
#    prior written permission. For written permission, please contact
32
#    coreteam@pfsense.org.
33
#
34
# 5. Products derived from this software may not be called "pfSense"
35
#    nor may "pfSense" appear in their names without prior written
36
#    permission of the Electric Sheep Fencing, LLC.
37
#
38
# 6. Redistributions of any form whatsoever must retain the following
39
#    acknowledgment:
40
#
41
# "This product includes software developed by the pfSense Project
42
# for use in the pfSense software distribution (http://www.pfsense.org/).
43
#
44
# THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
45
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
48
# ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55
# OF THE POSSIBILITY OF SUCH DAMAGE.
56

    
57
#/bin/stty status '^T'
58
#/bin/stty susp '^-' intr '^-' quit '^-'
59

    
60
#trap : 2
61
#trap : 3
62

    
63
HOME=/
64
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
65
export HOME PATH
66

    
67
# Set our operating platform
68
PLATFORM=`/bin/cat /etc/platform`
69

    
70
# Set our current version
71
version=`/bin/cat /etc/version`
72

    
73
# Version patch
74
version_patch="0"
75
if [ -f /etc/version.patch ]; then
76
	version_patch=`/bin/cat /etc/version.patch`
77
fi
78

    
79
if [ "${version_patch}" = "0" ]; then
80
	version_patch=""
81
else
82
	version_patch=" (Patch ${version_patch})"
83
fi
84

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

    
89
# Setup dumpdev/ddb/savecore"
90
echo "Configuring crash dumps..."
91
if [ "$PLATFORM" = "${product}" ]; then
92
	/etc/rc.dumpon
93
fi
94

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

    
100
if [ -e /root/force_fsck ]; then
101
	echo "Forcing filesystem(s) check..."
102
	/sbin/fsck -y -F -t ufs
103
fi
104

    
105
if [ "${PLATFORM}" != "cdrom" ]; then
106
	FSCK_ACTION_NEEDED=0
107
	/sbin/fsck -p -F
108
	case $? in
109
	0)
110
		echo "Filesystems are clean, continuing..."
111
		echo "Mounting filesystems..."
112
		;;
113
	8)
114
		echo "Preen mode recommended running a check that will be performed now."
115
		FSCK_ACTION_NEEDED=1
116
		;;
117
	*)
118
		echo "Stopping boot is recommended because filesystem manual action is needed, nevertheless automated repair of the filesystem will be attempted."
119
		FSCK_ACTION_NEEDED=1
120
		;;
121
	esac
122

    
123
	if [ ${FSCK_ACTION_NEEDED} = 1 ]; then
124
		echo "WARNING: Trying to recover filesystem from inconsistency..."
125
		/sbin/fsck -yF
126
	fi
127

    
128
	/sbin/mount -a 2>/dev/null
129
	mount_rc=$?
130
	attempts=0
131
	while [ ${mount_rc} -ne 0 -a ${attempts} -lt 3 ]; do
132
		/sbin/fsck -yF
133
		/sbin/mount -a 2>/dev/null
134
		mount_rc=$?
135
		attempts=$((attempts+1))
136
	done
137

    
138
	if [ "${PLATFORM}" = "nanobsd" ]; then
139
		# XXX This script does need all filesystems rw!!!!
140
		# Put this workaround for now until better ways are found.
141
		/sbin/mount -u -w -o sync,noatime /
142
		/sbin/mount -u -w -o sync,noatime /cf
143
	fi
144

    
145
	# If /conf is a directory, convert it to a symlink to /cf/conf
146
	if [ -d "/conf" ]; then
147
		# If item is not a symlink then rm and recreate
148
		CONFPOINTSTO=`readlink /conf`
149
		if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then
150
			/bin/rm -rf /conf
151
			/bin/ln -s /cf/conf /conf
152
		fi
153
	fi
154

    
155
	USE_MFS_TMPVAR=$(/usr/local/sbin/read_xml_tag.sh boolean system/use_mfs_tmpvar)
156
	unset MOVE_PKG_DATA
157
	if [ "$PLATFORM" = "${product}" ]; then
158
		# If use MFS var is disabled, move files back to place
159
		if [ "${USE_MFS_TMPVAR}" != "true" -a -f /root/var/db/pkg/local.sqlite ]; then
160
			MOVE_PKG_DATA=1
161
			rm -rf /var/db/pkg 2>/dev/null
162
			rm -rf /var/cache/pkg 2>/dev/null
163
			mv /root/var/db/pkg /var/db
164
			mv /root/var/cache/pkg /var/cache
165
		# If use MFS var is enabled, move files to a safe place
166
		elif [ "${USE_MFS_TMPVAR}" = "true" -a -f /var/db/pkg/local.sqlite ]; then
167
			MOVE_PKG_DATA=1
168
			/bin/mkdir -p /root/var/db /root/var/cache
169
			mv /var/db/pkg /root/var/db
170
			mv /var/cache/pkg /root/var/cache
171
		fi
172
	elif [ "${PLATFORM}" = "nanobsd" ]; then
173
		MOVE_PKG_DATA=1
174
	fi
175

    
176
	if [ "${PLATFORM}" = "nanobsd" ] || [ "${USE_MFS_TMPVAR}" = "true" ]; then
177
		/etc/rc.embedded
178
	fi
179

    
180
	if [ -n "${MOVE_PKG_DATA}" -o "${USE_MFS_TMPVAR}" = "true" ]; then
181
		/bin/mkdir -p /var/db /var/cache
182
		ln -sf ../../root/var/db/pkg /var/db/pkg
183
		ln -sf ../../root/var/cache/pkg /var/cache/pkg
184
	fi
185
fi
186

    
187
/bin/rm -f /root/force_fsck
188
/bin/rm -f /root/TRIM_set
189
/bin/rm -f /root/TRIM_unset
190

    
191
if [ "${PLATFORM}" = "nanobsd" ]; then
192
	/sbin/kldstat -qm zfs
193
	if [ $? -eq 0 ]; then
194
		/sbin/kldunload zfs
195
	fi
196
elif [ "$PLATFORM" = "${product}" ]; then
197
	# Handle ZFS read-only case
198
	/sbin/kldstat -qm zfs
199
	if [ $? -eq 0 ]; then
200
		ZFSFSAVAILABLE=$(/sbin/zfs mount 2>/dev/null | wc -l)
201
		if [ $ZFSFSAVAILABLE -eq 0 ]; then
202
			/sbin/kldunload zfs
203
		elif [ -f /usr/bin/grep ]; then
204
			ZFSROOT=`/sbin/zfs mount | /usr/bin/grep ' /$' | /usr/bin/cut -d ' ' -f 1`
205
			if [ "$ZFSROOT" != "" ]; then
206
				/sbin/zfs set readonly=off $ZFSROOT
207
			fi
208
		fi
209
	fi
210
elif [ "${PLATFORM}" = "cdrom" ]; then
211
	/etc/rc.cdrom
212
fi
213

    
214
# Disable APM on ATA drives. Leaving this on will kill drives long-term, especially laptop drives, by generating excessive Load Cycles.
215
if [ -f /etc/rc.disable_hdd_apm ]; then
216
	/etc/rc.disable_hdd_apm
217
fi
218

    
219
# Eject CD devices on 3G modems
220
MANUFACTURER="huawei|zte"
221
CDDEVICE=`dmesg |egrep -ie "($MANUFACTURER)" | awk -F: '/cd/ {print $1}'`
222
if [ "$CDDEVICE" != "" ]; then
223
	cdcontrol -f /dev/"$CDDEVICE" eject
224
fi
225

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

    
229
if [ "$PLATFORM" = "${product}" ] && [ "${USE_MFS_TMPVAR}" != "true" ]; then
230
	/sbin/mdmfs -S -M -s 4m md $varrunpath
231
fi
232

    
233
# Use php -n here because we are not ready to load extensions yet
234
hideplatform=$(/usr/local/bin/php -n /usr/local/sbin/read_global_var hideplatform)
235
if [ "$hideplatform" = "true" ]; then
236
	platformbanner="" # hide the platform
237
else
238
	platformbanner=" on the '${PLATFORM}' platform"
239
fi
240

    
241
echo
242
cat /etc/ascii-art/pfsense-logo-small.txt
243
echo
244
echo
245
echo "Welcome to ${product} ${version}${version_patch}${platformbanner}..."
246
echo
247

    
248
/sbin/conscontrol mute off >/dev/null
249

    
250
if [ "$PLATFORM" = "${product}" ]; then
251
	SWAPDEVICE=`/bin/cat /etc/fstab | /usr/bin/grep swap | /usr/bin/cut -f1`
252
	/sbin/swapon -a 2>/dev/null >/dev/null
253
	/etc/rc.savecore
254
fi
255

    
256
if [ "$PLATFORM" = "cdrom" ] ; then
257
	echo -n "Mounting unionfs directories..."
258
	/bin/mkdir /tmp/unionfs
259
	/bin/mkdir /tmp/unionfs/usr
260
	/bin/mkdir /tmp/unionfs/root
261
	/bin/mkdir /tmp/unionfs/sbin
262
	/bin/mkdir /tmp/unionfs/bin
263
	/bin/mkdir /tmp/unionfs/boot
264
	/bin/mkdir /tmp/unionfs/confdefault
265
	/sbin/mount_unionfs /tmp/unionfs/usr /usr/
266
	/sbin/mount_unionfs /tmp/unionfs/root /root/
267
	/sbin/mount_unionfs /tmp/unionfs/bin /bin/
268
	/sbin/mount_unionfs /tmp/unionfs/sbin /sbin/
269
	/sbin/mount_unionfs /tmp/unionfs/boot /boot/
270
	/sbin/mount_unionfs /tmp/unionfs/confdefault /conf.default/
271
	echo "done."
272
fi
273

    
274
# make some directories in /var
275
/bin/mkdir -p $varrunpath /var/log /var/etc /var/db/entropy /var/db/rrd /var/at/jobs/ /var/empty 2>/dev/null
276
/bin/rm -rf $varrunpath/*
277
if [ "$PLATFORM" != "${product}" ]; then
278
	/bin/rm /var/log/* 2>/dev/null
279
fi
280

    
281
# Cleanup configuration files from previous instance
282
/bin/rm -rf /var/etc/*
283

    
284
# Workaround for ipsec symlinks, otherwise it's going to break
285
# strongswan pkg upgrade
286

    
287
if [ -L /usr/local/etc/ipsec.d ]; then
288
	rm -f /usr/local/etc/ipsec.d
289
fi
290
if [ -L /usr/local/etc/ipsec.conf ]; then
291
	rm -f /usr/local/etc/ipsec.conf
292
fi
293
if [ -L /usr/local/etc/strongswan.d ]; then
294
	rm -f /usr/local/etc/strongswan.d
295
fi
296
if [ -L /usr/local/etc/strongswan.conf ]; then
297
	rm -f /usr/local/etc/strongswan.conf
298
fi
299

    
300
echo -n "Creating symlinks..."
301
# Repair symlinks if they are broken
302
if [ -f /etc/newsyslog.conf ]; then
303
	/bin/rm -f /etc/newsyslog.conf
304
fi
305
if [ ! -L /etc/syslog.conf ]; then
306
	/bin/rm -rf /etc/syslog.conf
307
	if [ ! -f /var/etc/syslog.conf ]; then
308
		touch /var/etc/syslog.conf
309
	fi
310
	/bin/ln -s /var/etc/syslog.conf /etc/syslog.conf
311
fi
312

    
313
# Repair symlinks if they are broken
314
if [ ! -L /etc/hosts ]; then
315
	/bin/rm -rf /etc/hosts
316
	/bin/ln -s /var/etc/hosts /etc/hosts
317
fi
318

    
319
if [ ! -L /etc/resolv.conf ]; then
320
	/bin/rm -rf /etc/resolv.conf
321
	/bin/ln -s /var/etc/resolv.conf /etc/resolv.conf
322
fi
323

    
324
if [ ! -L /etc/resolvconf.conf ]; then
325
	/bin/rm -rf /etc/resolvconf.conf
326
	/bin/ln -s /var/etc/resolvconf.conf /etc/resolvconf.conf
327
fi
328

    
329
# Setup compatibility link for packages that
330
# have trouble overriding the PREFIX configure
331
# argument since we build our packages in a
332
# separated PREFIX area
333
# Only create if symlink does not exist.
334
if [ ! -h /tmp/tmp ]; then
335
	/bin/ln -hfs / /tmp/tmp
336
fi
337

    
338
# Make sure our /tmp is 777 + Sticky
339
if [ ! "$PLATFORM" = "cdrom" ] ; then
340
	/bin/rm -rf /tmp/*
341
fi
342
/bin/chmod 1777 /tmp
343

    
344
if [ ! "$PLATFORM" = "cdrom" ] ; then
345
	# Malloc debugging check
346
	if [ -L /etc/malloc.conf ]; then
347
		#ln -s aj /etc/malloc.conf
348
		/bin/rm /etc/malloc.conf
349
	fi
350
fi
351

    
352
if [ ! -L /etc/dhclient.conf ]; then
353
	/bin/rm -rf /etc/dhclient.conf
354
fi
355

    
356
if [ ! -d /var/tmp ]; then
357
	/bin/mkdir -p /var/tmp
358
fi
359

    
360
set -T
361
trap "echo 'Reboot interrupted'; exit 1" 3
362

    
363
# Remove old nameserver resolution files
364
/bin/rm -f /var/etc/nameserver*
365

    
366
echo -n "."
367
DISABLESYSLOGCLOG=$(/usr/local/sbin/read_xml_tag.sh boolean system/disablesyslogclog)
368
LOG_FILES="system filter dhcpd vpn pptps poes l2tps openvpn portalauth ipsec ppp relayd wireless nginx ntpd gateways resolver routing"
369

    
370
DEFAULT_LOG_FILE_SIZE=$(/usr/local/sbin/read_xml_tag.sh string syslog/logfilesize)
371
DEFAULT_LOG_FILE_SIZE=${DEFAULT_LOG_FILE_SIZE:-"511488"}
372

    
373
for logfile in $LOG_FILES; do
374
	if [ "$DISABLESYSLOGCLOG" = "true" ]; then
375
		/usr/bin/touch /var/log/$logfile.log
376
	else
377
		if [ ! -f /var/log/$logfile.log ]; then
378
			/usr/local/sbin/clog -i -s ${DEFAULT_LOG_FILE_SIZE} /var/log/$logfile.log
379
		fi
380
	fi
381
done
382

    
383
# change permissions on newly created log files.
384
/bin/chmod 0600 /var/log/*.log
385

    
386
echo -n "."
387
DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
388
if [ "$DEVFS" = "0" ]; then
389
	mount_devfs devfs /dev
390
fi
391

    
392
# Create an initial utmp file
393
cd $varrunpath && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
394

    
395
echo -n "."
396
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
397
/etc/rc.d/ldconfig start 2>/dev/null
398

    
399
# Launching kbdmux(4)
400
if [ -f "/dev/kbdmux0" ]; then
401
	echo -n "."
402
	/usr/sbin/kbdcontrol -k /dev/kbdmux0 < /dev/console
403
	[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
404
	[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
405
fi
406

    
407
# Fire up unionfs if mount points exist.
408
if [ -f /dist/uniondirs ]; then
409
	echo -n "."
410
	/etc/rc.d/unionfs start
411
fi
412

    
413
echo "done."
414

    
415
# Recreate capabilities DB
416
/usr/bin/cap_mkdb /etc/login.conf
417

    
418
# Second upgrade stage
419
/usr/local/sbin/${product}-upgrade -y -b 2
420

    
421
# Run the php.ini setup file and populate
422
# /usr/local/etc/php.ini
423
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
424
/usr/local/sbin/php-fpm -c /usr/local/etc/php.ini -y /usr/local/lib/php-fpm.conf -RD 2>&1 >/dev/null
425

    
426
# Launch external configuration loader for supported platforms
427
if [ "$PLATFORM" = "nanobsd" ]; then
428
	/usr/local/sbin/fcgicli -f /etc/ecl.php
429
fi
430

    
431
# Launch external configuration loader for supported platforms
432
if [ "$PLATFORM" = "${product}" ]; then
433
	/usr/local/sbin/fcgicli -f /etc/ecl.php
434
fi
435

    
436
if [ -f /etc/rc.custom_boot_early ]; then
437
	/bin/echo -n "Launching /etc/rc.custom_boot_early...";
438
	/etc/rc.custom_boot_early
439
	echo "Done"
440
fi
441

    
442
export fcgipath=/var/run/php-fpm.socket
443
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
444

    
445
# let the PHP-based configuration subsystem set up the system now
446
echo -n "Launching the init system..."
447
/bin/rm -f /cf/conf/backup/backup.cache
448
/usr/bin/touch $varrunpath/booting
449

    
450
if [ "${PLATFORM}" = "nanobsd" ]; then
451
	# XXX This script does need all filesystems rw!!!!
452
	# Put this workaround for now until better ways are found.
453
	/sbin/mount -u -f -r -o sync,noatime /
454
	/sbin/mount -u -f -r -o sync,noatime /cf
455
fi
456

    
457
# Copy custom logo over if it's present
458
if [ -d /usr/local/share/${product}/custom_logos ]; then
459
	cp -f /usr/local/share/${product}/custom_logos/*png \
460
		/usr/local/www
461
fi
462

    
463
/etc/rc.bootup
464

    
465
# /etc/rc.bootup unset $g['booting'], and removes file
466
# Be sure the file is removed to not create troubles after
467
if [ -f $varrunpath/booting ]; then
468
	/bin/rm $varrunpath/booting
469
fi
470

    
471
echo -n "Starting CRON... "
472
cd /tmp && /usr/sbin/cron -s 2>/dev/null
473
echo "done."
474

    
475
# Start packages
476
/usr/local/sbin/fcgicli -f /etc/rc.start_packages
477

    
478
/bin/rm -rf /usr/local/pkg/pf/CVS
479

    
480
# Start ping handler every 240 seconds
481
/usr/local/bin/minicron 240 $varrunpath/ping_hosts.pid /usr/local/bin/ping_hosts.sh
482

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

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

    
489
/bin/chmod a+rw /tmp/.
490

    
491
# Check for GEOM mirrors
492
GMIRROR_STATUS=`/sbin/gmirror status`
493
if [ "${GMIRROR_STATUS}" != "" ]; then
494
	# Using a flag file at bootup saves an expensive exec/check on each page load.
495
	/usr/bin/touch /var/run/gmirror_active
496
	# Setup monitoring/notifications
497
	/usr/local/bin/minicron 60 /var/run/gmirror_status_check.pid /usr/local/sbin/gmirror_status_check.php
498
fi
499

    
500
/usr/local/sbin/${product}-upgrade -y -b 3
501

    
502
# Log product version to syslog
503
BUILDTIME=`cat /etc/version.buildtime`
504
ARCH=`uname -m`
505
echo "$product ($PLATFORM) ${version}${version_patch} $ARCH $BUILDTIME"
506

    
507
echo "Bootup complete"
508

    
509
/usr/local/bin/beep.sh start 2>&1 >/dev/null
510

    
511
# Reset the cache.  read-only requires this.
512
/bin/rm -f /tmp/config.cache
513

    
514
exit 0
(23-23/94)