Project

General

Profile

Download (11 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/${product}-ddb.conf
61
fi
62

    
63
fsck_forced_iterations=`/bin/kenv -q pfsense.fsck.force`
64
if [ ! -z "${fsck_forced_iterations}" ]; then
65
	echo "Forcing filesystem check (${fsck_forced_iterations} times)..."
66
	while [ ${fsck_forced_iterations} -gt 0 ]; do
67
		/sbin/fsck -y -t ufs
68
		fsck_forced_iterations=$((fsck_forced_iterations - 1))
69
	done
70
fi
71

    
72
if [ -e /root/force_growfs ]; then
73
	/etc/rc.d/growfs onestart
74
fi
75

    
76
FSCK_ACTION_NEEDED=0
77
/sbin/fsck -p
78
case $? in
79
0)
80
	echo "Filesystems are clean, continuing..."
81
	echo "Mounting filesystems..."
82
	;;
83
8)
84
	echo "Preen mode recommended running a check that will be performed now."
85
	FSCK_ACTION_NEEDED=1
86
	;;
87
*)
88
	echo "Stopping boot is recommended because filesystem manual action is needed, nevertheless automated repair of the filesystem will be attempted."
89
	FSCK_ACTION_NEEDED=1
90
	;;
91
esac
92

    
93
if [ ${FSCK_ACTION_NEEDED} = 1 ]; then
94
	echo "WARNING: Trying to recover filesystem from inconsistency..."
95
	/sbin/fsck -y -t ufs
96
fi
97

    
98
/sbin/mount -a 2>/dev/null
99
mount_rc=$?
100
attempts=0
101
while [ ${mount_rc} -ne 0 -a ${attempts} -lt 10 ]; do
102
	/sbin/fsck -y -t ufs
103
	/sbin/mount -a 2>/dev/null
104
	mount_rc=$?
105
	attempts=$((attempts+1))
106
done
107

    
108
if [ ${mount_rc} -ne 0 ]; then
109
	echo "ERROR: Impossible to mount filesystem, use interactive shell to attempt to recover it"
110
	/bin/sh
111
	/sbin/reboot
112
fi
113

    
114
# Handle ZFS read-only case
115
/sbin/kldstat -qm zfs
116
if [ $? -eq 0 ]; then
117
	ZFSFSAVAILABLE=$(/sbin/zfs mount 2>/dev/null | wc -l)
118
	if [ $ZFSFSAVAILABLE -eq 0 ]; then
119
		/sbin/kldunload zfs
120
	elif [ -f /usr/bin/grep ]; then
121
		ZFSROOT=`/sbin/zfs mount | /usr/bin/grep ' /$' | /usr/bin/cut -d ' ' -f 1`
122
		if [ "$ZFSROOT" != "" ]; then
123
			/sbin/zfs set readonly=off $ZFSROOT
124
		fi
125
	fi
126
fi
127

    
128
# If /conf is a directory, convert it to a symlink to /cf/conf
129
if [ -d "/conf" ]; then
130
	# If item is not a symlink then rm and recreate
131
	CONFPOINTSTO=`readlink /conf`
132
	if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then
133
		/bin/rm -rf /conf
134
		/bin/ln -s /cf/conf /conf
135
	fi
136
fi
137

    
138
USE_MFS_TMPVAR=$(/usr/local/sbin/read_xml_tag.sh boolean system/use_mfs_tmpvar)
139
unset MOVE_PKG_DATA
140
# If use MFS var is disabled, move files back to place
141
if [ "${USE_MFS_TMPVAR}" != "true" -a -f /root/var/db/pkg/local.sqlite ]; then
142
	MOVE_PKG_DATA=1
143
	rm -rf /var/db/pkg 2>/dev/null
144
	rm -rf /var/cache/pkg 2>/dev/null
145
	mv -f /root/var/db/pkg /var/db
146
	mv -f /root/var/cache/pkg /var/cache
147
# If use MFS var is enabled, move files to a safe place
148
elif [ "${USE_MFS_TMPVAR}" = "true" -a -f /var/db/pkg/local.sqlite ]; then
149
	MOVE_PKG_DATA=1
150
	rm -rf /root/var/db/pkg 2>/dev/null
151
	rm -rf /root/var/cache/pkg 2>/dev/null
152
	/bin/mkdir -p /root/var/db /root/var/cache
153
	mv -f /var/db/pkg /root/var/db
154
	mv -f /var/cache/pkg /root/var/cache
155
fi
156

    
157
if [ "${USE_MFS_TMPVAR}" = "true" ]; then
158
	/etc/rc.embedded
159
fi
160

    
161
if [ -n "${MOVE_PKG_DATA}" -o "${USE_MFS_TMPVAR}" = "true" ]; then
162
	/bin/mkdir -p /var/db /var/cache
163
	ln -sf ../../root/var/db/pkg /var/db/pkg
164
	ln -sf ../../root/var/cache/pkg /var/cache/pkg
165
fi
166

    
167
# Restore contents of the RAM disk store
168
/etc/rc.restore_ramdisk_store
169

    
170
# Make sure /home exists
171
[ -d /home ] \
172
	|| mkdir /home
173

    
174
/bin/rm -f /root/force_fsck
175
/bin/rm -f /root/TRIM_set
176
/bin/rm -f /root/TRIM_unset
177

    
178
# Disable APM on ATA drives. Leaving this on will kill drives long-term, especially laptop drives, by generating excessive Load Cycles.
179
if [ -f /etc/rc.disable_hdd_apm ]; then
180
	/etc/rc.disable_hdd_apm
181
fi
182

    
183
# Eject CD devices on 3G modems
184
MANUFACTURER="huawei|zte"
185
CDDEVICE=`dmesg |egrep -ie "($MANUFACTURER)" | awk -F: '/cd/ {print $1}'`
186
if [ "$CDDEVICE" != "" ]; then
187
	cdcontrol -f /dev/"$CDDEVICE" eject
188
fi
189

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

    
193
if [ "${USE_MFS_TMPVAR}" != "true" ]; then
194
	/sbin/mdmfs -S -M -s 4m md $varrunpath
195
fi
196

    
197
echo
198
cat /usr/local/share/pfSense/ascii-art/pfsense-logo-small.txt
199
echo
200
echo
201
echo "Welcome to ${product} ${version}${version_patch}..."
202
echo
203

    
204
/sbin/conscontrol mute off >/dev/null
205

    
206
SWAPDEVICE=`/bin/cat /etc/fstab | /usr/bin/grep swap | /usr/bin/cut -f1`
207
/sbin/swapon -a 2>/dev/null >/dev/null
208
/etc/rc.savecore
209

    
210
# make some directories in /var
211
/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
212
chmod 0555 /var/empty
213
/bin/rm -rf $varrunpath/*
214

    
215
# Cleanup configuration files from previous instance
216
/bin/rm -rf /var/etc/*
217

    
218
# Workaround for ipsec symlinks, otherwise it's going to break
219
# strongswan pkg upgrade
220

    
221
if [ -L /usr/local/etc/ipsec.d ]; then
222
	rm -f /usr/local/etc/ipsec.d
223
fi
224
if [ -L /usr/local/etc/ipsec.conf ]; then
225
	rm -f /usr/local/etc/ipsec.conf
226
fi
227
if [ -L /usr/local/etc/strongswan.d ]; then
228
	rm -f /usr/local/etc/strongswan.d
229
fi
230
if [ -L /usr/local/etc/strongswan.conf ]; then
231
	rm -f /usr/local/etc/strongswan.conf
232
fi
233

    
234
# Remove deprecated symlinks - #5538
235
for f in /etc/hosts \
236
    /etc/resolv.conf \
237
    /etc/resolvconf.conf \
238
    /etc/syslog.conf; do
239
	if [ -L "${f}" ]; then
240
		rm -f ${f}
241
	fi
242
done
243

    
244
# Make sure our /tmp is 777 + Sticky
245
/bin/chmod 1777 /tmp
246

    
247
if [ ! -L /etc/dhclient.conf ]; then
248
	/bin/rm -rf /etc/dhclient.conf
249
fi
250

    
251
if [ ! -d /var/tmp ]; then
252
	/bin/mkdir -p /var/tmp
253
fi
254
# Make sure our /var/tmp is 777 + Sticky
255
/bin/chmod 1777 /tmp
256

    
257
set -T
258
trap "echo 'Reboot interrupted'; exit 1" 3
259

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

    
264
DEFAULT_LOG_FILE_SIZE=$(/usr/local/sbin/read_xml_tag.sh string syslog/logfilesize)
265
DEFAULT_LOG_FILE_SIZE=${DEFAULT_LOG_FILE_SIZE:-"511488"}
266

    
267
for logfile in $LOG_FILES; do
268
	if [ "$DISABLESYSLOGCLOG" = "true" ]; then
269
		/usr/bin/touch /var/log/$logfile.log
270
	else
271
		if [ ! -f /var/log/$logfile.log ]; then
272
			/usr/local/sbin/clog -i -s ${DEFAULT_LOG_FILE_SIZE} /var/log/$logfile.log
273
		fi
274
	fi
275
done
276

    
277
# change permissions on newly created log files.
278
/bin/chmod 0600 /var/log/*.log
279

    
280
echo -n "."
281
DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
282
if [ "$DEVFS" = "0" ]; then
283
	mount_devfs devfs /dev
284
fi
285

    
286
# Create an initial utmp file
287
cd $varrunpath && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
288

    
289
echo -n "."
290
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
291
/etc/rc.d/ldconfig start 2>/dev/null
292

    
293
# Launching kbdmux(4)
294
if [ -f "/dev/kbdmux0" ]; then
295
	echo -n "."
296
	/usr/sbin/kbdcontrol -k /dev/kbdmux0 < /dev/console
297
	[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
298
	[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
299
fi
300

    
301
# Fire up unionfs if mount points exist.
302
if [ -f /dist/uniondirs ]; then
303
	echo -n "."
304
	/etc/rc.d/unionfs start
305
fi
306

    
307
echo "done."
308

    
309
# Recreate capabilities DB
310
/usr/bin/cap_mkdb /etc/login.conf
311

    
312
# Second upgrade stage
313
/usr/local/sbin/${product}-upgrade -y -b 2
314

    
315
# Copy default openssl config file
316
[ -d /etc/ssl ] \
317
	|| mkdir -p /etc/ssl
318
[ -f /usr/local/share/${product}/ssl/openssl.cnf ] \
319
	&& cp -f /usr/local/share/${product}/ssl/openssl.cnf /etc/ssl
320
mkdir -p /usr/local/openssl >/dev/null 2>&1
321
ln -sf /etc/ssl/openssl.cnf \
322
	/usr/local/openssl/openssl.cnf
323

    
324
# Run the php.ini setup file and populate
325
# /usr/local/etc/php.ini
326
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
327
/usr/local/sbin/php-fpm -c /usr/local/etc/php.ini -y /usr/local/lib/php-fpm.conf -RD 2>&1 >/dev/null
328

    
329
# Launch external configuration loader
330
/usr/local/sbin/fcgicli -f /etc/ecl.php
331

    
332
if [ -f /etc/rc.custom_boot_early ]; then
333
	/bin/echo -n "Launching /etc/rc.custom_boot_early...";
334
	/etc/rc.custom_boot_early
335
	echo "Done"
336
fi
337

    
338
export fcgipath=/var/run/php-fpm.socket
339
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
340

    
341
# let the PHP-based configuration subsystem set up the system now
342
echo -n "Launching the init system..."
343
/bin/rm -f /cf/conf/backup/backup.cache
344
/usr/bin/touch $varrunpath/booting
345

    
346
# Copy custom logo over if it's present
347
if [ -d /usr/local/share/${product}/custom_logos ]; then
348
	cp -f /usr/local/share/${product}/custom_logos/*png \
349
		/usr/local/www
350
fi
351

    
352
/etc/rc.bootup
353

    
354
# /etc/rc.bootup unset $g['booting'], and removes file
355
# Be sure the file is removed to not create troubles after
356
if [ -f $varrunpath/booting ]; then
357
	/bin/rm $varrunpath/booting
358
fi
359

    
360
echo -n "Starting CRON... "
361
cd /tmp && /usr/sbin/cron -s 2>/dev/null
362
echo "done."
363

    
364
# Start packages
365
/usr/local/sbin/fcgicli -f /etc/rc.start_packages
366

    
367
/bin/rm -rf /usr/local/pkg/pf/CVS
368

    
369
# Start ping handler every 240 seconds
370
/usr/local/bin/minicron 240 $varrunpath/ping_hosts.pid /usr/local/bin/ping_hosts.sh
371

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

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

    
378
/bin/chmod a+rw /tmp/.
379

    
380
# Check for GEOM mirrors
381
GMIRROR_STATUS=`/sbin/gmirror status`
382
if [ "${GMIRROR_STATUS}" != "" ]; then
383
	# Using a flag file at bootup saves an expensive exec/check on each page load.
384
	/usr/bin/touch /var/run/gmirror_active
385
	# Setup monitoring/notifications
386
	/usr/local/bin/minicron 60 /var/run/gmirror_status_check.pid /usr/local/sbin/gmirror_status_check.php
387
fi
388

    
389
/usr/local/sbin/${product}-upgrade -y -b 3
390

    
391
# Log product version to syslog
392
BUILDTIME=`cat /etc/version.buildtime`
393
ARCH=`uname -m`
394
echo "$product ${version}${version_patch} $ARCH $BUILDTIME"
395

    
396
echo "Bootup complete"
397

    
398
/usr/local/bin/beep.sh start 2>&1 >/dev/null
399

    
400
# Reset the cache.  read-only requires this.
401
/bin/rm -f /tmp/config.cache
402

    
403
exit 0
(11-11/78)