Project

General

Profile

Download (9.96 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php -f
2
<?php
3 1b8df11b Bill Marquette
/* $Id$ */
4 5b237745 Scott Ullrich
/*
5
	rc.bootup
6 e5cd29a0 Scott Ullrich
	part of pfSense by Scott Ullrich
7
	originally based on m0n0wall (http://m0n0.ch/wall)
8 70045f5f Scott Ullrich
	Copyright (C) 2004-2009 Scott Ullrich <sullrich@pfsense.org>.
9 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10 745188c8 Scott Ullrich
	Copyright (C) 2009 Erik Kristensen
11 5b237745 Scott Ullrich
	All rights reserved.
12 e5cd29a0 Scott Ullrich
13 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15 e5cd29a0 Scott Ullrich
16 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18 e5cd29a0 Scott Ullrich
19 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
20
	   notice, this list of conditions and the following disclaimer in the
21
	   documentation and/or other materials provided with the distribution.
22 e5cd29a0 Scott Ullrich
23 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33
*/
34
35 6cc9e241 Scott Ullrich
function rescue_detect_keypress() {
36
	// How long do you want the script to wait before moving on (in seconds)
37 1e4e8458 Scott Ullrich
	$timeout=9;
38 41d07e42 Scott Ullrich
	echo "\n";
39 6c616b93 Scott Ullrich
    echo "[ Press R to enter recovery mode or ]\n";
40
	echo "[  press I to launch the installer  ]\n\n";
41 1e4e8458 Scott Ullrich
	echo "(R)ecovery mode can assist by rescuing config.xml\n";
42 e5a06994 Scott Ullrich
	echo "from a broken hard disk installation, etc.\n\n";
43 1e4e8458 Scott Ullrich
	echo "Alternatively the (I)nstaller may be invoked now if you do \n";
44 5b051819 Scott Ullrich
	echo "not wish to boot into the liveCD environment at this time.\n\n";
45 1e4e8458 Scott Ullrich
	echo "Timeout before auto boot continues (seconds): {$timeout}";
46 6cc9e241 Scott Ullrich
	$key = null;
47 1e4e8458 Scott Ullrich
	exec("/bin/stty erase " . chr(8));
48 68235416 Scott Ullrich
	while(!in_array($key, array("r","R", "i", "I", "~", "!"))) {
49 1e4e8458 Scott Ullrich
	        echo chr(8) . "{$timeout}";
50 e5a06994 Scott Ullrich
	        `/bin/stty -icanon min 0 time 25`;
51 6cc9e241 Scott Ullrich
	        $key = trim(`KEY=\`dd count=1 2>/dev/null\`; echo \$KEY`);
52 2eeb1781 Scott Ullrich
	        `/bin/stty icanon`;
53 6cc9e241 Scott Ullrich
	        // Decrement our timeout value
54
	        $timeout--;
55
	        // If we have reached 0 exit and continue on
56 70045f5f Scott Ullrich
	        if ($timeout == 0) 
57
				break;
58 6cc9e241 Scott Ullrich
	}
59 540bd313 Scott Ullrich
	// If R or I was pressed do our logic here
60 70045f5f Scott Ullrich
	if (in_array($key, array("r", "R"))) {
61 68235416 Scott Ullrich
	  putenv("TERM=cons25");
62
	  echo "\n\nRecovery mode selected...\n";
63 f98d3d65 Scott Ullrich
	  passthru("/usr/bin/env TERM=cons25 /bin/tcsh -c /scripts/lua_installer_rescue");
64 d5116ed5 Scott Ullrich
	} elseif (in_array($key, array("i", "I"))) {
65 68235416 Scott Ullrich
	  putenv("TERM=cons25");  
66
	  echo "\n\nInstaller mode selected...\n";
67 f98d3d65 Scott Ullrich
	  passthru("/usr/bin/env TERM=cons25 /bin/tcsh -c /scripts/lua_installer");
68 c1da5030 Scott Ullrich
	  if(file_exists("/tmp/install_complete")) {
69 f98d3d65 Scott Ullrich
		passthru("/etc/rc.reboot");
70 c1da5030 Scott Ullrich
		exit;
71
	  }
72
	} elseif (in_array($key, array("!", "~"))) {
73 68235416 Scott Ullrich
 		putenv("TERM=cons25");
74
		echo "\n\nRecovery shell selected...\n";
75 6c616b93 Scott Ullrich
		echo "\n";
76 c1da5030 Scott Ullrich
		touch("/tmp/donotbootup");
77
		exit;
78 01ef30e9 Scott Ullrich
	} else {
79
		echo "\n\n";
80 745188c8 Scott Ullrich
	}
81 6cc9e241 Scott Ullrich
}
82
83
echo " done.\n";
84
85
echo "Initializing...";
86
echo ".";
87
require_once("/etc/inc/globals.inc");
88 483e6de8 Scott Ullrich
echo ".";
89 00a4146e jim-p
require_once("/etc/inc/led.inc");
90
led_normalize();
91 483e6de8 Scott Ullrich
echo ".";
92 00a4146e jim-p
if (led_count() >= 3) {
93
	led_kitt();
94
}
95 483e6de8 Scott Ullrich
96 6cc9e241 Scott Ullrich
/* let the other functions know we're booting */
97
$pkg_interface = 'console';
98 410cdac4 Scott Ullrich
$g['booting'] = true;
99 6cc9e241 Scott Ullrich
touch("{$g['varrun_path']}/booting");
100
101
/* parse the configuration and include all functions used below */
102
require_once("/etc/inc/config.inc");
103
echo ".";
104 3066a36f Ermal Lu?i
require_once("/etc/inc/auth.inc");
105
echo ".";
106 6cc9e241 Scott Ullrich
require_once("/etc/inc/functions.inc");
107 62d93213 Scott Ullrich
echo ".";
108 5f2d078e Scott Ullrich
require("/etc/inc/filter.inc");
109
echo ".";
110
require("/etc/inc/shaper.inc");
111
echo ".";
112 483e6de8 Scott Ullrich
require_once("/etc/inc/ipsec.inc");
113
echo ".";
114
require_once("/etc/inc/vpn.inc");
115
echo ".";
116 5f2d078e Scott Ullrich
require_once("/etc/inc/openvpn.inc");
117 62d93213 Scott Ullrich
echo ".";
118 483e6de8 Scott Ullrich
require_once("/etc/inc/captiveportal.inc");
119
echo ".";
120
require_once("/etc/inc/rrd.inc");
121
echo ".";
122 62d93213 Scott Ullrich
123 6cc9e241 Scott Ullrich
/* get system memory amount */
124
$memory = get_memory();
125
$avail = $memory[0];
126
echo " done.\n";
127
128
conf_mount_rw();
129
130
/* remove previous firmware upgrade if present */
131
if (file_exists("/root/firmware.tgz")) 
132
	unlink("/root/firmware.tgz");
133
134
/* start devd (dhclient now uses it */
135
echo "Starting device manager (devd)...";
136
mute_kernel_msgs();
137
start_devd();
138
set_device_perms();
139
unmute_kernel_msgs();
140
echo "done.\n";
141
142
// Display rescue configuration option
143
if($g['platform'] == "cdrom") 
144
		rescue_detect_keypress();
145
146 d5116ed5 Scott Ullrich
echo "Loading configuration...";
147
parse_config_bootup();
148
echo "done.\n";
149
150 6cc9e241 Scott Ullrich
$lan_if = $config['interfaces']['lan']['if'];
151
$wan_if = get_real_interface();
152
153
/*
154
 *  Determine if we need to throw a interface exception
155
 *  and ask the user to reassign interfaces.  This will
156
 *  avoid a reboot and thats a good thing.
157
 */
158
unmute_kernel_msgs();
159
while(is_interface_mismatch() == true) {
160
	echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
161
	set_networking_interfaces_ports();
162
}
163
164
/* convert config and clean backups */
165
echo "Updating configuration...";
166
convert_config();
167
echo "done.\n";
168
169
echo "Cleaning backup cache...";
170
cleanup_backupcache(true);
171
echo "done.\n";
172
173
/* read in /etc/sysctl.conf and set values if needed */
174
echo "Setting up extended sysctls...";
175
system_setup_sysctl();
176
echo "done.\n";
177
178 09f18f59 jim-p
/* enable glxsb if wanted */
179
load_glxsb();
180
181 6cc9e241 Scott Ullrich
/* run any early shell commands specified in config.xml */
182
system_do_shell_commands(1);
183 ef0090a3 Scott Ullrich
184 6cc9e241 Scott Ullrich
/* save dmesg output to file */
185
system_dmesg_save();
186 ef0090a3 Scott Ullrich
187 6cc9e241 Scott Ullrich
/* set up our timezone */
188
system_timezone_configure();
189
190
/* set up our hostname */
191
system_hostname_configure();
192
193
/* make hosts file */
194
system_hosts_generate();
195
196
/* configure loopback interface */
197
interfaces_loopback_configure();
198
199
/* set up interfaces */
200
if(!$debugging)
201 70b89814 Scott Ullrich
	mute_kernel_msgs();
202 6cc9e241 Scott Ullrich
interfaces_configure();
203
if(!$debugging)
204 70b89814 Scott Ullrich
	unmute_kernel_msgs();
205 86ddbb71 Scott Ullrich
206 6cc9e241 Scott Ullrich
/* generate resolv.conf */
207
system_resolvconf_generate();
208 aa01f2f2 Scott Ullrich
209 93291959 sullrich
/* start syslogd */
210
system_syslogd_start();
211
212 2fd9d050 Scott Ullrich
/* setup altq + pf */
213
filter_configure_sync();
214
215 6cc9e241 Scott Ullrich
/* start pflog */
216
echo "Starting PFLOG...";
217
filter_pflog_start();
218
echo "done.\n";
219 d0e94aaf Scott Ullrich
220 6cc9e241 Scott Ullrich
/* start load balancer daemon */
221
relayd_configure();
222 e5cd29a0 Scott Ullrich
223 17fdcb8d Ermal Lu?i
/* reconfigure our gateway monitor */
224 6cc9e241 Scott Ullrich
echo "Setting up gateway monitors...";
225 17fdcb8d Ermal Lu?i
setup_gateways_monitor();
226
echo "done.\n";
227
228
echo "Synchronizing user settings...";
229
if (!isset($config['system']['webgui']['backend']))
230
	local_sync_accounts();
231 6cc9e241 Scott Ullrich
echo "done.\n";
232 d0e94aaf Scott Ullrich
233 6cc9e241 Scott Ullrich
/* start OpenVPN server & clients */
234
echo "Syncing OpenVPN settings...";
235
openvpn_resync_all();
236
echo "done.\n";
237 e5cd29a0 Scott Ullrich
238 6cc9e241 Scott Ullrich
if($avail > 0 and $avail < 65) {
239
	echo "System has less than 65 megabytes of ram {$avail}.  Delaying webConfigurator startup.\n";
240
	/* start webConfigurator up on final pass */
241
	touch("/tmp/restart_webgui");
242
} else {
243
	/* start web server */
244
	system_webgui_start();
245
}
246 ef9366bd Scott Ullrich
247 6cc9e241 Scott Ullrich
/* configure cron service */
248
echo "Configuring CRON...";
249
configure_cron();
250
echo "done.\n";
251 68cd47b3 Scott Ullrich
252 6cc9e241 Scott Ullrich
/* set up static routes */
253
system_routing_configure();
254 d0e94aaf Scott Ullrich
255 6cc9e241 Scott Ullrich
/* enable routing */
256
system_routing_enable();
257 e5cd29a0 Scott Ullrich
258 5cd26039 Ermal Lu?i
echo "Starting Secure Shell Services...";
259
mwexec_bg("/etc/sshd");
260
echo "done.\n";
261
262 6cc9e241 Scott Ullrich
/* configure console menu */
263
system_console_configure();
264 a005424e Scott Ullrich
265 6cc9e241 Scott Ullrich
/* start the NTP client */
266
echo "Starting OpenNTP time client...";
267
system_ntp_configure();
268
echo "done.\n";
269 5ffb18e0 Scott Ullrich
270 6cc9e241 Scott Ullrich
/* Launch on bootup and keep trying to sync.  Exit once time/date has been sync'd. */
271
mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh");
272 5b237745 Scott Ullrich
273 6cc9e241 Scott Ullrich
/* static IP address? -> attempt DNS update */
274
if (is_ipaddr($config['interfaces']['wan']['ipaddr']))
275
	services_dnsupdate_process();
276 e5cd29a0 Scott Ullrich
277 6cc9e241 Scott Ullrich
/* start dnsmasq service */
278
services_dnsmasq_configure();
279 e5cd29a0 Scott Ullrich
280 85b2f424 Ermal
/* start dyndns service */
281
@touch("{$g['tmp_path']}/update_dyndns");
282
283 6cc9e241 Scott Ullrich
/* start DHCP relay */
284
services_dhcrelay_configure();
285 562fca6d Scott Ullrich
286 6cc9e241 Scott Ullrich
/* setup pppoe and pptp */
287
vpn_setup();
288 c6e604d8 Scott Ullrich
289 6cc9e241 Scott Ullrich
/* start the captive portal */
290
captiveportal_configure();
291 f4959a69 Scott Ullrich
292 336e3c1c Charlie
/* start Voucher support */
293
voucher_configure();
294
295 6cc9e241 Scott Ullrich
/* run any shell commands specified in config.xml */
296
system_do_shell_commands();
297 9f966bc9 Scott Ullrich
298 6cc9e241 Scott Ullrich
/* setup polling */
299
setup_polling();
300 f4959a69 Scott Ullrich
301 6cc9e241 Scott Ullrich
/* setup interface microcode which improves tcp/ip speed */
302
echo "Setting up microcode and tx/rx offloading...";
303
setup_microcode();
304
echo "done.\n";
305 d0e94aaf Scott Ullrich
306 6cc9e241 Scott Ullrich
/* start IPsec tunnels */
307
vpn_ipsec_configure();
308 a199b93e Scott Ullrich
309 6cc9e241 Scott Ullrich
/* start SNMP service */
310
services_snmpd_configure();
311 11cbd478 Scott Ullrich
312 6cc9e241 Scott Ullrich
/* power down hard drive if needed/set */
313
system_set_harddisk_standby();
314 011bff69 Bill Marquette
315 6cc9e241 Scott Ullrich
/* lock down console if necessary */
316 a46e450c Ermal Lu?i
auto_login();
317 d0e94aaf Scott Ullrich
318 6cc9e241 Scott Ullrich
/* Run a filter configure now that most all services have started */
319
filter_configure_sync();
320 6d80ad3a Scott Ullrich
321 6cc9e241 Scott Ullrich
/* load graphing functions */
322
enable_rrd_graphing();
323
324
/* start DHCP service */
325
services_dhcpd_configure();
326
327 7ea754a8 sullrich
/* start DHCP logging service which populates /etc/hosts */
328
services_parse_dhcpd_hostnames();
329
330 6cc9e241 Scott Ullrich
/* startup OLSR if needed */
331
setup_wireless_olsr();
332
333
/* startup routed if needed */
334
include_once("/usr/local/pkg/routed/routed.inc");
335
setup_routed();
336
337
/* enable watchdog if supported */
338
enable_watchdog();
339
340
/* if <system><afterbootupshellcmd> exists, execute the command */
341
if($config['system']['afterbootupshellcmd'] <> "") {
342
	echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
343
	mwexec($config['system']['afterbootupshellcmd']);
344
}
345
346 9f274393 Chris Buechler
if($avail < $g['minimum_ram_warning']) {
347 6cc9e241 Scott Ullrich
	require_once("/etc/inc/notices.inc");
348 9f274393 Chris Buechler
	file_notice("{$g['product_name']}MemoryRequirements", "{$g['product_name']} requires at least {$g['minimum_ram_warning_text']} of RAM.  Expect unusual performance.  This platform is not supported.", "Memory", "", 1);
349 6cc9e241 Scott Ullrich
	mwexec("sysctl net.inet.tcp.recvspace=4096");
350
	mwexec("sysctl net.inet.tcp.sendspace=4096");
351
}
352
353
/* if we are operating at 1000 then increase timeouts.
354
   this was never accounted for after moving to 1000 hz */
355
$kern_hz = `sysctl kern.clockrate | awk '{ print $5 }' | cut -d"," -f1`;
356
$kern_hz = trim($kern_hz, "\r\n");
357
if($kern_hz == "1000") 
358
	mwexec("sysctl net.inet.tcp.rexmit_min=30");
359 c108ec01 Scott Ullrich
360 34c7f02e Scott Ullrich
/* start the igmpproxy daemon */
361 6cc9e241 Scott Ullrich
services_igmpproxy_configure();
362 41997fbb Ermal Luci
363 6cc9e241 Scott Ullrich
/* start the upnp daemon if it is enabled */
364
upnp_start();
365 6f20377b Scott Ullrich
366 6cc9e241 Scott Ullrich
/* If powerd is enabled, lets launch it */
367
activate_powerd();
368 8e9fa41d Scott Ullrich
369 6cc9e241 Scott Ullrich
/* done */
370
unlink("{$g['varrun_path']}/booting");
371 27556fa9 Scott Ullrich
unset($g['booting']);
372 5c60c947 Scott Ullrich
373 00a4146e jim-p
led_normalize();
374 410cdac4 Scott Ullrich
375 6346595c Ermal Lu?i
conf_mount_ro();
376
377 17fdcb8d Ermal Lu?i
?>