Project

General

Profile

Download (9.39 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php -f
2
<?php
3
/* $Id$ */
4
/*
5
	rc.bootup
6
	part of pfSense by Scott Ullrich
7
	originally based on m0n0wall (http://m0n0.ch/wall)
8
	Copyright (C) 2004-2009 Scott Ullrich <sullrich@pfsense.org>.
9
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	Copyright (C) 2009 Erik Kristensen
11
	All rights reserved.
12

    
13
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15

    
16
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18

    
19
	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

    
23
	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
function rescue_detect_keypress() {
36
	// How long do you want the script to wait before moving on (in seconds)
37
	$timeout=9;
38
	echo "\n";
39
    echo "[ Press R to enter recovery mode or ]\n";
40
	echo "[  press I to launch the installer  ]\n\n";
41
	echo "(R)ecovery mode can assist by rescuing config.xml\n";
42
	echo "from a broken hard disk installation, etc.\n\n";
43
	echo "Alternatively the (I)nstaller may be invoked now if you do \n";
44
	echo "not wish to boot into the liveCD environment at this time.\n\n";
45
	echo "Timeout before auto boot continues (seconds): {$timeout}";
46
	$key = null;
47
	exec("/bin/stty erase " . chr(8));
48
	while(!in_array($key, array("r","R", "i", "I", "~", "!"))) {
49
	        echo chr(8) . "{$timeout}";
50
	        `/bin/stty -icanon min 0 time 25`;
51
	        $key = trim(`KEY=\`dd count=1 2>/dev/null\`; echo \$KEY`);
52
	        `/bin/stty icanon`;
53
	        // Decrement our timeout value
54
	        $timeout--;
55
	        // If we have reached 0 exit and continue on
56
	        if ($timeout == 0) 
57
				break;
58
	}
59
	// If R or I was pressed do our logic here
60
	if (in_array($key, array("r", "R"))) {
61
	  putenv("TERM=cons25");
62
	  echo "\n\nRecovery mode selected...\n";
63
	  passthru("/usr/bin/env TERM=cons25 /bin/tcsh -c /scripts/lua_installer_rescue");
64
	} elseif (in_array($key, array("i", "I"))) {
65
	  putenv("TERM=cons25");  
66
	  echo "\n\nInstaller mode selected...\n";
67
	  passthru("/usr/bin/env TERM=cons25 /bin/tcsh -c /scripts/lua_installer");
68
	  if(file_exists("/tmp/install_complete")) {
69
		passthru("/etc/rc.reboot");
70
		exit;
71
	  }
72
	} elseif (in_array($key, array("!", "~"))) {
73
 		putenv("TERM=cons25");
74
		echo "\n\nRecovery shell selected...\n";
75
		echo "\n";
76
		touch("/tmp/donotbootup");
77
		exit;
78
	} else {
79
		echo "\n\n";
80
	}
81
}
82

    
83
echo " done.\n";
84

    
85
echo "Initializing...";
86
echo ".";
87
require_once("/etc/inc/globals.inc");
88
echo ".";
89
/* let the other functions know we're booting */
90
$pkg_interface = 'console';
91
$g['booting'] = TRUE;
92
touch("{$g['varrun_path']}/booting");
93
if($g['platform'] == "cdrom") {
94
	$motd = trim(file_get_contents("/etc/motd"));
95
	if (strlen($motd) > 2) 
96
		echo "\n{$motd}\n\n";
97
}
98

    
99
/* parse the configuration and include all functions used below */
100
require_once("/etc/inc/config.inc");
101
echo ".";
102
require_once("/etc/inc/functions.inc");
103
/* get system memory amount */
104
$memory = get_memory();
105
$avail = $memory[0];
106
echo " done.\n";
107

    
108
conf_mount_rw();
109

    
110
/* remove previous firmware upgrade if present */
111
if (file_exists("/root/firmware.tgz")) 
112
	unlink("/root/firmware.tgz");
113

    
114
/* start devd (dhclient now uses it */
115
echo "Starting device manager (devd)...";
116
mute_kernel_msgs();
117
start_devd();
118
set_device_perms();
119
unmute_kernel_msgs();
120
echo "done.\n";
121

    
122
// Display rescue configuration option
123
if($g['platform'] == "cdrom") 
124
		rescue_detect_keypress();
125

    
126
echo "Loading configuration...";
127
parse_config_bootup();
128
echo "done.\n";
129

    
130
$lan_if = $config['interfaces']['lan']['if'];
131
$wan_if = get_real_interface();
132

    
133
/*
134
 *  Determine if we need to throw a interface exception
135
 *  and ask the user to reassign interfaces.  This will
136
 *  avoid a reboot and thats a good thing.
137
 */
138
unmute_kernel_msgs();
139
while(is_interface_mismatch() == true) {
140
	echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
141
	set_networking_interfaces_ports();
142
}
143

    
144
/* convert config and clean backups */
145
echo "Updating configuration...";
146
convert_config();
147
echo "done.\n";
148

    
149
echo "Cleaning backup cache...";
150
cleanup_backupcache(true);
151
echo "done.\n";
152

    
153
/* read in /etc/sysctl.conf and set values if needed */
154
echo "Setting up extended sysctls...";
155
system_setup_sysctl();
156
echo "done.\n";
157

    
158
echo "Starting Secure Shell Services...";
159
mwexec_bg("/etc/sshd");
160
echo "done.\n";
161

    
162
/* run any early shell commands specified in config.xml */
163
system_do_shell_commands(1);
164

    
165
/* save dmesg output to file */
166
system_dmesg_save();
167

    
168
/* set up our timezone */
169
system_timezone_configure();
170

    
171
/* set up our hostname */
172
system_hostname_configure();
173

    
174
/* make hosts file */
175
system_hosts_generate();
176

    
177
/* configure loopback interface */
178
interfaces_loopback_configure();
179

    
180
/* start syslogd */
181
system_syslogd_start();
182

    
183
/* set up interfaces */
184
if(!$debugging)
185
	mute_kernel_msgs();
186
interfaces_configure();
187
if(!$debugging)
188
	unmute_kernel_msgs();
189

    
190
/* setup altq + pf */
191
filter_configure_sync();
192

    
193
/* generate resolv.conf */
194
system_resolvconf_generate();
195

    
196
/* start pflog */
197
echo "Starting PFLOG...";
198
filter_pflog_start();
199
echo "done.\n";
200

    
201
/* start load balancer daemon */
202
relayd_configure();
203

    
204
	/* reconfigure our gateway monitor */
205
echo "Setting up gateway monitors...";
206
	setup_gateways_monitor();
207
echo "done.\n";
208

    
209
/* start OpenVPN server & clients */
210
echo "Syncing OpenVPN settings...";
211
openvpn_resync_all();
212
echo "done.\n";
213

    
214
if($avail > 0 and $avail < 65) {
215
	echo "System has less than 65 megabytes of ram {$avail}.  Delaying webConfigurator startup.\n";
216
	/* start webConfigurator up on final pass */
217
	touch("/tmp/restart_webgui");
218
} else {
219
	/* start web server */
220
	system_webgui_start();
221
}
222

    
223
/* configure cron service */
224
echo "Configuring CRON...";
225
configure_cron();
226
echo "done.\n";
227

    
228
/* set up static routes */
229
system_routing_configure();
230

    
231
/* enable routing */
232
system_routing_enable();
233

    
234
/* configure console menu */
235
system_console_configure();
236

    
237
/* start the NTP client */
238
echo "Starting OpenNTP time client...";
239
system_ntp_configure();
240
echo "done.\n";
241

    
242
/* Launch on bootup and keep trying to sync.  Exit once time/date has been sync'd. */
243
mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh");
244

    
245
/* start dyndns service */
246
services_dyndns_configure();
247

    
248
/* static IP address? -> attempt DNS update */
249
if (is_ipaddr($config['interfaces']['wan']['ipaddr']))
250
	services_dnsupdate_process();
251

    
252
/* start dnsmasq service */
253
services_dnsmasq_configure();
254

    
255
/* start DHCP relay */
256
services_dhcrelay_configure();
257

    
258
/* start proxy ARP service */
259
services_proxyarp_configure();
260

    
261
/* setup pppoe and pptp */
262
vpn_setup();
263

    
264
/* start the captive portal */
265
captiveportal_configure();
266

    
267
/* run any shell commands specified in config.xml */
268
system_do_shell_commands();
269

    
270
/* setup polling */
271
setup_polling();
272

    
273
/* setup interface microcode which improves tcp/ip speed */
274
echo "Setting up microcode and tx/rx offloading...";
275
setup_microcode();
276
echo "done.\n";
277

    
278
/* start IPsec tunnels */
279
vpn_ipsec_configure();
280

    
281
/* start SNMP service */
282
services_snmpd_configure();
283

    
284
/* power down hard drive if needed/set */
285
system_set_harddisk_standby();
286

    
287
/* lock down console if necessary */
288
if(isset($config['system']['disableconsolemenu']))
289
	touch("/var/etc/console_lockdown");
290

    
291
/* Run a filter configure now that most all services have started */
292
filter_configure_sync();
293

    
294
/* load graphing functions */
295
enable_rrd_graphing();
296

    
297
/* start DHCP service */
298
services_dhcpd_configure();
299

    
300
/* startup OLSR if needed */
301
setup_wireless_olsr();
302

    
303
/* startup routed if needed */
304
include_once("/usr/local/pkg/routed/routed.inc");
305
setup_routed();
306

    
307
/* enable watchdog if supported */
308
enable_watchdog();
309

    
310
/* if <system><afterbootupshellcmd> exists, execute the command */
311
if($config['system']['afterbootupshellcmd'] <> "") {
312
	echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
313
	mwexec($config['system']['afterbootupshellcmd']);
314
}
315

    
316
if($avail < 126) {
317
	require_once("/etc/inc/notices.inc");
318
	file_notice("{$g['product_name']}MemoryRequirements", "{$g['product_name']} requires atleast 128 megabytes of RAM.  Expect unusual performance.  This platform is not supported.", "Memory", "", 1);
319
	mwexec("sysctl net.inet.tcp.recvspace=4096");
320
	mwexec("sysctl net.inet.tcp.sendspace=4096");
321
}
322

    
323
/* if we are operating at 1000 then increase timeouts.
324
   this was never accounted for after moving to 1000 hz */
325
$kern_hz = `sysctl kern.clockrate | awk '{ print $5 }' | cut -d"," -f1`;
326
$kern_hz = trim($kern_hz, "\r\n");
327
if($kern_hz == "1000") 
328
	mwexec("sysctl net.inet.tcp.rexmit_min=30");
329

    
330
/* start the igmpproxy daemon
331
services_igmpproxy_configure();
332

    
333
/* start the upnp daemon if it is enabled */
334
upnp_start();
335

    
336
/* If powerd is enabled, lets launch it */
337
activate_powerd();
338

    
339
mwexec_bg("/usr/sbin/update_dns_cache.sh");
340

    
341
/* done */
342
unlink("{$g['varrun_path']}/booting");
343
$g['booting'] = FALSE;
344

    
345
?>
(32-32/85)