Project

General

Profile

Download (9.31 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=4;
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 "Recovery mode can assist by rescuing config.xml\n";
42
	echo "from a broken hard disk installation, etc.\n\n";
43
	echo "Alternatively the installer 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): ";
46
	$key = null;
47
	while(!in_array($key, array("r","R", "i", "I", "~", "!"))) {
48
	        echo " {$timeout}";
49
	        `/bin/stty -icanon min 0 time 25`;
50
	        $key = trim(`KEY=\`dd count=1 2>/dev/null\`; echo \$KEY`);
51
	        `/bin/stty icanon`;
52
	        // Decrement our timeout value
53
	        $timeout--;
54
	        // If we have reached 0 exit and continue on
55
	        if ($timeout == 0) 
56
				break;
57
	}
58
	// If R or I was pressed do our logic here
59
	if (in_array($key, array("r", "R"))) {
60
	  putenv("TERM=cons25");
61
	  echo "\n\nRecovery mode selected...\n";
62
	  passthru("/usr/bin/env TERM=cons25 /bin/tcsh -c /scripts/lua_installer_rescue");
63
	} elseif (in_array($key, array("i", "I"))) {
64
	  putenv("TERM=cons25");  
65
	  echo "\n\nInstaller mode selected...\n";
66
	  passthru("/usr/bin/env TERM=cons25 /bin/tcsh -c /scripts/lua_installer");
67
	  if(file_exists("/tmp/install_complete")) {
68
		passthru("/etc/rc.reboot");
69
		exit;
70
	  }
71
	} elseif (in_array($key, array("!", "~"))) {
72
 		putenv("TERM=cons25");
73
		echo "\n\nRecovery shell selected...\n";
74
		echo "\n";
75
		touch("/tmp/donotbootup");
76
		exit;
77
	}
78
}
79

    
80
echo " done.\n";
81

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

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

    
105
conf_mount_rw();
106

    
107
/* remove previous firmware upgrade if present */
108
if (file_exists("/root/firmware.tgz")) 
109
	unlink("/root/firmware.tgz");
110

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

    
119
// Display rescue configuration option
120
if($g['platform'] == "cdrom") 
121
		rescue_detect_keypress();
122

    
123
echo "Loading configuration...";
124
parse_config_bootup();
125
echo "done.\n";
126

    
127
$lan_if = $config['interfaces']['lan']['if'];
128
$wan_if = get_real_interface();
129

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

    
141
/* convert config and clean backups */
142
echo "Updating configuration...";
143
convert_config();
144
echo "done.\n";
145

    
146
echo "Cleaning backup cache...";
147
cleanup_backupcache(true);
148
echo "done.\n";
149

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

    
155
echo "Starting Secure Shell Services...";
156
mwexec_bg("/etc/sshd");
157
echo "done.\n";
158

    
159
/* run any early shell commands specified in config.xml */
160
system_do_shell_commands(1);
161

    
162
/* save dmesg output to file */
163
system_dmesg_save();
164

    
165
/* set up our timezone */
166
system_timezone_configure();
167

    
168
/* set up our hostname */
169
system_hostname_configure();
170

    
171
/* make hosts file */
172
system_hosts_generate();
173

    
174
/* configure loopback interface */
175
interfaces_loopback_configure();
176

    
177
/* start syslogd */
178
system_syslogd_start();
179

    
180
/* set up interfaces */
181
if(!$debugging)
182
	mute_kernel_msgs();
183
interfaces_configure();
184
if(!$debugging)
185
	unmute_kernel_msgs();
186

    
187
/* setup altq + pf */
188
filter_configure_sync();
189

    
190
/* generate resolv.conf */
191
system_resolvconf_generate();
192

    
193
/* start pflog */
194
echo "Starting PFLOG...";
195
filter_pflog_start();
196
echo "done.\n";
197

    
198
/* start load balancer daemon */
199
relayd_configure();
200

    
201
	/* reconfigure our gateway monitor */
202
echo "Setting up gateway monitors...";
203
	setup_gateways_monitor();
204
echo "done.\n";
205

    
206
/* start OpenVPN server & clients */
207
echo "Syncing OpenVPN settings...";
208
openvpn_resync_all();
209
echo "done.\n";
210

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

    
220
/* configure cron service */
221
echo "Configuring CRON...";
222
configure_cron();
223
echo "done.\n";
224

    
225
/* set up static routes */
226
system_routing_configure();
227

    
228
/* enable routing */
229
system_routing_enable();
230

    
231
/* configure console menu */
232
system_console_configure();
233

    
234
/* start the NTP client */
235
echo "Starting OpenNTP time client...";
236
system_ntp_configure();
237
echo "done.\n";
238

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

    
242
/* start dyndns service */
243
services_dyndns_configure();
244

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

    
249
/* start dnsmasq service */
250
services_dnsmasq_configure();
251

    
252
/* start DHCP relay */
253
services_dhcrelay_configure();
254

    
255
/* start proxy ARP service */
256
services_proxyarp_configure();
257

    
258
/* setup pppoe and pptp */
259
vpn_setup();
260

    
261
/* start the captive portal */
262
captiveportal_configure();
263

    
264
/* run any shell commands specified in config.xml */
265
system_do_shell_commands();
266

    
267
/* setup polling */
268
setup_polling();
269

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

    
275
/* start IPsec tunnels */
276
vpn_ipsec_configure();
277

    
278
/* start SNMP service */
279
services_snmpd_configure();
280

    
281
/* power down hard drive if needed/set */
282
system_set_harddisk_standby();
283

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

    
288
/* Run a filter configure now that most all services have started */
289
filter_configure_sync();
290

    
291
/* load graphing functions */
292
enable_rrd_graphing();
293

    
294
/* start DHCP service */
295
services_dhcpd_configure();
296

    
297
/* startup OLSR if needed */
298
setup_wireless_olsr();
299

    
300
/* startup routed if needed */
301
include_once("/usr/local/pkg/routed/routed.inc");
302
setup_routed();
303

    
304
/* enable watchdog if supported */
305
enable_watchdog();
306

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

    
313
if($avail < 126) {
314
	require_once("/etc/inc/notices.inc");
315
	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);
316
	mwexec("sysctl net.inet.tcp.recvspace=4096");
317
	mwexec("sysctl net.inet.tcp.sendspace=4096");
318
}
319

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

    
327
/* start the igmpproxy daemon
328
services_igmpproxy_configure();
329

    
330
/* start the upnp daemon if it is enabled */
331
upnp_start();
332

    
333
/* If powerd is enabled, lets launch it */
334
activate_powerd();
335

    
336
mwexec_bg("/usr/sbin/update_dns_cache.sh");
337

    
338
/* done */
339
unlink("{$g['varrun_path']}/booting");
340
$g['booting'] = FALSE;
341

    
342
?>
(32-32/85)