1
|
#!/bin/sh
|
2
|
#
|
3
|
# pfSense-rc
|
4
|
#
|
5
|
# part of pfSense (https://www.pfsense.org)
|
6
|
# Copyright (c) 2004-2013 BSD Perimeter
|
7
|
# Copyright (c) 2013-2016 Electric Sheep Fencing
|
8
|
# Copyright (c) 2014-2025 Rubicon Communications, LLC (Netgate)
|
9
|
# All rights reserved.
|
10
|
#
|
11
|
# originally based on m0n0wall (http://neon1.net/m0n0wall)
|
12
|
# Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
13
|
# All rights reserved.
|
14
|
#
|
15
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
16
|
# you may not use this file except in compliance with the License.
|
17
|
# You may obtain a copy of the License at
|
18
|
#
|
19
|
# http://www.apache.org/licenses/LICENSE-2.0
|
20
|
#
|
21
|
# Unless required by applicable law or agreed to in writing, software
|
22
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
23
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
24
|
# See the License for the specific language governing permissions and
|
25
|
# limitations under the License.
|
26
|
|
27
|
#/bin/stty status '^T'
|
28
|
#/bin/stty susp '^-' intr '^-' quit '^-'
|
29
|
|
30
|
#trap : 2
|
31
|
#trap : 3
|
32
|
|
33
|
HOME=/
|
34
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
|
35
|
export HOME PATH
|
36
|
|
37
|
get_version ()
|
38
|
{
|
39
|
# Set our current version
|
40
|
version=`/bin/cat /etc/version`
|
41
|
|
42
|
# Version patch
|
43
|
version_patch="0"
|
44
|
if [ -f /etc/version.patch ]; then
|
45
|
version_patch=`/bin/cat /etc/version.patch`
|
46
|
fi
|
47
|
|
48
|
if [ "${version_patch}" = "0" ]; then
|
49
|
version_patch=""
|
50
|
else
|
51
|
version_patch=" (Patch ${version_patch})"
|
52
|
fi
|
53
|
}
|
54
|
|
55
|
get_version
|
56
|
|
57
|
# Read product_name from $g, defaults to pfSense
|
58
|
# Use php -n here because we are not ready to load extensions yet
|
59
|
product_name=$(/usr/local/bin/php -n /usr/local/sbin/read_global_var product_name pfSense)
|
60
|
product_label=$(/usr/local/bin/php -n /usr/local/sbin/read_global_var product_label pfSense)
|
61
|
|
62
|
# Setup dumpdev/ddb/savecore"
|
63
|
echo "Configuring crash dumps..."
|
64
|
/etc/rc.dumpon
|
65
|
|
66
|
unset SWAP_FSTAB_ADD
|
67
|
if [ -e /root/force_growfs ]; then
|
68
|
if /sbin/gpart show mmcsd0 2> /dev/null | grep -q freebsd-zfs; then
|
69
|
if /sbin/zpool status pfSense | grep -q mmcsd0 > /dev/null; then
|
70
|
echo "Clearing ZFS label before expanding"
|
71
|
/sbin/zpool labelclear /dev/mmcsd0
|
72
|
fi
|
73
|
fi
|
74
|
/etc/rc.d/growfs onestart
|
75
|
ALL_SWAPFS="$(/usr/bin/awk '/swap/ && !(/dev\/mirror\// || /dev\/ufsid\// || /dev\/label\// || /dev\/geom\//) {print $1}' "${DESTDIR}/etc/fstab")"
|
76
|
HAS_SWAP="0"
|
77
|
for SFS in ${ALL_SWAPFS}
|
78
|
do
|
79
|
DEV="${SFS##/dev/}"
|
80
|
[ "${DEV}" = "" ] && continue
|
81
|
SWAPDEV="${DEV}"
|
82
|
echo "FS: Swap slice on device ${SWAPDEV}"
|
83
|
HAS_SWAP="1"
|
84
|
done
|
85
|
|
86
|
# Check if growfs has created a swap partition.
|
87
|
if [ "${HAS_SWAP}" = "0" ] && \
|
88
|
[ "$(/sbin/glabel status | /usr/bin/grep -c "growfs_swap")" = "1" ]; then
|
89
|
DEV="$(/sbin/glabel status | /usr/bin/grep growfs_swap | /usr/bin/awk '{ printf $3 }')"
|
90
|
# Rename the default growfs swap partition name.
|
91
|
/sbin/glabel destroy -f growfs_swap
|
92
|
/sbin/glabel label swap1 "/dev/${DEV}"
|
93
|
SWAP_FSTAB_ADD="1"
|
94
|
fi
|
95
|
fi
|
96
|
|
97
|
#
|
98
|
# The file system needs to be unmounted to guarantee a clean operation of fsck.
|
99
|
# Pending changes can keep the file system dirty until all the cached data is
|
100
|
# flushed to the disk.
|
101
|
#
|
102
|
/sbin/mount -ur /
|
103
|
|
104
|
fsck_forced_iterations=`/bin/kenv -q pfsense.fsck.force`
|
105
|
if [ -n "${fsck_forced_iterations}" ]; then
|
106
|
echo "Forcing filesystem check (${fsck_forced_iterations} times)..."
|
107
|
while [ "${fsck_forced_iterations}" -gt 0 ]; do
|
108
|
/sbin/fsck -fy -t ufs
|
109
|
fsck_forced_iterations=$((fsck_forced_iterations - 1))
|
110
|
done
|
111
|
fi
|
112
|
|
113
|
fsck_fix_flag_file="/.fix_for_SA-19-10.ufs"
|
114
|
|
115
|
# Apply fix for https://www.freebsd.org/security/advisories/FreeBSD-SA-19:10.ufs.asc
|
116
|
unset fsck_fix_applied
|
117
|
unset skip_fsck_fix
|
118
|
unset fsck_fix_count
|
119
|
if [ -f "${fsck_fix_flag_file}" ]; then
|
120
|
if ! awk '{print $3}' /etc/fstab | grep -q ufs; then
|
121
|
echo "Fix for FreeBSD-SA-19:10.ufs is not needed in this system"
|
122
|
skip_fsck_fix=1
|
123
|
else
|
124
|
fsck_fix_count=$(cat ${fsck_fix_flag_file})
|
125
|
echo "Applying fix for FreeBSD-SA-19:10.ufs"
|
126
|
if /sbin/fsck -t ufs -f -p -T ufs:-z >/dev/null 2>&1; then
|
127
|
fsck_fix_applied=1
|
128
|
fi
|
129
|
fi
|
130
|
fi
|
131
|
|
132
|
# Set it to 0 if it's empty
|
133
|
fsck_fix_count=${fsck_fix_count:-0}
|
134
|
|
135
|
FSCK_ACTION_NEEDED=0
|
136
|
/sbin/fsck -p
|
137
|
case $? in
|
138
|
0)
|
139
|
echo "Filesystems are clean, continuing..."
|
140
|
echo "Mounting filesystems..."
|
141
|
;;
|
142
|
8|16)
|
143
|
echo "Preen mode recommended running a check that will be performed now."
|
144
|
FSCK_ACTION_NEEDED=1
|
145
|
;;
|
146
|
*)
|
147
|
echo "Stopping boot is recommended because filesystem manual action is needed, nevertheless automated repair of the filesystem will be attempted."
|
148
|
FSCK_ACTION_NEEDED=1
|
149
|
;;
|
150
|
esac
|
151
|
|
152
|
if [ ${FSCK_ACTION_NEEDED} = 1 ]; then
|
153
|
echo "WARNING: Trying to recover filesystem from inconsistency..."
|
154
|
/sbin/fsck -fy -t ufs
|
155
|
fi
|
156
|
|
157
|
/sbin/mount -a 2>/dev/null
|
158
|
mount_rc=$?
|
159
|
attempts=0
|
160
|
while [ "${mount_rc}" -ne 0 ] && [ "${attempts}" -lt 10 ]; do
|
161
|
/sbin/fsck -fy -t ufs
|
162
|
/sbin/mount -a 2>/dev/null
|
163
|
mount_rc=$?
|
164
|
attempts=$((attempts+1))
|
165
|
done
|
166
|
|
167
|
if [ ${mount_rc} -ne 0 ]; then
|
168
|
echo "ERROR: Impossible to mount filesystem, use interactive shell to attempt to recover it"
|
169
|
/bin/sh
|
170
|
/sbin/reboot
|
171
|
fi
|
172
|
|
173
|
. /etc/rc.ramdisk_functions.sh
|
174
|
|
175
|
# Handle ZFS read-only case
|
176
|
unset USE_ZFS
|
177
|
if /sbin/kldstat -qm zfs; then
|
178
|
ZFSFSAVAILABLE=$(/sbin/zfs mount 2>/dev/null | wc -l)
|
179
|
if [ "$ZFSFSAVAILABLE" -eq 0 ]; then
|
180
|
/sbin/kldunload zfs
|
181
|
else
|
182
|
USE_ZFS=1
|
183
|
ZFSROOT=$(/sbin/zfs mount | /usr/bin/awk '$2 == "/" {print $1}')
|
184
|
if [ -n "$ZFSROOT" ]; then
|
185
|
/sbin/zfs set readonly=off "$ZFSROOT"
|
186
|
fi
|
187
|
/sbin/zfs mount -a
|
188
|
# If /bootpool is present, then there is an additional zfs pool to import
|
189
|
# See https://redmine.pfsense.org/issues/8063
|
190
|
if [ -d /bootpool ]; then
|
191
|
/sbin/zpool import -f bootpool
|
192
|
fi
|
193
|
# We need to handle ZFS boot environments here
|
194
|
_be_mount_zfs
|
195
|
fi
|
196
|
fi
|
197
|
|
198
|
# Add the swap partition created by growfs to the system fstab.
|
199
|
if [ -n "${SWAP_FSTAB_ADD}" ] && [ -c "/dev/label/swap1" ]; then
|
200
|
printf "/dev/label/swap1\tnone\tswap\tsw\t0\t0\n" >> /etc/fstab
|
201
|
fi
|
202
|
|
203
|
# If /conf is a directory, convert it to a symlink to /cf/conf
|
204
|
if [ -d "/conf" ]; then
|
205
|
# If item is not a symlink then rm and recreate
|
206
|
CONFPOINTSTO=`readlink /conf`
|
207
|
if [ "$CONFPOINTSTO" != "/cf/conf" ]; then
|
208
|
/bin/rm -rf /conf
|
209
|
/bin/ln -s /cf/conf /conf
|
210
|
fi
|
211
|
fi
|
212
|
|
213
|
# Sanity check the clock
|
214
|
/etc/rc.checkclock
|
215
|
|
216
|
# Make sure the dynamic linker is setup for xmllint
|
217
|
[ ! -f /var/run/ld-elf.so.hints ] && /etc/rc.d/ldconfig start
|
218
|
|
219
|
# Check if RAM disks are enabled, store for repeated use
|
220
|
if ramdisk_check_enabled && ramdisk_check_size; then
|
221
|
export USE_RAMDISK=true
|
222
|
fi
|
223
|
|
224
|
# Relocate pkgdb on UFS based on desired RAM disk settings
|
225
|
if [ -z "${USE_ZFS}" ]; then
|
226
|
ramdisk_relocate_pkgdb_all
|
227
|
fi
|
228
|
|
229
|
# Dismount /tmp and /var on ZFS if using RAM disks and they are separate volumes
|
230
|
if [ -n "${USE_ZFS}" ] && [ -n "${USE_RAMDISK}" ]; then
|
231
|
ramdisk_fixup_zfs_unmount
|
232
|
fi
|
233
|
|
234
|
# Attempt to create and mount RAM disks
|
235
|
if [ -n "${USE_RAMDISK}" ]; then
|
236
|
echo -n "Setting up memory disks..."
|
237
|
if ramdisk_try_mount tmp && ramdisk_try_mount var; then
|
238
|
/bin/rm -f "${RAMDISK_FLAG_FILE}"
|
239
|
# Create some needed directories
|
240
|
/bin/mkdir -p /var/db /var/spool/lock
|
241
|
/usr/sbin/chown uucp:dialer /var/spool/lock
|
242
|
# Ensure vi's recover directory is present
|
243
|
/bin/mkdir -p /var/tmp/vi.recover
|
244
|
/bin/mkdir -p /var/crash
|
245
|
/bin/mkdir -p /var/run
|
246
|
/bin/mkdir -p /var/log
|
247
|
echo " done."
|
248
|
else
|
249
|
/usr/bin/touch "${RAMDISK_FLAG_FILE}"
|
250
|
/sbin/umount -f /tmp /var 2>/dev/null
|
251
|
echo " failed."
|
252
|
fi
|
253
|
# Remount the correct subordinate ZFS datasets to ensure they are used properly
|
254
|
[ -n "${USE_ZFS}" ] && _be_mount_zfs
|
255
|
fi
|
256
|
|
257
|
# If RAM disks are active, make symlinks for pkg database on UFS
|
258
|
if [ -n "${USE_RAMDISK}" ] || [ -n "${MOVE_PKG_DATA}" ]; then
|
259
|
if [ -z "${USE_ZFS}" ]; then
|
260
|
ramdisk_link_pkgdb
|
261
|
fi
|
262
|
fi
|
263
|
|
264
|
# If activating RAM disks failed, then undo some of the above actions
|
265
|
if [ -n "${USE_RAMDISK}" ] && ramdisk_failed; then
|
266
|
ramdisk_fixup_zfs_mount
|
267
|
if [ -z "${USE_ZFS}" ]; then
|
268
|
ramdisk_relocate_pkgdb disk
|
269
|
fi
|
270
|
else
|
271
|
ramdisk_reset_status
|
272
|
fi
|
273
|
|
274
|
# Setup ddb on all platforms.
|
275
|
if [ -n "$( sysctl -Nq debug.ddb.scripting.scripts )" ]; then
|
276
|
/sbin/ddb "/etc/${product_name}-ddb.conf"
|
277
|
fi
|
278
|
|
279
|
# Restore contents of the RAM disk store
|
280
|
/etc/rc.restore_ramdisk_store
|
281
|
|
282
|
# Make sure /home exists
|
283
|
[ -d /home ] \
|
284
|
|| mkdir /home
|
285
|
|
286
|
/bin/rm -f /root/force_fsck
|
287
|
/bin/rm -f /root/force_growfs
|
288
|
/bin/rm -f /root/TRIM_set
|
289
|
/bin/rm -f /root/TRIM_unset
|
290
|
|
291
|
# Disable APM on ATA drives. Leaving this on will kill drives long-term, especially laptop drives, by generating excessive Load Cycles.
|
292
|
if [ -f /etc/rc.disable_hdd_apm ]; then
|
293
|
/etc/rc.disable_hdd_apm
|
294
|
fi
|
295
|
|
296
|
# Eject CD devices on 3G modems
|
297
|
MANUFACTURER="huawei|zte"
|
298
|
CDDEVICE=`dmesg |egrep -ie "($MANUFACTURER)" | awk -F: '/cd/ {print $1}'`
|
299
|
if [ "$CDDEVICE" != "" ]; then
|
300
|
cdcontrol -f /dev/"$CDDEVICE" eject
|
301
|
fi
|
302
|
|
303
|
# Use php -n here because we are not ready to load extensions yet
|
304
|
varrunpath=$(/usr/local/bin/php -n /usr/local/sbin/read_global_var varrun_path "/var/run")
|
305
|
|
306
|
if [ -z "${USE_RAMDISK}" ]; then
|
307
|
/sbin/mount -o rw,size=4m,mode=1777 -t tmpfs tmpfs "$varrunpath"
|
308
|
fi
|
309
|
|
310
|
echo
|
311
|
cat /usr/local/share/pfSense/ascii-art/pfsense-logo-small.txt
|
312
|
echo
|
313
|
echo
|
314
|
echo "Welcome to ${product_label} ${version}${version_patch}..."
|
315
|
echo
|
316
|
|
317
|
/sbin/conscontrol mute off >/dev/null
|
318
|
|
319
|
SWAPDEVICE=`/bin/cat /etc/fstab | /usr/bin/grep swap | /usr/bin/awk '{ printf $1 }' | /usr/bin/head -n 1`
|
320
|
if [ -n "${SWAPDEVICE}" ]; then
|
321
|
/bin/rm -f /tmp/fstab.swap
|
322
|
if ! [ -c "${SWAPDEVICE}" ]; then
|
323
|
# Keep the original device, in case it is special, such as encrypted+mirrored zfs swap
|
324
|
echo "${SWAPDEVICE} none swap sw 0 0" >> /tmp/fstab.swap
|
325
|
# The swap device in fstab does not exist, look for other valid entries and update fstab
|
326
|
for SWAPLABEL in /dev/label/swap* /dev/mirror/swap*; do
|
327
|
if [ -c "${SWAPLABEL}" ]; then
|
328
|
echo "${SWAPLABEL} none swap sw 0 0" >> /tmp/fstab.swap
|
329
|
fi
|
330
|
done
|
331
|
else
|
332
|
/bin/cp /etc/fstab /tmp/fstab.swap
|
333
|
fi
|
334
|
/sbin/swapon -F /tmp/fstab.swap -a 2>/dev/null >/dev/null
|
335
|
/etc/rc.savecore
|
336
|
fi
|
337
|
|
338
|
# make some directories in /var
|
339
|
/bin/mkdir -p "$varrunpath" /var/etc /var/db/entropy /var/db/rrd /var/at/jobs/ /var/empty /var/log/nginx 2>/dev/null
|
340
|
|
341
|
# turn off the immutable flag, set /var/empty to read-only, make it immutable again
|
342
|
chflags noschg /var/empty
|
343
|
chmod 0555 /var/empty
|
344
|
chflags schg /var/empty
|
345
|
|
346
|
/bin/rm -rf "$varrunpath"/*
|
347
|
|
348
|
# Cleanup configuration files from previous instance
|
349
|
/bin/rm -rf /var/etc/*
|
350
|
|
351
|
# Workaround for ipsec symlinks, otherwise it's going to break
|
352
|
# strongswan pkg upgrade
|
353
|
|
354
|
if [ -L /usr/local/etc/ipsec.d ]; then
|
355
|
rm -f /usr/local/etc/ipsec.d
|
356
|
fi
|
357
|
if [ -L /usr/local/etc/ipsec.conf ]; then
|
358
|
rm -f /usr/local/etc/ipsec.conf
|
359
|
fi
|
360
|
if [ -L /usr/local/etc/strongswan.d ]; then
|
361
|
rm -f /usr/local/etc/strongswan.d
|
362
|
fi
|
363
|
if [ -L /usr/local/etc/strongswan.conf ]; then
|
364
|
rm -f /usr/local/etc/strongswan.conf
|
365
|
fi
|
366
|
|
367
|
# Remove deprecated symlinks - #5538
|
368
|
for f in /etc/hosts \
|
369
|
/etc/resolv.conf \
|
370
|
/etc/resolvconf.conf \
|
371
|
/etc/syslog.conf; do
|
372
|
if [ -L "${f}" ]; then
|
373
|
rm -f ${f}
|
374
|
fi
|
375
|
done
|
376
|
|
377
|
# Make sure our /tmp is 777 + Sticky
|
378
|
/bin/chmod 1777 /tmp
|
379
|
|
380
|
if [ ! -L /etc/dhclient.conf ]; then
|
381
|
/bin/rm -rf /etc/dhclient.conf
|
382
|
fi
|
383
|
|
384
|
if [ ! -d /var/tmp ]; then
|
385
|
/bin/mkdir -p /var/tmp
|
386
|
fi
|
387
|
# Make sure our /var/tmp is 777 + Sticky
|
388
|
/bin/chmod 1777 /var/tmp
|
389
|
|
390
|
set -T
|
391
|
trap "echo 'Reboot interrupted'; exit 1" 3
|
392
|
|
393
|
echo -n "."
|
394
|
LOG_FILES="system filter dhcpd vpn poes l2tps openvpn auth portalauth ipsec ppp wireless nginx ntpd gateways resolver routing"
|
395
|
|
396
|
for logfile in $LOG_FILES; do
|
397
|
/usr/bin/touch "/var/log/${logfile}.log"
|
398
|
done
|
399
|
|
400
|
# change permissions on newly created log files.
|
401
|
/bin/chmod 0600 /var/log/*.log
|
402
|
|
403
|
echo -n "."
|
404
|
DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
|
405
|
if [ "$DEVFS" = "0" ]; then
|
406
|
mount_devfs devfs /dev
|
407
|
fi
|
408
|
|
409
|
# Create an initial utmp file
|
410
|
/bin/cp /dev/null "${varrunpath}/utmp" && /bin/chmod 644 "${varrunpath}/utmp"
|
411
|
|
412
|
echo -n "."
|
413
|
/etc/rc.d/ldconfig start 2>/dev/null
|
414
|
|
415
|
# Launching kbdmux(4)
|
416
|
if [ -f "/dev/kbdmux0" ]; then
|
417
|
echo -n "."
|
418
|
/usr/sbin/kbdcontrol -k /dev/kbdmux0 < /dev/console
|
419
|
[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
|
420
|
[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
|
421
|
fi
|
422
|
|
423
|
# Fire up unionfs if mount points exist.
|
424
|
if [ -f /dist/uniondirs ]; then
|
425
|
echo -n "."
|
426
|
/etc/rc.d/unionfs start
|
427
|
fi
|
428
|
|
429
|
echo "done."
|
430
|
|
431
|
# Recreate capabilities DB
|
432
|
/usr/bin/cap_mkdb /etc/login.conf
|
433
|
|
434
|
if [ -f /cf/conf/needs_package_sync ]; then
|
435
|
# When restoring a configuration backup:
|
436
|
# - do not call pfSense-upgrade on boot
|
437
|
# - do not run rc.start_packages
|
438
|
skip_packages=1
|
439
|
fi
|
440
|
|
441
|
# Run the php.ini setup file
|
442
|
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
|
443
|
|
444
|
# Second upgrade stage
|
445
|
[ -z "$skip_packages" ] \
|
446
|
&& "/usr/local/sbin/${product_name}-upgrade" -y -U -b 2
|
447
|
|
448
|
# Copy default openssl config file and Netgate CA
|
449
|
[ -d /etc/ssl ] \
|
450
|
|| mkdir -p /etc/ssl
|
451
|
[ -f "/usr/local/share/${product_name}/ssl/openssl.cnf" ] \
|
452
|
&& cp -f "/usr/local/share/${product_name}/ssl/openssl.cnf" /etc/ssl
|
453
|
mkdir -p /usr/local/openssl >/dev/null 2>&1
|
454
|
ln -sf /etc/ssl/openssl.cnf \
|
455
|
/usr/local/openssl/openssl.cnf
|
456
|
|
457
|
[ -f "/usr/local/share/${product_name}/ssl/netgate-ca.pem" ] \
|
458
|
&& cp -f "/usr/local/share/${product_name}/ssl/netgate-ca.pem" /etc/ssl
|
459
|
|
460
|
# Populate /usr/local/etc/php.ini
|
461
|
/usr/local/sbin/php-fpm -c /usr/local/etc/php.ini -y /usr/local/lib/php-fpm.conf -RD 2>&1 >/dev/null
|
462
|
|
463
|
# Launch external configuration loader
|
464
|
/etc/rc.ecl
|
465
|
|
466
|
if [ -f /etc/rc.custom_boot_early ]; then
|
467
|
/bin/echo -n "Launching /etc/rc.custom_boot_early...";
|
468
|
/etc/rc.custom_boot_early
|
469
|
echo "Done"
|
470
|
fi
|
471
|
|
472
|
export fcgipath=/var/run/php-fpm.socket
|
473
|
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
|
474
|
|
475
|
# let the PHP-based configuration subsystem set up the system now
|
476
|
echo -n "Launching the init system..."
|
477
|
/bin/rm -f /cf/conf/backup/backup.cache
|
478
|
/usr/bin/touch "$varrunpath/booting"
|
479
|
|
480
|
# Copy custom logo over if it's present
|
481
|
if [ -d "/usr/local/share/${product_name}/custom_logos" ]; then
|
482
|
cp -f "/usr/local/share/${product_name}/custom_logos/"*svg \
|
483
|
/usr/local/www
|
484
|
cp -f "/usr/local/share/${product_name}/custom_logos/"*css \
|
485
|
/usr/local/www/css
|
486
|
fi
|
487
|
|
488
|
# Apply CPU microcode update
|
489
|
[ -x /usr/local/etc/rc.d/microcode_update ] \
|
490
|
&& /usr/local/etc/rc.d/microcode_update onestart
|
491
|
|
492
|
if [ -n "${skip_fsck_fix}" ]; then
|
493
|
rm -f "${fsck_fix_flag_file}"
|
494
|
elif [ -f "${fsck_fix_flag_file}" ]; then
|
495
|
# fsck fix already applied
|
496
|
if [ -n "${fsck_fix_applied}" ]; then
|
497
|
touch /cf/conf/applied_fix_for_SA-19-10.ufs
|
498
|
rm -f "${fsck_fix_flag_file}"
|
499
|
elif [ "${fsck_fix_count}" -ge 3 ]; then
|
500
|
echo "ERROR: fsck fix for SA-19-10 failed to apply..."
|
501
|
sleep 5
|
502
|
rm -f "${fsck_fix_flag_file}"
|
503
|
else
|
504
|
# if / is UFS, reroot instead of reboot
|
505
|
root_fstype=$(mount -p / | awk '{print $3}')
|
506
|
unset reroot
|
507
|
if [ "${root_fstype}" = "ufs" ]; then
|
508
|
reroot="-r"
|
509
|
fi
|
510
|
|
511
|
# fsck fix failed, increment escape counter to avoid infinite
|
512
|
# loop on a system with a broken filesystem
|
513
|
fsck_fix_count=$((fsck_fix_count+1))
|
514
|
|
515
|
echo "${fsck_fix_count}" > ${fsck_fix_flag_file}
|
516
|
|
517
|
# fsck binary was old and didn't have -z option, then reboot
|
518
|
# and run again
|
519
|
echo "fsck needs to run to fix SA-10-10. Rebooting..."
|
520
|
/etc/rc.reboot ${reroot}
|
521
|
exit 0
|
522
|
fi
|
523
|
fi
|
524
|
|
525
|
/etc/rc.bootup
|
526
|
|
527
|
# /etc/rc.bootup unset $g['booting'], and removes file
|
528
|
# Be sure the file is removed to not create troubles after
|
529
|
if [ -f "$varrunpath/booting" ]; then
|
530
|
/bin/rm "$varrunpath/booting"
|
531
|
fi
|
532
|
|
533
|
if [ -n "${USE_ZFS}" ]; then
|
534
|
# Create ZFS reservation
|
535
|
if [ ! -f /.no_zfs_reservation ]; then
|
536
|
zpool list -o name pfSense > /dev/null 2>&1 && ZPOOL=pfSense
|
537
|
zpool list -o name zroot > /dev/null 2>&1 && ZPOOL=zroot
|
538
|
if [ -n "${ZPOOL}" ]; then
|
539
|
if zfs list -Hp -o name -t filesystem | grep -q "${ZPOOL}/reservation"; then
|
540
|
AVAIL=$( zfs list -Hpo avail "${ZPOOL}" )
|
541
|
RESSIZE=$( zfs list -Hpo avail,used "${ZPOOL}" | awk -v CONVFMT='%.0f' '{printf ( $1 + $2 ) * 0.1 "\n"}' )
|
542
|
if [ $(( AVAIL / 2 )) -gt "${RESSIZE}" ]; then
|
543
|
logger "Creating ZFS reservation of ${RESSIZE} bytes on ${ZPOOL}"
|
544
|
zfs create -o reservation="${RESSIZE}" "${ZPOOL}/reservation"
|
545
|
else
|
546
|
logger "Not enough space to create reservation on ${ZPOOL}; ${AVAIL} / 2 is not greater than ${RESSIZE} bytes"
|
547
|
fi
|
548
|
fi
|
549
|
fi
|
550
|
fi
|
551
|
|
552
|
# Enable zpool trimming
|
553
|
if [ ! -f /.no_zpool_autotrim ]; then
|
554
|
/sbin/zpool list -o name pfSense > /dev/null 2>&1 && ZPOOL=pfSense
|
555
|
/sbin/zpool list -o name zroot > /dev/null 2>&1 && ZPOOL=zroot
|
556
|
if [ -n "${ZPOOL}" ]; then
|
557
|
AUTOTRIM=$( /sbin/zpool get -H -o value autotrim "${ZPOOL}" )
|
558
|
if [ "${AUTOTRIM}" = "off" ]; then
|
559
|
echo -n "Trimming the zpool... "
|
560
|
/sbin/zpool set autotrim=on "${ZPOOL}"
|
561
|
/sbin/zpool trim "${ZPOOL}"
|
562
|
echo "done."
|
563
|
fi
|
564
|
fi
|
565
|
fi
|
566
|
fi
|
567
|
|
568
|
echo -n "Starting CRON... "
|
569
|
cd /tmp && /usr/sbin/cron -s 2>/dev/null
|
570
|
echo "done."
|
571
|
|
572
|
/bin/rm -rf /usr/local/pkg/pf/CVS
|
573
|
|
574
|
# Start ping handler every 240 seconds
|
575
|
/usr/local/bin/minicron 240 "$varrunpath/ping_hosts.pid" /usr/local/bin/ping_hosts.sh
|
576
|
|
577
|
# Start IPsec keep alive handler every 300 seconds
|
578
|
/usr/local/bin/minicron 300 "$varrunpath/ipsec_keepalive.pid" /usr/local/bin/ipsec_keepalive.php
|
579
|
|
580
|
# Start account expire handler every hour
|
581
|
/usr/local/bin/minicron 3600 "$varrunpath/expire_accounts.pid" '/usr/local/sbin/fcgicli -f /etc/rc.expireaccounts'
|
582
|
|
583
|
# Start alias url updater every 24 hours
|
584
|
/usr/local/bin/minicron 86400 "$varrunpath/update_alias_url_data.pid" '/usr/local/sbin/fcgicli -f /etc/rc.update_alias_url_data'
|
585
|
|
586
|
/bin/chmod a+rw /tmp/.
|
587
|
|
588
|
# Check for GEOM mirrors
|
589
|
GMIRROR_STATUS=`/sbin/gmirror status`
|
590
|
if [ "${GMIRROR_STATUS}" != "" ]; then
|
591
|
# Using a flag file at bootup saves an expensive exec/check on each page load.
|
592
|
/usr/bin/touch /var/run/gmirror_active
|
593
|
# Setup monitoring/notifications
|
594
|
/usr/local/bin/minicron 60 /var/run/gmirror_status_check.pid /usr/local/sbin/gmirror_status_check.php
|
595
|
fi
|
596
|
|
597
|
if [ -z "$skip_packages" ]; then
|
598
|
"/usr/local/sbin/${product_name}-upgrade" -y -U -b 3
|
599
|
fi
|
600
|
|
601
|
# Start packages
|
602
|
[ -z "$skip_packages" ] \
|
603
|
&& /usr/local/sbin/fcgicli -f /etc/rc.start_packages
|
604
|
|
605
|
# Update pkg metadata
|
606
|
/etc/rc.update_pkg_metadata now
|
607
|
|
608
|
# Reset the cache. read-only requires this.
|
609
|
/bin/rm -f /tmp/config.cache
|
610
|
|
611
|
# Run /etc/rc.local
|
612
|
if [ -f /etc/rc.local ]; then
|
613
|
unset do_sleep
|
614
|
if ! /bin/pgrep -qf 'rc.local$'; then
|
615
|
echo ">>> Launching rc.local in background..."
|
616
|
/bin/sh /etc/rc.local &
|
617
|
do_sleep=1
|
618
|
fi
|
619
|
if [ -f /etc/rc.local.running ] &&
|
620
|
! /bin/pgrep -qf 'rc.local.running$'; then
|
621
|
[ -n "${do_sleep}" ] && sleep 1
|
622
|
echo ">>> Launching rc.local.running in background..."
|
623
|
/bin/sh /etc/rc.local.running &
|
624
|
fi
|
625
|
fi
|
626
|
|
627
|
# Log product version to syslog
|
628
|
get_version
|
629
|
BUILDTIME=`cat /etc/version.buildtime`
|
630
|
ARCH=`uname -m`
|
631
|
echo "$product_label ${version}${version_patch} $ARCH $BUILDTIME"
|
632
|
|
633
|
echo "Bootup complete"
|
634
|
echo "Bootup complete" | /usr/bin/logger
|
635
|
|
636
|
/usr/local/bin/beep.sh start 2>&1 >/dev/null
|
637
|
|
638
|
exit 0
|