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
|
FSCK_ACTION_NEEDED=0
|
50
|
/sbin/fsck -p -F
|
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
|
unset MOVE_PKG_DATA
|
100
|
if [ "$PLATFORM" = "${product}" ]; then
|
101
|
# If use MFS var is disabled, move files back to place
|
102
|
if [ "${USE_MFS_TMPVAR}" != "true" -a -f /root/var/db/pkg/local.sqlite ]; then
|
103
|
MOVE_PKG_DATA=1
|
104
|
rm -rf /var/db/pkg 2>/dev/null
|
105
|
rm -rf /var/cache/pkg 2>/dev/null
|
106
|
mv /root/var/db/pkg /var/db
|
107
|
mv /root/var/cache/pkg /var/cache
|
108
|
# If use MFS var is enabled, move files to a safe place
|
109
|
elif [ "${USE_MFS_TMPVAR}" = "true" -a -f /var/db/pkg/local.sqlite ]; then
|
110
|
MOVE_PKG_DATA=1
|
111
|
/bin/mkdir -p /root/var/db /root/var/cache
|
112
|
mv /var/db/pkg /root/var/db
|
113
|
mv /var/cache/pkg /root/var/cache
|
114
|
fi
|
115
|
elif [ "${PLATFORM}" = "nanobsd" ]; then
|
116
|
MOVE_PKG_DATA=1
|
117
|
fi
|
118
|
|
119
|
if [ "${PLATFORM}" = "nanobsd" ] || [ "${USE_MFS_TMPVAR}" = "true" ]; then
|
120
|
/etc/rc.embedded
|
121
|
fi
|
122
|
|
123
|
if [ -n "${MOVE_PKG_DATA}" -o "${USE_MFS_TMPVAR}" = "true" ]; then
|
124
|
/bin/mkdir -p /var/db /var/cache
|
125
|
ln -sf ../../root/var/db/pkg /var/db/pkg
|
126
|
ln -sf ../../root/var/cache/pkg /var/cache/pkg
|
127
|
fi
|
128
|
fi
|
129
|
|
130
|
/bin/rm -f /root/force_fsck
|
131
|
/bin/rm -f /root/TRIM_set
|
132
|
/bin/rm -f /root/TRIM_unset
|
133
|
|
134
|
if [ "${PLATFORM}" = "nanobsd" ]; then
|
135
|
/sbin/kldstat -qm zfs
|
136
|
if [ $? -eq 0 ]; then
|
137
|
/sbin/kldunload zfs
|
138
|
fi
|
139
|
elif [ "$PLATFORM" = "${product}" ]; then
|
140
|
# Handle ZFS read-only case
|
141
|
/sbin/kldstat -qm zfs
|
142
|
if [ $? -eq 0 ]; then
|
143
|
ZFSFSAVAILABLE=$(/sbin/zfs mount 2>/dev/null | wc -l)
|
144
|
if [ $ZFSFSAVAILABLE -eq 0 ]; then
|
145
|
/sbin/kldunload zfs
|
146
|
elif [ -f /usr/bin/grep ]; then
|
147
|
ZFSROOT=`/sbin/zfs mount | /usr/bin/grep ' /$' | /usr/bin/cut -d ' ' -f 1`
|
148
|
if [ "$ZFSROOT" != "" ]; then
|
149
|
/sbin/zfs set readonly=off $ZFSROOT
|
150
|
fi
|
151
|
fi
|
152
|
fi
|
153
|
elif [ "${PLATFORM}" = "cdrom" ]; then
|
154
|
/etc/rc.cdrom
|
155
|
fi
|
156
|
|
157
|
# Disable APM on ATA drives. Leaving this on will kill drives long-term, especially laptop drives, by generating excessive Load Cycles.
|
158
|
if [ -f /etc/rc.disable_hdd_apm ]; then
|
159
|
/etc/rc.disable_hdd_apm
|
160
|
fi
|
161
|
|
162
|
# Eject CD devices on 3G modems
|
163
|
MANUFACTURER="huawei|zte"
|
164
|
CDDEVICE=`dmesg |egrep -ie "($MANUFACTURER)" | awk -F: '/cd/ {print $1}'`
|
165
|
if [ "$CDDEVICE" != "" ]; then
|
166
|
cdcontrol -f /dev/"$CDDEVICE" eject
|
167
|
fi
|
168
|
|
169
|
# Use php -n here because we are not ready to load extensions yet
|
170
|
varrunpath=$(/usr/local/bin/php -n /usr/local/sbin/read_global_var varrun_path "/var/run")
|
171
|
|
172
|
if [ "$PLATFORM" = "${product}" ] && [ "${USE_MFS_TMPVAR}" != "true" ]; then
|
173
|
/sbin/mdmfs -S -M -s 4m md $varrunpath
|
174
|
fi
|
175
|
|
176
|
# Use php -n here because we are not ready to load extensions yet
|
177
|
hideplatform=$(/usr/local/bin/php -n /usr/local/sbin/read_global_var hideplatform)
|
178
|
if [ "$hideplatform" = "true" ]; then
|
179
|
platformbanner="" # hide the platform
|
180
|
else
|
181
|
platformbanner=" on the '${PLATFORM}' platform"
|
182
|
fi
|
183
|
|
184
|
echo
|
185
|
cat /etc/ascii-art/pfsense-logo-small.txt
|
186
|
echo
|
187
|
echo
|
188
|
echo "Welcome to ${product} ${version}${platformbanner}..."
|
189
|
echo
|
190
|
|
191
|
/sbin/conscontrol mute off >/dev/null
|
192
|
|
193
|
if [ "$PLATFORM" = "${product}" ]; then
|
194
|
SWAPDEVICE=`/bin/cat /etc/fstab | /usr/bin/grep swap | /usr/bin/cut -f1`
|
195
|
/sbin/swapon -a 2>/dev/null >/dev/null
|
196
|
/etc/rc.savecore
|
197
|
fi
|
198
|
|
199
|
if [ "$PLATFORM" = "cdrom" ] ; then
|
200
|
echo -n "Mounting unionfs directories..."
|
201
|
/bin/mkdir /tmp/unionfs
|
202
|
/bin/mkdir /tmp/unionfs/usr
|
203
|
/bin/mkdir /tmp/unionfs/root
|
204
|
/bin/mkdir /tmp/unionfs/sbin
|
205
|
/bin/mkdir /tmp/unionfs/bin
|
206
|
/bin/mkdir /tmp/unionfs/boot
|
207
|
/bin/mkdir /tmp/unionfs/confdefault
|
208
|
/sbin/mount_unionfs /tmp/unionfs/usr /usr/
|
209
|
/sbin/mount_unionfs /tmp/unionfs/root /root/
|
210
|
/sbin/mount_unionfs /tmp/unionfs/bin /bin/
|
211
|
/sbin/mount_unionfs /tmp/unionfs/sbin /sbin/
|
212
|
/sbin/mount_unionfs /tmp/unionfs/boot /boot/
|
213
|
/sbin/mount_unionfs /tmp/unionfs/confdefault /conf.default/
|
214
|
echo "done."
|
215
|
fi
|
216
|
|
217
|
# make some directories in /var
|
218
|
/bin/mkdir -p $varrunpath /var/log /var/etc /var/db/entropy /var/db/rrd /var/at/jobs/ /var/empty 2>/dev/null
|
219
|
/bin/rm -rf $varrunpath/*
|
220
|
if [ "$PLATFORM" != "${product}" ]; then
|
221
|
/bin/rm /var/log/* 2>/dev/null
|
222
|
fi
|
223
|
|
224
|
# Cleanup configuration files from previous instance
|
225
|
/bin/rm -rf /var/etc/*
|
226
|
|
227
|
# Workaround for ipsec symlinks, otherwise it's going to break
|
228
|
# strongswan pkg upgrade
|
229
|
|
230
|
if [ -L /usr/local/etc/ipsec.d ]; then
|
231
|
rm -f /usr/local/etc/ipsec.d
|
232
|
fi
|
233
|
if [ -L /usr/local/etc/ipsec.conf ]; then
|
234
|
rm -f /usr/local/etc/ipsec.conf
|
235
|
fi
|
236
|
if [ -L /usr/local/etc/strongswan.d ]; then
|
237
|
rm -f /usr/local/etc/strongswan.d
|
238
|
fi
|
239
|
if [ -L /usr/local/etc/strongswan.conf ]; then
|
240
|
rm -f /usr/local/etc/strongswan.conf
|
241
|
fi
|
242
|
|
243
|
echo -n "Creating symlinks..."
|
244
|
# Repair symlinks if they are broken
|
245
|
if [ -f /etc/newsyslog.conf ]; then
|
246
|
/bin/rm -f /etc/newsyslog.conf
|
247
|
fi
|
248
|
if [ ! -L /etc/syslog.conf ]; then
|
249
|
/bin/rm -rf /etc/syslog.conf
|
250
|
if [ ! -f /var/etc/syslog.conf ]; then
|
251
|
touch /var/etc/syslog.conf
|
252
|
fi
|
253
|
/bin/ln -s /var/etc/syslog.conf /etc/syslog.conf
|
254
|
fi
|
255
|
|
256
|
# Repair symlinks if they are broken
|
257
|
if [ ! -L /etc/hosts ]; then
|
258
|
/bin/rm -rf /etc/hosts
|
259
|
/bin/ln -s /var/etc/hosts /etc/hosts
|
260
|
fi
|
261
|
|
262
|
if [ ! -L /etc/resolv.conf ]; then
|
263
|
/bin/rm -rf /etc/resolv.conf
|
264
|
/bin/ln -s /var/etc/resolv.conf /etc/resolv.conf
|
265
|
fi
|
266
|
|
267
|
if [ ! -L /etc/resolvconf.conf ]; then
|
268
|
/bin/rm -rf /etc/resolvconf.conf
|
269
|
/bin/ln -s /var/etc/resolvconf.conf /etc/resolvconf.conf
|
270
|
fi
|
271
|
|
272
|
# Setup compatibility link for packages that
|
273
|
# have trouble overriding the PREFIX configure
|
274
|
# argument since we build our packages in a
|
275
|
# separated PREFIX area
|
276
|
# Only create if symlink does not exist.
|
277
|
if [ ! -h /tmp/tmp ]; then
|
278
|
/bin/ln -hfs / /tmp/tmp
|
279
|
fi
|
280
|
|
281
|
# Make sure our /tmp is 777 + Sticky
|
282
|
if [ ! "$PLATFORM" = "cdrom" ] ; then
|
283
|
/bin/rm -rf /tmp/*
|
284
|
fi
|
285
|
/bin/chmod 1777 /tmp
|
286
|
|
287
|
if [ ! "$PLATFORM" = "cdrom" ] ; then
|
288
|
# Malloc debugging check
|
289
|
if [ -L /etc/malloc.conf ]; then
|
290
|
#ln -s aj /etc/malloc.conf
|
291
|
/bin/rm /etc/malloc.conf
|
292
|
fi
|
293
|
fi
|
294
|
|
295
|
if [ ! -L /etc/dhclient.conf ]; then
|
296
|
/bin/rm -rf /etc/dhclient.conf
|
297
|
fi
|
298
|
|
299
|
if [ ! -d /var/tmp ]; then
|
300
|
/bin/mkdir -p /var/tmp
|
301
|
fi
|
302
|
|
303
|
set -T
|
304
|
trap "echo 'Reboot interrupted'; exit 1" 3
|
305
|
|
306
|
# Remove old nameserver resolution files
|
307
|
/bin/rm -f /var/etc/nameserver*
|
308
|
|
309
|
echo -n "."
|
310
|
DISABLESYSLOGCLOG=$(/usr/local/sbin/read_xml_tag.sh boolean system/disablesyslogclog)
|
311
|
LOG_FILES="system filter dhcpd vpn pptps poes l2tps openvpn portalauth ipsec ppp relayd wireless nginx ntpd gateways resolver routing"
|
312
|
|
313
|
DEFAULT_LOG_FILE_SIZE=$(/usr/local/sbin/read_xml_tag.sh string syslog/logfilesize)
|
314
|
DEFAULT_LOG_FILE_SIZE=${DEFAULT_LOG_FILE_SIZE:-"511488"}
|
315
|
|
316
|
for logfile in $LOG_FILES; do
|
317
|
if [ "$DISABLESYSLOGCLOG" = "true" ]; then
|
318
|
/usr/bin/touch /var/log/$logfile.log
|
319
|
else
|
320
|
if [ ! -f /var/log/$logfile.log ]; then
|
321
|
/usr/local/sbin/clog -i -s ${DEFAULT_LOG_FILE_SIZE} /var/log/$logfile.log
|
322
|
fi
|
323
|
fi
|
324
|
done
|
325
|
|
326
|
# change permissions on newly created log files.
|
327
|
/bin/chmod 0600 /var/log/*.log
|
328
|
|
329
|
echo -n "."
|
330
|
DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
|
331
|
if [ "$DEVFS" = "0" ]; then
|
332
|
mount_devfs devfs /dev
|
333
|
fi
|
334
|
|
335
|
# Create an initial utmp file
|
336
|
cd $varrunpath && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
|
337
|
|
338
|
echo -n "."
|
339
|
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
|
340
|
/etc/rc.d/ldconfig start 2>/dev/null
|
341
|
|
342
|
# Launching kbdmux(4)
|
343
|
if [ -f "/dev/kbdmux0" ]; then
|
344
|
echo -n "."
|
345
|
/usr/sbin/kbdcontrol -k /dev/kbdmux0 < /dev/console
|
346
|
[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
|
347
|
[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
|
348
|
fi
|
349
|
|
350
|
# Fire up unionfs if mount points exist.
|
351
|
if [ -f /dist/uniondirs ]; then
|
352
|
echo -n "."
|
353
|
/etc/rc.d/unionfs start
|
354
|
fi
|
355
|
|
356
|
echo "done."
|
357
|
|
358
|
# Recreate capabilities DB
|
359
|
/usr/bin/cap_mkdb /etc/login.conf
|
360
|
|
361
|
# Second upgrade stage
|
362
|
/usr/local/sbin/${product}-upgrade -y -b 2
|
363
|
|
364
|
# Run the php.ini setup file and populate
|
365
|
# /usr/local/etc/php.ini
|
366
|
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
|
367
|
/usr/local/sbin/php-fpm -c /usr/local/etc/php.ini -y /usr/local/lib/php-fpm.conf -RD 2>&1 >/dev/null
|
368
|
|
369
|
# Launch external configuration loader for supported platforms
|
370
|
if [ "$PLATFORM" = "nanobsd" ]; then
|
371
|
/usr/local/sbin/fcgicli -f /etc/ecl.php
|
372
|
fi
|
373
|
|
374
|
# Launch external configuration loader for supported platforms
|
375
|
if [ "$PLATFORM" = "${product}" ]; then
|
376
|
/usr/local/sbin/fcgicli -f /etc/ecl.php
|
377
|
fi
|
378
|
|
379
|
if [ -f /etc/rc.custom_boot_early ]; then
|
380
|
/bin/echo -n "Launching /etc/rc.custom_boot_early...";
|
381
|
/etc/rc.custom_boot_early
|
382
|
echo "Done"
|
383
|
fi
|
384
|
|
385
|
export fcgipath=/var/run/php-fpm.socket
|
386
|
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
|
387
|
|
388
|
# let the PHP-based configuration subsystem set up the system now
|
389
|
echo -n "Launching the init system..."
|
390
|
/bin/rm -f /cf/conf/backup/backup.cache
|
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
|