Project

General

Profile

Download (10.8 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 -F -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 -F
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 -yF
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 3 ]; do
102
	/sbin/fsck -yF
103
	/sbin/mount -a 2>/dev/null
104
	mount_rc=$?
105
	attempts=$((attempts+1))
106
done
107

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

    
122
# If /conf is a directory, convert it to a symlink to /cf/conf
123
if [ -d "/conf" ]; then
124
	# If item is not a symlink then rm and recreate
125
	CONFPOINTSTO=`readlink /conf`
126
	if ! test "x$CONFPOINTSTO" = "x/cf/conf"; then
127
		/bin/rm -rf /conf
128
		/bin/ln -s /cf/conf /conf
129
	fi
130
fi
131

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

    
151
if [ "${USE_MFS_TMPVAR}" = "true" ]; then
152
	/etc/rc.embedded
153
fi
154

    
155
if [ -n "${MOVE_PKG_DATA}" -o "${USE_MFS_TMPVAR}" = "true" ]; then
156
	/bin/mkdir -p /var/db /var/cache
157
	ln -sf ../../root/var/db/pkg /var/db/pkg
158
	ln -sf ../../root/var/cache/pkg /var/cache/pkg
159
fi
160

    
161
# Restore contents of the RAM disk store
162
/etc/rc.restore_ramdisk_store
163

    
164
# Make sure /home exists
165
[ -d /home ] \
166
	|| mkdir /home
167

    
168
/bin/rm -f /root/force_fsck
169
/bin/rm -f /root/TRIM_set
170
/bin/rm -f /root/TRIM_unset
171

    
172
# Disable APM on ATA drives. Leaving this on will kill drives long-term, especially laptop drives, by generating excessive Load Cycles.
173
if [ -f /etc/rc.disable_hdd_apm ]; then
174
	/etc/rc.disable_hdd_apm
175
fi
176

    
177
# Eject CD devices on 3G modems
178
MANUFACTURER="huawei|zte"
179
CDDEVICE=`dmesg |egrep -ie "($MANUFACTURER)" | awk -F: '/cd/ {print $1}'`
180
if [ "$CDDEVICE" != "" ]; then
181
	cdcontrol -f /dev/"$CDDEVICE" eject
182
fi
183

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

    
187
if [ "${USE_MFS_TMPVAR}" != "true" ]; then
188
	/sbin/mdmfs -S -M -s 4m md $varrunpath
189
fi
190

    
191
echo
192
cat /usr/local/share/pfSense/ascii-art/pfsense-logo-small.txt
193
echo
194
echo
195
echo "Welcome to ${product} ${version}${version_patch}..."
196
echo
197

    
198
/sbin/conscontrol mute off >/dev/null
199

    
200
SWAPDEVICE=`/bin/cat /etc/fstab | /usr/bin/grep swap | /usr/bin/cut -f1`
201
/sbin/swapon -a 2>/dev/null >/dev/null
202
/etc/rc.savecore
203

    
204
# make some directories in /var
205
/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
206
chmod 0555 /var/empty
207
/bin/rm -rf $varrunpath/*
208

    
209
# Cleanup configuration files from previous instance
210
/bin/rm -rf /var/etc/*
211

    
212
# Workaround for ipsec symlinks, otherwise it's going to break
213
# strongswan pkg upgrade
214

    
215
if [ -L /usr/local/etc/ipsec.d ]; then
216
	rm -f /usr/local/etc/ipsec.d
217
fi
218
if [ -L /usr/local/etc/ipsec.conf ]; then
219
	rm -f /usr/local/etc/ipsec.conf
220
fi
221
if [ -L /usr/local/etc/strongswan.d ]; then
222
	rm -f /usr/local/etc/strongswan.d
223
fi
224
if [ -L /usr/local/etc/strongswan.conf ]; then
225
	rm -f /usr/local/etc/strongswan.conf
226
fi
227

    
228
# Remove deprecated symlinks - #5538
229
for f in /etc/hosts \
230
    /etc/resolv.conf \
231
    /etc/resolvconf.conf \
232
    /etc/syslog.conf; do
233
	if [ -L "${f}" ]; then
234
		rm -f ${f}
235
	fi
236
done
237

    
238
# Make sure our /tmp is 777 + Sticky
239
/bin/chmod 1777 /tmp
240

    
241
if [ ! -L /etc/dhclient.conf ]; then
242
	/bin/rm -rf /etc/dhclient.conf
243
fi
244

    
245
if [ ! -d /var/tmp ]; then
246
	/bin/mkdir -p /var/tmp
247
fi
248

    
249
set -T
250
trap "echo 'Reboot interrupted'; exit 1" 3
251

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

    
256
DEFAULT_LOG_FILE_SIZE=$(/usr/local/sbin/read_xml_tag.sh string syslog/logfilesize)
257
DEFAULT_LOG_FILE_SIZE=${DEFAULT_LOG_FILE_SIZE:-"511488"}
258

    
259
for logfile in $LOG_FILES; do
260
	if [ "$DISABLESYSLOGCLOG" = "true" ]; then
261
		/usr/bin/touch /var/log/$logfile.log
262
	else
263
		if [ ! -f /var/log/$logfile.log ]; then
264
			/usr/local/sbin/clog -i -s ${DEFAULT_LOG_FILE_SIZE} /var/log/$logfile.log
265
		fi
266
	fi
267
done
268

    
269
# change permissions on newly created log files.
270
/bin/chmod 0600 /var/log/*.log
271

    
272
echo -n "."
273
DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
274
if [ "$DEVFS" = "0" ]; then
275
	mount_devfs devfs /dev
276
fi
277

    
278
# Create an initial utmp file
279
cd $varrunpath && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
280

    
281
echo -n "."
282
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
283
/etc/rc.d/ldconfig start 2>/dev/null
284

    
285
# Launching kbdmux(4)
286
if [ -f "/dev/kbdmux0" ]; then
287
	echo -n "."
288
	/usr/sbin/kbdcontrol -k /dev/kbdmux0 < /dev/console
289
	[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
290
	[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
291
fi
292

    
293
# Fire up unionfs if mount points exist.
294
if [ -f /dist/uniondirs ]; then
295
	echo -n "."
296
	/etc/rc.d/unionfs start
297
fi
298

    
299
echo "done."
300

    
301
# Recreate capabilities DB
302
/usr/bin/cap_mkdb /etc/login.conf
303

    
304
# Second upgrade stage
305
/usr/local/sbin/${product}-upgrade -y -b 2
306

    
307
# Copy default openssl config file
308
[ -d /etc/ssl ] \
309
	|| mkdir -p /etc/ssl
310
[ -f /usr/local/share/${product}/ssl/openssl.cnf ] \
311
	&& cp -f /usr/local/share/${product}/ssl/openssl.cnf /etc/ssl
312
mkdir -p /usr/local/openssl >/dev/null 2>&1
313
ln -sf /etc/ssl/openssl.cnf \
314
	/usr/local/openssl/openssl.cnf
315

    
316
# Run the php.ini setup file and populate
317
# /usr/local/etc/php.ini
318
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
319
/usr/local/sbin/php-fpm -c /usr/local/etc/php.ini -y /usr/local/lib/php-fpm.conf -RD 2>&1 >/dev/null
320

    
321
# Launch external configuration loader
322
/usr/local/sbin/fcgicli -f /etc/ecl.php
323

    
324
if [ -f /etc/rc.custom_boot_early ]; then
325
	/bin/echo -n "Launching /etc/rc.custom_boot_early...";
326
	/etc/rc.custom_boot_early
327
	echo "Done"
328
fi
329

    
330
export fcgipath=/var/run/php-fpm.socket
331
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
332

    
333
# let the PHP-based configuration subsystem set up the system now
334
echo -n "Launching the init system..."
335
/bin/rm -f /cf/conf/backup/backup.cache
336
/usr/bin/touch $varrunpath/booting
337

    
338
# Copy custom logo over if it's present
339
if [ -d /usr/local/share/${product}/custom_logos ]; then
340
	cp -f /usr/local/share/${product}/custom_logos/*png \
341
		/usr/local/www
342
fi
343

    
344
/etc/rc.bootup
345

    
346
# /etc/rc.bootup unset $g['booting'], and removes file
347
# Be sure the file is removed to not create troubles after
348
if [ -f $varrunpath/booting ]; then
349
	/bin/rm $varrunpath/booting
350
fi
351

    
352
echo -n "Starting CRON... "
353
cd /tmp && /usr/sbin/cron -s 2>/dev/null
354
echo "done."
355

    
356
# Start packages
357
/usr/local/sbin/fcgicli -f /etc/rc.start_packages
358

    
359
/bin/rm -rf /usr/local/pkg/pf/CVS
360

    
361
# Start ping handler every 240 seconds
362
/usr/local/bin/minicron 240 $varrunpath/ping_hosts.pid /usr/local/bin/ping_hosts.sh
363

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

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

    
370
/bin/chmod a+rw /tmp/.
371

    
372
# Check for GEOM mirrors
373
GMIRROR_STATUS=`/sbin/gmirror status`
374
if [ "${GMIRROR_STATUS}" != "" ]; then
375
	# Using a flag file at bootup saves an expensive exec/check on each page load.
376
	/usr/bin/touch /var/run/gmirror_active
377
	# Setup monitoring/notifications
378
	/usr/local/bin/minicron 60 /var/run/gmirror_status_check.pid /usr/local/sbin/gmirror_status_check.php
379
fi
380

    
381
/usr/local/sbin/${product}-upgrade -y -b 3
382

    
383
# Log product version to syslog
384
BUILDTIME=`cat /etc/version.buildtime`
385
ARCH=`uname -m`
386
echo "$product ${version}${version_patch} $ARCH $BUILDTIME"
387

    
388
echo "Bootup complete"
389

    
390
/usr/local/bin/beep.sh start 2>&1 >/dev/null
391

    
392
# Reset the cache.  read-only requires this.
393
/bin/rm -f /tmp/config.cache
394

    
395
exit 0
(11-11/78)