1
|
#!/bin/sh
|
2
|
#
|
3
|
# pfSense-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
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
14
|
# you may not use this file except in compliance with the License.
|
15
|
# You may obtain a copy of the License at
|
16
|
#
|
17
|
# http://www.apache.org/licenses/LICENSE-2.0
|
18
|
#
|
19
|
# Unless required by applicable law or agreed to in writing, software
|
20
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
21
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
22
|
# See the License for the specific language governing permissions and
|
23
|
# limitations under the License.
|
24
|
|
25
|
#/bin/stty status '^T'
|
26
|
#/bin/stty susp '^-' intr '^-' quit '^-'
|
27
|
|
28
|
#trap : 2
|
29
|
#trap : 3
|
30
|
|
31
|
HOME=/
|
32
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
|
33
|
export HOME PATH
|
34
|
|
35
|
get_version ()
|
36
|
{
|
37
|
# Set our current version
|
38
|
version=`/bin/cat /etc/version`
|
39
|
|
40
|
# Version patch
|
41
|
version_patch="0"
|
42
|
if [ -f /etc/version.patch ]; then
|
43
|
version_patch=`/bin/cat /etc/version.patch`
|
44
|
fi
|
45
|
|
46
|
if [ "${version_patch}" = "0" ]; then
|
47
|
version_patch=""
|
48
|
else
|
49
|
version_patch=" (Patch ${version_patch})"
|
50
|
fi
|
51
|
}
|
52
|
|
53
|
get_version
|
54
|
|
55
|
# Read product_name from $g, defaults to pfSense
|
56
|
# Use php -n here because we are not ready to load extensions yet
|
57
|
product=$(/usr/local/bin/php -n /usr/local/sbin/read_global_var product_name pfSense)
|
58
|
|
59
|
# Setup dumpdev/ddb/savecore"
|
60
|
echo "Configuring crash dumps..."
|
61
|
/etc/rc.dumpon
|
62
|
|
63
|
# Setup ddb on all platforms.
|
64
|
if [ ! -z "`sysctl -Nq debug.ddb.scripting.scripts`" ]; then
|
65
|
/sbin/ddb /etc/${product}-ddb.conf
|
66
|
fi
|
67
|
|
68
|
fsck_forced_iterations=`/bin/kenv -q pfsense.fsck.force`
|
69
|
if [ ! -z "${fsck_forced_iterations}" ]; then
|
70
|
echo "Forcing filesystem check (${fsck_forced_iterations} times)..."
|
71
|
while [ ${fsck_forced_iterations} -gt 0 ]; do
|
72
|
/sbin/fsck -y -t ufs
|
73
|
fsck_forced_iterations=$((fsck_forced_iterations - 1))
|
74
|
done
|
75
|
fi
|
76
|
|
77
|
if [ -e /root/force_growfs ]; then
|
78
|
/etc/rc.d/growfs onestart
|
79
|
fi
|
80
|
|
81
|
FSCK_ACTION_NEEDED=0
|
82
|
/sbin/fsck -p
|
83
|
case $? in
|
84
|
0)
|
85
|
echo "Filesystems are clean, continuing..."
|
86
|
echo "Mounting filesystems..."
|
87
|
;;
|
88
|
8)
|
89
|
echo "Preen mode recommended running a check that will be performed now."
|
90
|
FSCK_ACTION_NEEDED=1
|
91
|
;;
|
92
|
*)
|
93
|
echo "Stopping boot is recommended because filesystem manual action is needed, nevertheless automated repair of the filesystem will be attempted."
|
94
|
FSCK_ACTION_NEEDED=1
|
95
|
;;
|
96
|
esac
|
97
|
|
98
|
if [ ${FSCK_ACTION_NEEDED} = 1 ]; then
|
99
|
echo "WARNING: Trying to recover filesystem from inconsistency..."
|
100
|
/sbin/fsck -y -t ufs
|
101
|
fi
|
102
|
|
103
|
/sbin/mount -a 2>/dev/null
|
104
|
mount_rc=$?
|
105
|
attempts=0
|
106
|
while [ ${mount_rc} -ne 0 -a ${attempts} -lt 10 ]; do
|
107
|
/sbin/fsck -y -t ufs
|
108
|
/sbin/mount -a 2>/dev/null
|
109
|
mount_rc=$?
|
110
|
attempts=$((attempts+1))
|
111
|
done
|
112
|
|
113
|
if [ ${mount_rc} -ne 0 ]; then
|
114
|
echo "ERROR: Impossible to mount filesystem, use interactive shell to attempt to recover it"
|
115
|
/bin/sh
|
116
|
/sbin/reboot
|
117
|
fi
|
118
|
|
119
|
# Handle ZFS read-only case
|
120
|
unset USE_ZFS
|
121
|
if /sbin/kldstat -qm zfs; then
|
122
|
ZFSFSAVAILABLE=$(/sbin/zfs mount 2>/dev/null | wc -l)
|
123
|
if [ $ZFSFSAVAILABLE -eq 0 ]; then
|
124
|
/sbin/kldunload zfs
|
125
|
else
|
126
|
USE_ZFS=1
|
127
|
ZFSROOT=$(/sbin/zfs mount | /usr/bin/awk '$2 == "/" {print $1}')
|
128
|
if [ -n "$ZFSROOT" ]; then
|
129
|
/sbin/zfs set readonly=off $ZFSROOT
|
130
|
fi
|
131
|
/sbin/zfs mount -a
|
132
|
fi
|
133
|
fi
|
134
|
|
135
|
# If /conf is a directory, convert it to a symlink to /cf/conf
|
136
|
if [ -d "/conf" ]; then
|
137
|
# If item is not a symlink then rm and recreate
|
138
|
CONFPOINTSTO=`readlink /conf`
|
139
|
if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then
|
140
|
/bin/rm -rf /conf
|
141
|
/bin/ln -s /cf/conf /conf
|
142
|
fi
|
143
|
fi
|
144
|
|
145
|
USE_MFS_TMPVAR=$(/usr/local/sbin/read_xml_tag.sh boolean system/use_mfs_tmpvar)
|
146
|
|
147
|
unset MOVE_PKG_DATA
|
148
|
# If use MFS var is disabled, move files back to place
|
149
|
if [ "${USE_MFS_TMPVAR}" != "true" -a -f /root/var/db/pkg/local.sqlite ]; then
|
150
|
MOVE_PKG_DATA=1
|
151
|
rm -rf /var/db/pkg 2>/dev/null
|
152
|
rm -rf /var/cache/pkg 2>/dev/null
|
153
|
mv -f /root/var/db/pkg /var/db
|
154
|
mv -f /root/var/cache/pkg /var/cache
|
155
|
# If use MFS var is enabled, move files to a safe place
|
156
|
elif [ "${USE_MFS_TMPVAR}" = "true" -a -f /var/db/pkg/local.sqlite ]; then
|
157
|
MOVE_PKG_DATA=1
|
158
|
rm -rf /root/var/db/pkg 2>/dev/null
|
159
|
rm -rf /root/var/cache/pkg 2>/dev/null
|
160
|
/bin/mkdir -p /root/var/db /root/var/cache
|
161
|
mv -f /var/db/pkg /root/var/db
|
162
|
mv -f /var/cache/pkg /root/var/cache
|
163
|
fi
|
164
|
|
165
|
# Mount /var and /tmp on ZFS filesystems when it's necessary
|
166
|
if [ -n "${USE_ZFS}" -a "${USE_MFS_TMPVAR}" = "true" ]; then
|
167
|
zfs list -H -o name,mountpoint |
|
168
|
while read volume mountpoint; do
|
169
|
[ "${mountpoint}" != "/var" -a "${mountpoint}" != "/tmp" ] \
|
170
|
&& continue
|
171
|
|
172
|
/sbin/zfs umount ${volume}
|
173
|
done
|
174
|
fi
|
175
|
|
176
|
if [ "${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
|
|
186
|
# Restore contents of the RAM disk store
|
187
|
/etc/rc.restore_ramdisk_store
|
188
|
|
189
|
# Make sure /home exists
|
190
|
[ -d /home ] \
|
191
|
|| mkdir /home
|
192
|
|
193
|
/bin/rm -f /root/force_fsck
|
194
|
/bin/rm -f /root/force_growfs
|
195
|
/bin/rm -f /root/TRIM_set
|
196
|
/bin/rm -f /root/TRIM_unset
|
197
|
|
198
|
# Disable APM on ATA drives. Leaving this on will kill drives long-term, especially laptop drives, by generating excessive Load Cycles.
|
199
|
if [ -f /etc/rc.disable_hdd_apm ]; then
|
200
|
/etc/rc.disable_hdd_apm
|
201
|
fi
|
202
|
|
203
|
# Eject CD devices on 3G modems
|
204
|
MANUFACTURER="huawei|zte"
|
205
|
CDDEVICE=`dmesg |egrep -ie "($MANUFACTURER)" | awk -F: '/cd/ {print $1}'`
|
206
|
if [ "$CDDEVICE" != "" ]; then
|
207
|
cdcontrol -f /dev/"$CDDEVICE" eject
|
208
|
fi
|
209
|
|
210
|
# Use php -n here because we are not ready to load extensions yet
|
211
|
varrunpath=$(/usr/local/bin/php -n /usr/local/sbin/read_global_var varrun_path "/var/run")
|
212
|
|
213
|
if [ "${USE_MFS_TMPVAR}" != "true" ]; then
|
214
|
/sbin/mdmfs -S -M -s 4m md $varrunpath
|
215
|
fi
|
216
|
|
217
|
echo
|
218
|
cat /usr/local/share/pfSense/ascii-art/pfsense-logo-small.txt
|
219
|
echo
|
220
|
echo
|
221
|
echo "Welcome to ${product} ${version}${version_patch}..."
|
222
|
echo
|
223
|
|
224
|
/sbin/conscontrol mute off >/dev/null
|
225
|
|
226
|
SWAPDEVICE=`/bin/cat /etc/fstab | /usr/bin/grep swap | /usr/bin/cut -f1`
|
227
|
if [ -n "${SWAPDEVICE}" ]; then
|
228
|
/sbin/swapon -a 2>/dev/null >/dev/null
|
229
|
/etc/rc.savecore
|
230
|
fi
|
231
|
|
232
|
# make some directories in /var
|
233
|
/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
|
234
|
|
235
|
# turn off the immutable flag, set /var/empty to read-only, make it immutable again
|
236
|
chflags noschg /var/empty
|
237
|
chmod 0555 /var/empty
|
238
|
chflags schg /var/empty
|
239
|
|
240
|
/bin/rm -rf $varrunpath/*
|
241
|
|
242
|
# Cleanup configuration files from previous instance
|
243
|
/bin/rm -rf /var/etc/*
|
244
|
|
245
|
# Workaround for ipsec symlinks, otherwise it's going to break
|
246
|
# strongswan pkg upgrade
|
247
|
|
248
|
if [ -L /usr/local/etc/ipsec.d ]; then
|
249
|
rm -f /usr/local/etc/ipsec.d
|
250
|
fi
|
251
|
if [ -L /usr/local/etc/ipsec.conf ]; then
|
252
|
rm -f /usr/local/etc/ipsec.conf
|
253
|
fi
|
254
|
if [ -L /usr/local/etc/strongswan.d ]; then
|
255
|
rm -f /usr/local/etc/strongswan.d
|
256
|
fi
|
257
|
if [ -L /usr/local/etc/strongswan.conf ]; then
|
258
|
rm -f /usr/local/etc/strongswan.conf
|
259
|
fi
|
260
|
|
261
|
# Remove deprecated symlinks - #5538
|
262
|
for f in /etc/hosts \
|
263
|
/etc/resolv.conf \
|
264
|
/etc/resolvconf.conf \
|
265
|
/etc/syslog.conf; do
|
266
|
if [ -L "${f}" ]; then
|
267
|
rm -f ${f}
|
268
|
fi
|
269
|
done
|
270
|
|
271
|
# Make sure our /tmp is 777 + Sticky
|
272
|
/bin/chmod 1777 /tmp
|
273
|
|
274
|
if [ ! -L /etc/dhclient.conf ]; then
|
275
|
/bin/rm -rf /etc/dhclient.conf
|
276
|
fi
|
277
|
|
278
|
if [ ! -d /var/tmp ]; then
|
279
|
/bin/mkdir -p /var/tmp
|
280
|
fi
|
281
|
# Make sure our /var/tmp is 777 + Sticky
|
282
|
/bin/chmod 1777 /var/tmp
|
283
|
|
284
|
set -T
|
285
|
trap "echo 'Reboot interrupted'; exit 1" 3
|
286
|
|
287
|
echo -n "."
|
288
|
DISABLESYSLOGCLOG=$(/usr/local/sbin/read_xml_tag.sh boolean system/disablesyslogclog)
|
289
|
LOG_FILES="system filter dhcpd vpn poes l2tps openvpn portalauth ipsec ppp relayd wireless nginx ntpd gateways resolver routing"
|
290
|
|
291
|
DEFAULT_LOG_FILE_SIZE=$(/usr/local/sbin/read_xml_tag.sh string syslog/logfilesize)
|
292
|
DEFAULT_LOG_FILE_SIZE=${DEFAULT_LOG_FILE_SIZE:-"511488"}
|
293
|
|
294
|
for logfile in $LOG_FILES; do
|
295
|
if [ "$DISABLESYSLOGCLOG" = "true" ]; then
|
296
|
/usr/bin/touch /var/log/$logfile.log
|
297
|
else
|
298
|
if [ ! -f /var/log/$logfile.log ]; then
|
299
|
/usr/local/sbin/clog -i -s ${DEFAULT_LOG_FILE_SIZE} /var/log/$logfile.log
|
300
|
fi
|
301
|
fi
|
302
|
done
|
303
|
|
304
|
# change permissions on newly created log files.
|
305
|
/bin/chmod 0600 /var/log/*.log
|
306
|
|
307
|
echo -n "."
|
308
|
DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
|
309
|
if [ "$DEVFS" = "0" ]; then
|
310
|
mount_devfs devfs /dev
|
311
|
fi
|
312
|
|
313
|
# Create an initial utmp file
|
314
|
cd $varrunpath && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
|
315
|
|
316
|
echo -n "."
|
317
|
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
|
318
|
/etc/rc.d/ldconfig start 2>/dev/null
|
319
|
|
320
|
# Launching kbdmux(4)
|
321
|
if [ -f "/dev/kbdmux0" ]; then
|
322
|
echo -n "."
|
323
|
/usr/sbin/kbdcontrol -k /dev/kbdmux0 < /dev/console
|
324
|
[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
|
325
|
[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
|
326
|
fi
|
327
|
|
328
|
# Fire up unionfs if mount points exist.
|
329
|
if [ -f /dist/uniondirs ]; then
|
330
|
echo -n "."
|
331
|
/etc/rc.d/unionfs start
|
332
|
fi
|
333
|
|
334
|
echo "done."
|
335
|
|
336
|
# Recreate capabilities DB
|
337
|
/usr/bin/cap_mkdb /etc/login.conf
|
338
|
|
339
|
# Second upgrade stage
|
340
|
/usr/local/sbin/${product}-upgrade -y -b 2
|
341
|
|
342
|
# Copy default openssl config file
|
343
|
[ -d /etc/ssl ] \
|
344
|
|| mkdir -p /etc/ssl
|
345
|
[ -f /usr/local/share/${product}/ssl/openssl.cnf ] \
|
346
|
&& cp -f /usr/local/share/${product}/ssl/openssl.cnf /etc/ssl
|
347
|
mkdir -p /usr/local/openssl >/dev/null 2>&1
|
348
|
ln -sf /etc/ssl/openssl.cnf \
|
349
|
/usr/local/openssl/openssl.cnf
|
350
|
|
351
|
# Run the php.ini setup file and populate
|
352
|
# /usr/local/etc/php.ini
|
353
|
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
|
354
|
/usr/local/sbin/php-fpm -c /usr/local/etc/php.ini -y /usr/local/lib/php-fpm.conf -RD 2>&1 >/dev/null
|
355
|
|
356
|
# Launch external configuration loader
|
357
|
/usr/local/sbin/fcgicli -f /etc/ecl.php
|
358
|
|
359
|
if [ -f /etc/rc.custom_boot_early ]; then
|
360
|
/bin/echo -n "Launching /etc/rc.custom_boot_early...";
|
361
|
/etc/rc.custom_boot_early
|
362
|
echo "Done"
|
363
|
fi
|
364
|
|
365
|
export fcgipath=/var/run/php-fpm.socket
|
366
|
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
|
367
|
|
368
|
# let the PHP-based configuration subsystem set up the system now
|
369
|
echo -n "Launching the init system..."
|
370
|
/bin/rm -f /cf/conf/backup/backup.cache
|
371
|
/usr/bin/touch $varrunpath/booting
|
372
|
|
373
|
# Copy custom logo over if it's present
|
374
|
if [ -d /usr/local/share/${product}/custom_logos ]; then
|
375
|
cp -f /usr/local/share/${product}/custom_logos/*png \
|
376
|
/usr/local/www
|
377
|
fi
|
378
|
|
379
|
/etc/rc.bootup
|
380
|
|
381
|
# /etc/rc.bootup unset $g['booting'], and removes file
|
382
|
# Be sure the file is removed to not create troubles after
|
383
|
if [ -f $varrunpath/booting ]; then
|
384
|
/bin/rm $varrunpath/booting
|
385
|
fi
|
386
|
|
387
|
echo -n "Starting CRON... "
|
388
|
cd /tmp && /usr/sbin/cron -s 2>/dev/null
|
389
|
echo "done."
|
390
|
|
391
|
# Start packages
|
392
|
/usr/local/sbin/fcgicli -f /etc/rc.start_packages
|
393
|
|
394
|
/bin/rm -rf /usr/local/pkg/pf/CVS
|
395
|
|
396
|
# Start ping handler every 240 seconds
|
397
|
/usr/local/bin/minicron 240 $varrunpath/ping_hosts.pid /usr/local/bin/ping_hosts.sh
|
398
|
|
399
|
# Start account expire handler every hour
|
400
|
/usr/local/bin/minicron 3600 $varrunpath/expire_accounts.pid '/usr/local/sbin/fcgicli -f /etc/rc.expireaccounts'
|
401
|
|
402
|
# Start alias url updater every 24 hours
|
403
|
/usr/local/bin/minicron 86400 $varrunpath/update_alias_url_data.pid '/usr/local/sbin/fcgicli -f /etc/rc.update_alias_url_data'
|
404
|
|
405
|
/bin/chmod a+rw /tmp/.
|
406
|
|
407
|
# Check for GEOM mirrors
|
408
|
GMIRROR_STATUS=`/sbin/gmirror status`
|
409
|
if [ "${GMIRROR_STATUS}" != "" ]; then
|
410
|
# Using a flag file at bootup saves an expensive exec/check on each page load.
|
411
|
/usr/bin/touch /var/run/gmirror_active
|
412
|
# Setup monitoring/notifications
|
413
|
/usr/local/bin/minicron 60 /var/run/gmirror_status_check.pid /usr/local/sbin/gmirror_status_check.php
|
414
|
fi
|
415
|
|
416
|
/usr/local/sbin/${product}-upgrade -y -b 3
|
417
|
|
418
|
# Update pkg metadata
|
419
|
/etc/rc.update_pkg_metadata now
|
420
|
|
421
|
# Log product version to syslog
|
422
|
get_version
|
423
|
BUILDTIME=`cat /etc/version.buildtime`
|
424
|
ARCH=`uname -m`
|
425
|
echo "$product ${version}${version_patch} $ARCH $BUILDTIME"
|
426
|
|
427
|
echo "Bootup complete"
|
428
|
|
429
|
/usr/local/bin/beep.sh start 2>&1 >/dev/null
|
430
|
|
431
|
# Reset the cache. read-only requires this.
|
432
|
/bin/rm -f /tmp/config.cache
|
433
|
|
434
|
exit 0
|