Projet

Général

Profil

Télécharger (12,4 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / etc / rc @ 1a7ed9d0

1
#!/bin/sh
2

    
3
# $Id$
4

    
5
# /etc/rc - master bootup script, invokes php setup
6
# part of pfSense by Scott Ullrich
7
# Copyright (C) 2004-2010 Scott Ullrich, All rights reserved.
8
# originally based on m0n0wall (http://neon1.net/m0n0wall)
9
# Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
# All rights reserved.
11

    
12
#/bin/stty status '^T'
13
#/bin/stty susp '^-' intr '^-' quit '^-'
14

    
15
#trap : 2
16
#trap : 3
17

    
18
HOME=/
19
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
20
export HOME PATH
21

    
22
# Set our operating platform
23
PLATFORM=`/bin/cat /etc/platform`
24

    
25
# Set our current version
26
version=`/bin/cat /etc/version`
27

    
28
# Setup dumpdev/ddb/savecore"
29
echo "Configuring crash dumps..."
30
if [ "$PLATFORM" = "pfSense" ]; then
31
	/etc/rc.dumpon
32
fi
33

    
34
if [ -e /root/force_fsck ]; then
35
	echo "Forcing filesystem check..."
36
	/sbin/fsck -y -t ufs /
37
	if [ "$PLATFORM" = "nanobsd" ]; then
38
		/sbin/fsck -y -t ufs /cf
39
	fi
40
fi
41

    
42
if [ "${PLATFORM}" = "nanobsd" ]; then
43
	kldstat -qm zfs
44
	if [ $? = 0 ]; then
45
		kldunload zfs
46
	fi
47
fi
48

    
49
# Mount memory file system if it exists
50
echo "Mounting filesystems..."
51

    
52
kldstat -qm zfs
53
# Handle ZFS read-only case
54
if [ "$PLATFORM" = "pfSense" ]; then
55
	kldstat -qm zfs
56
	if [ $? = 0 ]; then
57
		ZFSFSAVAILABLE=$(/sbin/zfs mount 2>/dev/null | wc -l)
58
		if [ $ZFSAVAILABLE -eq 0 ]; then
59
			kldunload zfs
60
		elif [ -f /usr/bin/grep ]; then
61
			ZFSROOT=`/sbin/zfs mount | /usr/bin/grep ' /$' | /usr/bin/cut -d ' ' -f 1`
62
			if [ "$ZFSROOT" != "" ]; then
63
				/sbin/zfs set readonly=off $ZFSROOT
64
			fi
65
		fi
66
	fi
67
fi
68

    
69
if [ "${PLATFORM}" = "cdrom" ]; then
70
	/etc/rc.cdrom
71
else
72
	# Mount /. If it fails run a fsck.
73
	if [ "$PLATFORM" = "nanobsd" ]; then
74
		export PKG_TMPDIR=/root/
75
		/sbin/mount -uw / 2>/dev/null
76
		mount_rc=$?
77
		attempts=0
78
		while [ ${mount_rc} != 0 -a ${attempts} -lt 3 ]; do
79
			/sbin/fsck -y /
80
			/sbin/fsck -y /cf
81
			/sbin/mount -uw / 2>/dev/null
82
			mount_rc=$?
83
			attempts=$((attempts+1))
84
		done
85
	else
86
		/sbin/mount -a 2>/dev/null
87
		mount_rc=$?
88
		attempts=0
89
		while [ ${mount_rc} != 0 -a ${attempts} -lt 3 ]; do
90
			/sbin/fsck -y /
91
			/sbin/mount -a 2>/dev/null
92
			mount_rc=$?
93
			attempts=$((attempts+1))
94
		done
95
	fi
96

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

    
107
	if [ ! "$PLATFORM" = "jail" ]; then
108
		# Check to see if a compact flash mountpoint exists
109
		# If it fails to mount then run a fsck -y
110
		if grep -q cf /etc/fstab; then
111
			/sbin/mount -w /cf 2>/dev/null
112
			/sbin/mount -uw /cf 2>/dev/null
113
			mount_rc=$?
114
			attempts=0
115
			while [ ${mount_rc} != 0 -a ${attempts} -lt 3 ]; do
116
				/sbin/umount /cf
117
				/sbin/fsck -y /cf
118
				/sbin/mount -w /cf 2>/dev/null
119
				mount_rc=$?
120
				attempts=$((attempts+1))
121
			done
122
		fi
123
	fi
124

    
125
	USE_MFS_TMPVAR=`/usr/bin/grep -c use_mfs_tmpvar /cf/conf/config.xml`
126
	if [ "${PLATFORM}" = "nanobsd" ] || [ ${USE_MFS_TMPVAR} -gt 0 ]; then
127
		/etc/rc.embedded
128
	fi
129
fi
130

    
131
/bin/rm -f /root/force_fsck
132
/bin/rm -f /root/TRIM_set
133
/bin/rm -f /root/TRIM_unset
134

    
135
# Disable APM on ATA drives. Leaving this on will kill drives long-term, especially laptop drives, by generating excessive Load Cycles.
136
if [ -f /etc/rc.disable_hdd_apm ]; then
137
	/etc/rc.disable_hdd_apm
138
fi
139

    
140
#Eject CD devices on 3G modems
141
MANUFACTURER="huawei|zte"
142
CDDEVICE=`dmesg |egrep -ie "($MANUFACTURER)" | awk -F: '/cd/ {print $1}'`
143
if [ "$CDDEVICE" != "" ]; then
144
	cdcontrol -f /dev/"$CDDEVICE" eject
145
fi
146

    
147
# sync pw database after mount.
148
rm -f /etc/spwd.db.tmp
149
/usr/sbin/pwd_mkdb -d /etc/ /etc/master.passwd
150

    
151
product=`/usr/bin/grep product_name /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
152
hideplatform=`/usr/bin/grep hideplatform /etc/inc/globals.inc | /usr/bin/wc -l`
153
varrunpath=`/usr/bin/grep varrun_path /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
154

    
155
if [ "$PLATFORM" = "pfSense" ] && [ ${USE_MFS_TMPVAR} -eq 0 ]; then
156
	/sbin/mdmfs -S -M -s 4m md $varrunpath
157
fi
158

    
159
if [ "$hideplatform" -gt "0" ]; then
160
	platformbanner="" # hide the platform
161
else
162
	platformbanner=" on the '${PLATFORM}' platform"
163
fi
164

    
165
echo
166
cat /etc/ascii-art/pfsense-logo-small.txt
167
echo
168
echo
169
echo "Welcome to ${product} ${version} ${platformbanner} ..."
170
echo
171

    
172
if [ ! "$PLATFORM" = "jail" ]; then
173
	# Enable console output if its muted.
174
	/sbin/conscontrol mute off >/dev/null
175
fi
176

    
177
if [ "$PLATFORM" = "cdrom" ] ; then
178
	# do nothing for cdrom platform
179
elif [ "$PLATFORM" = "nanobsd" ] || [ ${USE_MFS_TMPVAR} -gt 0 ]; then
180
	# Ensure that old-style PKG packages can be persistent across reboots
181
	/bin/mkdir -p /root/var/db/pkg
182
	/bin/rm -rf /var/db/pkg
183
	/bin/ln -s /root/var/db/pkg/ /var/db/pkg
184
	# Ensure that PBI packages can be persistent across reboots
185
	/bin/mkdir -p /root/var/db/pbi
186
	/bin/rm -rf /var/db/pbi
187
	/bin/ln -s /root/var/db/pbi/ /var/db/pbi
188
elif [ "$PLATFORM" = "jail" ]; then
189
	# do nothing for jail platform
190
else
191
	SWAPDEVICE=`/bin/cat /etc/fstab | /usr/bin/grep swap | /usr/bin/cut -f1`
192
	/sbin/swapon -a 2>/dev/null >/dev/null
193
	/etc/rc.savecore
194

    
195
	if [ -d /root/var/db/pkg ]; then
196
		# User must have just disabled RAM disks, move these back into place.
197
		/bin/mkdir -p /var/db/pkg
198
		/bin/mv /root/var/db/pkg /var/db/pkg
199
		/bin/mkdir -p /var/db/pbi
200
		/bin/mv /root/var/db/pkg /var/db/pbi
201
	fi
202
fi
203

    
204
if [ "$PLATFORM" = "cdrom" ] ; then
205
	echo -n "Mounting unionfs directories..."
206
	/bin/mkdir /tmp/unionfs
207
	/bin/mkdir /tmp/unionfs/usr
208
	/bin/mkdir /tmp/unionfs/root
209
	/bin/mkdir /tmp/unionfs/sbin
210
	/bin/mkdir /tmp/unionfs/bin
211
	/bin/mkdir /tmp/unionfs/boot
212
	/bin/mkdir /tmp/unionfs/confdefault
213
	/sbin/mount_unionfs /tmp/unionfs/usr /usr/
214
	/sbin/mount_unionfs /tmp/unionfs/root /root/
215
	/sbin/mount_unionfs /tmp/unionfs/bin /bin/		
216
	/sbin/mount_unionfs /tmp/unionfs/sbin /sbin/	
217
	/sbin/mount_unionfs /tmp/unionfs/boot /boot/
218
	/sbin/mount_unionfs /tmp/unionfs/confdefault /conf.default/
219
	echo "done."
220
fi
221

    
222
# make some directories in /var
223
/bin/mkdir -p $varrunpath /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
224
/bin/rm -rf $varrunpath/*
225
if [ "$PLATFORM" != "pfSense" ]; then
226
	/bin/rm /var/log/* 2>/dev/null
227
fi
228

    
229
# Cleanup configuration files from previous instance
230
/bin/rm -rf /var/etc/*
231
/bin/rm -rf /var/tmp/*
232

    
233
echo -n "Creating symlinks..."
234
# Make sure symlink is correct on nanobsd
235
if [ "$PLATFORM" = "nanobsd" ] ; then
236
	/bin/rm /conf
237
	/bin/ln -s /cf/conf/ /conf
238
fi
239

    
240
# Repair symlinks if they are broken
241
if [ -f /etc/newsyslog.conf ]; then
242
	/bin/rm -f /etc/newsyslog.conf
243
fi
244
if [ ! -L /etc/syslog.conf ]; then
245
	/bin/rm -rf /etc/syslog.conf
246
	if [ ! -f /var/etc/syslog.conf ]; then
247
		touch /var/etc/syslog.conf
248
	fi
249
	/bin/ln -s /var/etc/syslog.conf /etc/syslog.conf
250
fi
251

    
252
# Repair symlinks if they are broken
253
if [ ! -L /etc/hosts ]; then
254
	/bin/rm -rf /etc/hosts
255
	/bin/ln -s /var/etc/hosts /etc/hosts
256
fi
257

    
258
if [ ! -L /etc/resolv.conf ]; then
259
    /bin/rm -rf /etc/resolv.conf
260
    /bin/ln -s /var/etc/resolv.conf /etc/resolv.conf
261
fi
262

    
263
# Setup compatibility link for packages that
264
# have trouble overriding the PREFIX configure
265
# argument since we build our packages in a
266
# separated PREFIX area
267
# Only create if symlink does not exist. 
268
if [ ! -h /tmp/tmp ]; then
269
    /bin/ln -hfs / /tmp/tmp
270
fi
271

    
272
# Make sure our /tmp is 777 + Sticky
273
if [ ! "$PLATFORM" = "cdrom" ] ; then
274
	/bin/rm -rf /tmp/*
275
fi
276
/bin/chmod 1777 /tmp
277

    
278
if [ ! "$PLATFORM" = "cdrom" ] ; then
279
	# Malloc debugging check
280
	if [ -L /etc/malloc.conf ]; then
281
	    #ln -s aj /etc/malloc.conf
282
		/bin/rm /etc/malloc.conf
283
	fi
284
fi
285

    
286
if [ ! -L /etc/dhclient.conf ]; then
287
    /bin/rm -rf /etc/dhclient.conf
288
fi
289

    
290
if [ ! -d /var/tmp ]; then
291
	/bin/mkdir -p /var/tmp
292
fi
293

    
294
if [ ! -d /cf/conf/backup/ ]; then
295
	/bin/mkdir -p /cf/conf/backup/ 
296
fi
297

    
298
set -T
299
trap "echo 'Reboot interrupted'; exit 1" 3
300

    
301
# Remove old nameserver resolution files
302
/bin/rm -f /var/etc/nameserver*
303

    
304
# Create uploadbar tmp directory
305
/bin/mkdir -p /tmp/uploadbar
306
/bin/chmod 0777 /tmp/uploadbar
307

    
308
echo -n "."
309
DISABLESYSLOGCLOG=`/usr/bin/grep -c disablesyslogclog /cf/conf/config.xml`
310
ENABLEFIFOLOG=`/usr/bin/grep -c usefifolog /cf/conf/config.xml`
311
LOG_FILES="system filter dhcpd vpn pptps poes l2tps openvpn portalauth ipsec ppp relayd wireless lighttpd ntpd gateways resolver routing"
312

    
313
DEFAULT_LOG_FILE_SIZE=`/usr/local/bin/xmllint --xpath 'string(//pfsense/syslog/logfilesize)' /conf/config.xml`
314
if [ ! ${DEFAULT_LOG_FILE_SIZE} ]; then
315
	DEFAULT_LOG_FILE_SIZE=511488
316
fi
317

    
318
for logfile in $LOG_FILES; do
319
	if [ "$DISABLESYSLOGCLOG" -gt "0" ]; then 
320
		/usr/bin/touch /var/log/$logfile.log
321
	else 
322
		if [ ! -f /var/log/$logfile.log ]; then
323
			if [ "$ENABLEFIFOLOG" -gt "0" ]; then
324
				# generate fifolog files
325
				/usr/sbin/fifolog_create -s ${DEFAULT_LOG_FILE_SIZE} /var/log/$logfile.log
326
			else 
327
				/usr/local/sbin/clog -i -s ${DEFAULT_LOG_FILE_SIZE} /var/log/$logfile.log
328
			fi
329
		fi
330
	fi 
331
done
332

    
333
# change permissions on newly created fifolog files.
334
/bin/chmod 0600 /var/log/*.log
335

    
336
echo -n "."
337
if [ ! "$PLATFORM" = "jail" ]; then
338
	DEVFS=`/sbin/mount | /usr/bin/grep devfs | /usr/bin/wc -l | /usr/bin/cut -d" " -f8`
339
	if [ "$DEVFS" = "0" ]; then
340
		mount_devfs devfs /dev
341
	fi
342
fi
343

    
344
# Create an initial utmp file
345
cd $varrunpath && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
346

    
347
echo -n "."
348
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
349
/etc/rc.d/ldconfig start 2>/dev/null
350

    
351
# Make sure /etc/rc.conf doesn't exist.
352
if [ -f /etc/rc.conf ]; then
353
    /bin/rm -rf /etc/rc.conf
354
fi
355

    
356
if [ ! "$PLATFORM" = "jail" ]; then
357
	# Launching kbdmux(4)
358
	if [ -f "/dev/kbdmux0" ]; then
359
		echo -n "."
360
		/usr/sbin/kbdcontrol -k /dev/kbdmux0 < /dev/console
361
		[ -c "/dev/atkbd0" ] && kbdcontrol -a atkbd0 < /dev/console
362
		[ -c "/dev/ukbd0" ] && kbdcontrol -a ukbd0 < /dev/console
363
	fi
364

    
365
	# Fire up unionfs if mount points exist.
366
	if [ -f /dist/uniondirs ]; then
367
		echo -n "."
368
		/etc/rc.d/unionfs start
369
	fi
370
fi
371

    
372
echo "done."
373

    
374
# Ensure gettytab is of a sane size
375
if [ `/bin/ls -la /etc/gettytab | /usr/bin/awk '{ print $5'}` -lt 512 ]; then
376
	echo ">>> Restoring /etc/gettytab due to unusual size"
377
	echo ">>> Restoring /etc/gettytab due to unusual size" | /usr/bin/logger
378
	/bin/cp /etc/gettytab.bak /etc/gettytab
379
fi
380

    
381
# Recreate capabilities DB
382
/usr/bin/cap_mkdb /etc/login.conf
383

    
384
# Run the php.ini setup file and populate
385
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
386
/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
387
/usr/local/sbin/php-fpm -c /usr/local/lib/php.ini -y /usr/local/lib/php-fpm.conf -RD 2>&1 >/dev/null
388

    
389
# Launch external configuration loader for supported platforms
390
if [ "$PLATFORM" = "nanobsd" ]; then
391
	/usr/local/sbin/fcgicli -f /etc/ecl.php
392
fi
393

    
394
# Launch external configuration loader for supported platforms
395
if [ "$PLATFORM" = "pfSense" ]; then
396
	/usr/local/sbin/fcgicli -f /etc/ecl.php
397
fi
398

    
399
if [ -f /etc/rc.custom_boot_early ]; then
400
	/bin/echo -n "Launching /etc/rc.custom_boot_early...";
401
	/etc/rc.custom_boot_early
402
	echo "Done"
403
fi
404

    
405
export fcgipath=/var/run/php-fpm.socket
406
/usr/bin/nice -n20 /usr/local/sbin/check_reload_status
407

    
408
# let the PHP-based configuration subsystem set up the system now
409
echo -n "Launching the init system..."
410
/bin/rm -f /cf/conf/backup/backup.cache
411
/bin/rm -f /root/lighttpd*
412
/usr/bin/touch $varrunpath/booting
413
/etc/rc.bootup
414

    
415
# /etc/rc.bootup unset $g['booting'], remove file right now to be
416
# consistent
417
/bin/rm $varrunpath/booting
418

    
419
# If a shell was selected from recovery 
420
# console then just drop to the shell now.
421
if [ -f "/tmp/donotbootup" ]; then
422
	echo "Dropping to recovery shell."
423
	exit 0
424
fi
425

    
426
echo -n "Starting CRON... "
427
cd /tmp && /usr/sbin/cron -s 2>/dev/null
428
echo "done."
429

    
430
# Start packages
431
/usr/local/sbin/fcgicli -f /etc/rc.start_packages
432

    
433
/bin/rm -rf /usr/local/pkg/pf/CVS
434

    
435
# Start ping handler every 240 seconds
436
/usr/local/bin/minicron 240 $varrunpath/ping_hosts.pid /usr/local/bin/ping_hosts.sh
437

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

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

    
444
/bin/chmod a+rw /tmp/.
445

    
446
# Check for GEOM mirrors
447
GMIRROR_STATUS=`/sbin/gmirror status`
448
if [ "${GMIRROR_STATUS}" != "" ]; then
449
	# Using a flag file at bootup saves an expensive exec/check on each page load.
450
	/usr/bin/touch /var/run/gmirror_active
451
	# Setup monitoring/notifications
452
	/usr/local/bin/minicron 60 /var/run/gmirror_status_check.pid /usr/local/sbin/gmirror_status_check.php
453
fi
454

    
455
# Log product version to syslog
456
BUILDTIME=`cat /etc/version.buildtime`
457
ARCH=`uname -m`
458
echo "$product ($PLATFORM) $version $ARCH $BUILDTIME"
459

    
460
echo "Bootup complete"
461

    
462
/usr/local/bin/beep.sh start 2>&1 >/dev/null
463

    
464
# Reset the cache.  read-only requires this.
465
/bin/rm -f /tmp/config.cache
466

    
467
exit 0
(30-30/104)