Project

General

Profile

Download (15.1 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 Rubicon Communications, LLC (Netgate)
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 -f /root/var/db/pkg /var/db
164
			mv -f /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
			rm -rf /root/var/db/pkg 2>/dev/null
169
			rm -rf /root/var/cache/pkg 2>/dev/null
170
			/bin/mkdir -p /root/var/db /root/var/cache
171
			mv -f /var/db/pkg /root/var/db
172
			mv -f /var/cache/pkg /root/var/cache
173
		fi
174
	elif [ "${PLATFORM}" = "nanobsd" ]; then
175
		MOVE_PKG_DATA=1
176
	fi
177

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

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

    
189
/bin/rm -f /root/force_fsck
190
/bin/rm -f /root/TRIM_set
191
/bin/rm -f /root/TRIM_unset
192

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

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

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

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

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

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

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

    
250
/sbin/conscontrol mute off >/dev/null
251

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
362
set -T
363
trap "echo 'Reboot interrupted'; exit 1" 3
364

    
365
# Remove old nameserver resolution files
366
/bin/rm -f /var/etc/nameserver*
367

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

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

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

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

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

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

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

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

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

    
415
echo "done."
416

    
417
# Recreate capabilities DB
418
/usr/bin/cap_mkdb /etc/login.conf
419

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

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

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

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

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

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

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

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

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

    
465
/etc/rc.bootup
466

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

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

    
477
# Start packages
478
/usr/local/sbin/fcgicli -f /etc/rc.start_packages
479

    
480
/bin/rm -rf /usr/local/pkg/pf/CVS
481

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

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

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

    
491
/bin/chmod a+rw /tmp/.
492

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

    
502
/usr/local/sbin/${product}-upgrade -y -b 3
503

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

    
509
echo "Bootup complete"
510

    
511
/usr/local/bin/beep.sh start 2>&1 >/dev/null
512

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

    
516
exit 0
(23-23/94)