Project

General

Profile

Download (11.3 KB) Statistics
| Branch: | Tag: | Revision:
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
# Set our current version
36
version=`/bin/cat /etc/version`
37

    
38
# Version patch
39
version_patch="0"
40
if [ -f /etc/version.patch ]; then
41
	version_patch=`/bin/cat /etc/version.patch`
42
fi
43

    
44
if [ "${version_patch}" = "0" ]; then
45
	version_patch=""
46
else
47
	version_patch=" (Patch ${version_patch})"
48
fi
49

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

    
54
# Setup dumpdev/ddb/savecore"
55
echo "Configuring crash dumps..."
56
/etc/rc.dumpon
57

    
58
# Setup ddb on all platforms.
59
if [ ! -z "`sysctl -Nq debug.ddb.scripting.scripts`" ]; then
60
	/sbin/ddb /etc/ddb.conf
61
fi
62

    
63
if [ -e /root/force_fsck ]; then
64
	echo "Forcing filesystem(s) check..."
65
	/sbin/fsck -y -F -t ufs
66
fi
67

    
68
FSCK_ACTION_NEEDED=0
69
/sbin/fsck -p -F
70
case $? in
71
0)
72
	echo "Filesystems are clean, continuing..."
73
	echo "Mounting filesystems..."
74
	;;
75
8)
76
	echo "Preen mode recommended running a check that will be performed now."
77
	FSCK_ACTION_NEEDED=1
78
	;;
79
*)
80
	echo "Stopping boot is recommended because filesystem manual action is needed, nevertheless automated repair of the filesystem will be attempted."
81
	FSCK_ACTION_NEEDED=1
82
	;;
83
esac
84

    
85
if [ ${FSCK_ACTION_NEEDED} = 1 ]; then
86
	echo "WARNING: Trying to recover filesystem from inconsistency..."
87
	/sbin/fsck -yF
88
fi
89

    
90
/sbin/mount -a 2>/dev/null
91
mount_rc=$?
92
attempts=0
93
while [ ${mount_rc} -ne 0 -a ${attempts} -lt 3 ]; do
94
	/sbin/fsck -yF
95
	/sbin/mount -a 2>/dev/null
96
	mount_rc=$?
97
	attempts=$((attempts+1))
98
done
99

    
100
# If /conf is a directory, convert it to a symlink to /cf/conf
101
if [ -d "/conf" ]; then
102
	# If item is not a symlink then rm and recreate
103
	CONFPOINTSTO=`readlink /conf`
104
	if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then
105
		/bin/rm -rf /conf
106
		/bin/ln -s /cf/conf /conf
107
	fi
108
fi
109

    
110
USE_MFS_TMPVAR=$(/usr/local/sbin/read_xml_tag.sh boolean system/use_mfs_tmpvar)
111
unset MOVE_PKG_DATA
112
# If use MFS var is disabled, move files back to place
113
if [ "${USE_MFS_TMPVAR}" != "true" -a -f /root/var/db/pkg/local.sqlite ]; then
114
	MOVE_PKG_DATA=1
115
	rm -rf /var/db/pkg 2>/dev/null
116
	rm -rf /var/cache/pkg 2>/dev/null
117
	mv /root/var/db/pkg /var/db
118
	mv /root/var/cache/pkg /var/cache
119
# If use MFS var is enabled, move files to a safe place
120
elif [ "${USE_MFS_TMPVAR}" = "true" -a -f /var/db/pkg/local.sqlite ]; then
121
	MOVE_PKG_DATA=1
122
	/bin/mkdir -p /root/var/db /root/var/cache
123
	mv /var/db/pkg /root/var/db
124
	mv /var/cache/pkg /root/var/cache
125
fi
126

    
127
if [ "${USE_MFS_TMPVAR}" = "true" ]; then
128
	/etc/rc.embedded
129
fi
130

    
131
if [ -n "${MOVE_PKG_DATA}" -o "${USE_MFS_TMPVAR}" = "true" ]; then
132
	/bin/mkdir -p /var/db /var/cache
133
	ln -sf ../../root/var/db/pkg /var/db/pkg
134
	ln -sf ../../root/var/cache/pkg /var/cache/pkg
135
fi
136

    
137
# Make sure /home exists
138
[ -d /home ] \
139
	|| mkdir /home
140

    
141
/bin/rm -f /root/force_fsck
142
/bin/rm -f /root/TRIM_set
143
/bin/rm -f /root/TRIM_unset
144

    
145
# Handle ZFS read-only case
146
/sbin/kldstat -qm zfs
147
if [ $? -eq 0 ]; then
148
	ZFSFSAVAILABLE=$(/sbin/zfs mount 2>/dev/null | wc -l)
149
	if [ $ZFSFSAVAILABLE -eq 0 ]; then
150
		/sbin/kldunload zfs
151
	elif [ -f /usr/bin/grep ]; then
152
		ZFSROOT=`/sbin/zfs mount | /usr/bin/grep ' /$' | /usr/bin/cut -d ' ' -f 1`
153
		if [ "$ZFSROOT" != "" ]; then
154
			/sbin/zfs set readonly=off $ZFSROOT
155
		fi
156
	fi
157
fi
158

    
159
# Disable APM on ATA drives. Leaving this on will kill drives long-term, especially laptop drives, by generating excessive Load Cycles.
160
if [ -f /etc/rc.disable_hdd_apm ]; then
161
	/etc/rc.disable_hdd_apm
162
fi
163

    
164
# Eject CD devices on 3G modems
165
MANUFACTURER="huawei|zte"
166
CDDEVICE=`dmesg |egrep -ie "($MANUFACTURER)" | awk -F: '/cd/ {print $1}'`
167
if [ "$CDDEVICE" != "" ]; then
168
	cdcontrol -f /dev/"$CDDEVICE" eject
169
fi
170

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

    
174
if [ "${USE_MFS_TMPVAR}" != "true" ]; then
175
	/sbin/mdmfs -S -M -s 4m md $varrunpath
176
fi
177

    
178
echo
179
cat /usr/local/share/pfSense/ascii-art/pfsense-logo-small.txt
180
echo
181
echo
182
echo "Welcome to ${product} ${version}${version_patch}..."
183
echo
184

    
185
/sbin/conscontrol mute off >/dev/null
186

    
187
SWAPDEVICE=`/bin/cat /etc/fstab | /usr/bin/grep swap | /usr/bin/cut -f1`
188
/sbin/swapon -a 2>/dev/null >/dev/null
189
/etc/rc.savecore
190

    
191
# make some directories in /var
192
/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
193
/bin/rm -rf $varrunpath/*
194

    
195
# Cleanup configuration files from previous instance
196
/bin/rm -rf /var/etc/*
197

    
198
# Workaround for ipsec symlinks, otherwise it's going to break
199
# strongswan pkg upgrade
200

    
201
if [ -L /usr/local/etc/ipsec.d ]; then
202
	rm -f /usr/local/etc/ipsec.d
203
fi
204
if [ -L /usr/local/etc/ipsec.conf ]; then
205
	rm -f /usr/local/etc/ipsec.conf
206
fi
207
if [ -L /usr/local/etc/strongswan.d ]; then
208
	rm -f /usr/local/etc/strongswan.d
209
fi
210
if [ -L /usr/local/etc/strongswan.conf ]; then
211
	rm -f /usr/local/etc/strongswan.conf
212
fi
213

    
214
echo -n "Creating symlinks..."
215
# Repair symlinks if they are broken
216
if [ -f /etc/newsyslog.conf ]; then
217
	/bin/rm -f /etc/newsyslog.conf
218
fi
219
if [ ! -L /etc/syslog.conf ]; then
220
	/bin/rm -rf /etc/syslog.conf
221
	if [ ! -f /var/etc/syslog.conf ]; then
222
		touch /var/etc/syslog.conf
223
	fi
224
	/bin/ln -s /var/etc/syslog.conf /etc/syslog.conf
225
fi
226

    
227
# Repair symlinks if they are broken
228
if [ ! -L /etc/hosts ]; then
229
	/bin/rm -rf /etc/hosts
230
	/bin/ln -s /var/etc/hosts /etc/hosts
231
fi
232

    
233
if [ ! -L /etc/resolv.conf ]; then
234
	/bin/rm -rf /etc/resolv.conf
235
	/bin/ln -s /var/etc/resolv.conf /etc/resolv.conf
236
fi
237

    
238
if [ ! -L /etc/resolvconf.conf ]; then
239
	/bin/rm -rf /etc/resolvconf.conf
240
	/bin/ln -s /var/etc/resolvconf.conf /etc/resolvconf.conf
241
fi
242

    
243
# Setup compatibility link for packages that
244
# have trouble overriding the PREFIX configure
245
# argument since we build our packages in a
246
# separated PREFIX area
247
# Only create if symlink does not exist.
248
if [ ! -h /tmp/tmp ]; then
249
	/bin/ln -hfs / /tmp/tmp
250
fi
251

    
252
# Make sure our /tmp is 777 + Sticky
253
/bin/chmod 1777 /tmp
254

    
255
# Malloc debugging check
256
if [ -L /etc/malloc.conf ]; then
257
	#ln -s aj /etc/malloc.conf
258
	/bin/rm /etc/malloc.conf
259
fi
260

    
261
if [ ! -L /etc/dhclient.conf ]; then
262
	/bin/rm -rf /etc/dhclient.conf
263
fi
264

    
265
if [ ! -d /var/tmp ]; then
266
	/bin/mkdir -p /var/tmp
267
fi
268

    
269
set -T
270
trap "echo 'Reboot interrupted'; exit 1" 3
271

    
272
# Remove old nameserver resolution files
273
/bin/rm -f /var/etc/nameserver*
274

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

    
279
DEFAULT_LOG_FILE_SIZE=$(/usr/local/sbin/read_xml_tag.sh string syslog/logfilesize)
280
DEFAULT_LOG_FILE_SIZE=${DEFAULT_LOG_FILE_SIZE:-"511488"}
281

    
282
for logfile in $LOG_FILES; do
283
	if [ "$DISABLESYSLOGCLOG" = "true" ]; then
284
		/usr/bin/touch /var/log/$logfile.log
285
	else
286
		if [ ! -f /var/log/$logfile.log ]; then
287
			/usr/local/sbin/clog -i -s ${DEFAULT_LOG_FILE_SIZE} /var/log/$logfile.log
288
		fi
289
	fi
290
done
291

    
292
# change permissions on newly created log files.
293
/bin/chmod 0600 /var/log/*.log
294

    
295
echo -n "."
296
DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
297
if [ "$DEVFS" = "0" ]; then
298
	mount_devfs devfs /dev
299
fi
300

    
301
# Create an initial utmp file
302
cd $varrunpath && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
303

    
304
echo -n "."
305
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
306
/etc/rc.d/ldconfig start 2>/dev/null
307

    
308
# Launching kbdmux(4)
309
if [ -f "/dev/kbdmux0" ]; then
310
	echo -n "."
311
	/usr/sbin/kbdcontrol -k /dev/kbdmux0 < /dev/console
312
	[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
313
	[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
314
fi
315

    
316
# Fire up unionfs if mount points exist.
317
if [ -f /dist/uniondirs ]; then
318
	echo -n "."
319
	/etc/rc.d/unionfs start
320
fi
321

    
322
echo "done."
323

    
324
# Recreate capabilities DB
325
/usr/bin/cap_mkdb /etc/login.conf
326

    
327
# Second upgrade stage
328
/usr/local/sbin/${product}-upgrade -y -b 2
329

    
330
# Copy default openssl config file
331
[ -d /etc/ssl ] \
332
	|| mkdir -p /etc/ssl
333
[ -f /usr/local/share/${product}/ssl/openssl.cnf ] \
334
	&& cp -f /usr/local/share/${product}/ssl/openssl.cnf /etc/ssl
335
mkdir -p /usr/local/openssl >/dev/null 2>&1
336
ln -sf /etc/ssl/openssl.cnf \
337
	/usr/local/openssl/openssl.cnf
338

    
339
# Run the php.ini setup file and populate
340
# /usr/local/etc/php.ini
341
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
342
/usr/local/sbin/php-fpm -c /usr/local/etc/php.ini -y /usr/local/lib/php-fpm.conf -RD 2>&1 >/dev/null
343

    
344
# Launch external configuration loader
345
/usr/local/sbin/fcgicli -f /etc/ecl.php
346

    
347
if [ -f /etc/rc.custom_boot_early ]; then
348
	/bin/echo -n "Launching /etc/rc.custom_boot_early...";
349
	/etc/rc.custom_boot_early
350
	echo "Done"
351
fi
352

    
353
export fcgipath=/var/run/php-fpm.socket
354
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
355

    
356
# let the PHP-based configuration subsystem set up the system now
357
echo -n "Launching the init system..."
358
/bin/rm -f /cf/conf/backup/backup.cache
359
/usr/bin/touch $varrunpath/booting
360

    
361
# Copy custom logo over if it's present
362
if [ -d /usr/local/share/${product}/custom_logos ]; then
363
	cp -f /usr/local/share/${product}/custom_logos/*png \
364
		/usr/local/www
365
fi
366

    
367
/etc/rc.bootup
368

    
369
# /etc/rc.bootup unset $g['booting'], and removes file
370
# Be sure the file is removed to not create troubles after
371
if [ -f $varrunpath/booting ]; then
372
	/bin/rm $varrunpath/booting
373
fi
374

    
375
echo -n "Starting CRON... "
376
cd /tmp && /usr/sbin/cron -s 2>/dev/null
377
echo "done."
378

    
379
# Start packages
380
/usr/local/sbin/fcgicli -f /etc/rc.start_packages
381

    
382
/bin/rm -rf /usr/local/pkg/pf/CVS
383

    
384
# Start ping handler every 240 seconds
385
/usr/local/bin/minicron 240 $varrunpath/ping_hosts.pid /usr/local/bin/ping_hosts.sh
386

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

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

    
393
/bin/chmod a+rw /tmp/.
394

    
395
# Check for GEOM mirrors
396
GMIRROR_STATUS=`/sbin/gmirror status`
397
if [ "${GMIRROR_STATUS}" != "" ]; then
398
	# Using a flag file at bootup saves an expensive exec/check on each page load.
399
	/usr/bin/touch /var/run/gmirror_active
400
	# Setup monitoring/notifications
401
	/usr/local/bin/minicron 60 /var/run/gmirror_status_check.pid /usr/local/sbin/gmirror_status_check.php
402
fi
403

    
404
/usr/local/sbin/${product}-upgrade -y -b 3
405

    
406
# Log product version to syslog
407
BUILDTIME=`cat /etc/version.buildtime`
408
ARCH=`uname -m`
409
echo "$product ${version}${version_patch} $ARCH $BUILDTIME"
410

    
411
echo "Bootup complete"
412

    
413
/usr/local/bin/beep.sh start 2>&1 >/dev/null
414

    
415
# Reset the cache.  read-only requires this.
416
/bin/rm -f /tmp/config.cache
417

    
418
exit 0
(10-10/76)