Project

General

Profile

Download (7.71 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
9 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11 e5cd29a0 Scott Ullrich
12 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14 e5cd29a0 Scott Ullrich
15 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17 e5cd29a0 Scott Ullrich
18 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21 e5cd29a0 Scott Ullrich
22 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32
*/
33
34 d0e94aaf Scott Ullrich
	echo " done.\n";
35
36
	echo "Initializing...";
37
	echo ".";
38 4bee8672 Scott Ullrich
	require_once("/etc/inc/globals.inc");
39 d0e94aaf Scott Ullrich
	echo ".";
40 a164b0ca Scott Ullrich
	/* let the other functions know we're booting */
41
	$pkg_interface = 'console';
42
	$g['booting'] = TRUE;
43
	touch("{$g['varrun_path']}/booting");
44 2c35ed91 Scott Ullrich
	if($g['platform'] == "cdrom") {
45 7822d966 Colin Smith
		$motd = trim(file_get_contents("/etc/motd"));
46 3a312927 Ermal Luçi
		if (strlen($motd) > 2) 
47
			echo "\n{$motd}\n\n";
48 2c35ed91 Scott Ullrich
	}
49 5f89728d Scott Ullrich
50 5b237745 Scott Ullrich
	/* parse the configuration and include all functions used below */
51 4bee8672 Scott Ullrich
	require_once("/etc/inc/config.inc");
52 d0e94aaf Scott Ullrich
	echo ".";
53 4bee8672 Scott Ullrich
	require_once("/etc/inc/functions.inc");
54 a6abbd66 Scott Ullrich
	/* get system memory amount */
55
	$memory = get_memory();
56
	$avail = $memory[0];
57 d0e94aaf Scott Ullrich
	echo " done.\n";
58 e5cd29a0 Scott Ullrich
59 ef0090a3 Scott Ullrich
	conf_mount_rw();
60
61
	/* remove previous firmware upgrade if present */
62 3a312927 Ermal Luçi
	if (file_exists("/root/firmware.tgz")) 
63 f8554aed Scott Ullrich
		unlink("/root/firmware.tgz");
64 ef0090a3 Scott Ullrich
65 86ddbb71 Scott Ullrich
	/* start devd (dhclient now uses it */
66 f05740c1 Scott Ullrich
	echo "Starting device manager (devd)...";
67 70b89814 Scott Ullrich
	mute_kernel_msgs();
68 86ddbb71 Scott Ullrich
	start_devd();
69 09b949e1 Scott Ullrich
	set_device_perms();
70 70b89814 Scott Ullrich
	unmute_kernel_msgs();
71 86ddbb71 Scott Ullrich
	echo "done.\n";
72
73 f05740c1 Scott Ullrich
	echo "Loading configuration...";
74 b6f3f5c6 Colin Smith
	parse_config_bootup();
75 74dbce1f Scott Ullrich
	echo "done.\n";
76 b6f3f5c6 Colin Smith
77 afde8c22 Scott Ullrich
	$lan_if = $config['interfaces']['lan']['if'];
78 85a5da13 Ermal Luçi
	$wan_if = get_real_interface();
79 aa01f2f2 Scott Ullrich
80 28d38aa4 Scott Ullrich
	/*
81 22d0b8e5 Bill Marquette
	 *  Determine if we need to throw a interface exception
82 51a06872 Scott Ullrich
	 *  and ask the user to reassign interfaces.  This will
83
	 *  avoid a reboot and thats a good thing.
84 28d38aa4 Scott Ullrich
	 */
85 de16ed63 Scott Ullrich
	unmute_kernel_msgs();
86 8cd7e1fa Scott Ullrich
	while(is_interface_mismatch() == true) {
87
		echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
88
		set_networking_interfaces_ports();
89
	}
90
	
91 d6f1dbe3 Colin Smith
	/* convert config and clean backups */
92 f05740c1 Scott Ullrich
	echo "Updating configuration...";
93 5b237745 Scott Ullrich
	convert_config();
94 74dbce1f Scott Ullrich
	echo "done.\n";
95 bad59dd6 Colin Smith
96 f05740c1 Scott Ullrich
	echo "Cleaning backup cache...";
97 d6f1dbe3 Colin Smith
	cleanup_backupcache(true);
98 74dbce1f Scott Ullrich
	echo "done.\n";
99 d0e94aaf Scott Ullrich
100 3ff9d424 Scott Ullrich
	/* read in /etc/sysctl.conf and set values if needed */
101 f05740c1 Scott Ullrich
	echo "Setting up extended sysctls...";
102 3ff9d424 Scott Ullrich
	system_setup_sysctl();
103 92e2deb7 Scott Ullrich
	echo "done.\n";
104 3ff9d424 Scott Ullrich
105 f05740c1 Scott Ullrich
	echo "Starting Secure Shell Services...";
106 beaff8b0 Scott Ullrich
	mwexec_bg("/etc/sshd");
107
	echo "done.\n";
108
109 5b237745 Scott Ullrich
	/* run any early shell commands specified in config.xml */
110
	system_do_shell_commands(1);
111 e5cd29a0 Scott Ullrich
112 5b237745 Scott Ullrich
	/* save dmesg output to file */
113
	system_dmesg_save();
114 e5cd29a0 Scott Ullrich
115 5b237745 Scott Ullrich
	/* set up our timezone */
116
	system_timezone_configure();
117 e5cd29a0 Scott Ullrich
118 5b237745 Scott Ullrich
	/* set up our hostname */
119
	system_hostname_configure();
120 e5cd29a0 Scott Ullrich
121 5b237745 Scott Ullrich
	/* make hosts file */
122
	system_hosts_generate();
123 e5cd29a0 Scott Ullrich
124 5b237745 Scott Ullrich
	/* configure loopback interface */
125
	interfaces_loopback_configure();
126 e5cd29a0 Scott Ullrich
127 93629767 Scott Ullrich
	/* start syslogd */
128
	system_syslogd_start();
129
130 67ee1ec5 Ermal Luçi
	/* set up interfaces */
131 e556dea7 Scott Ullrich
	if(!$debugging)
132
		mute_kernel_msgs();
133 67ee1ec5 Ermal Luçi
	interfaces_configure();
134 d0e94aaf Scott Ullrich
	if(!$debugging)
135 e556dea7 Scott Ullrich
		unmute_kernel_msgs();
136 dd2ab8f8 Scott Ullrich
137 499994ff Scott Ullrich
	/* setup altq + pf */
138
	filter_configure_sync();
139
140 3a89b8d9 Scott Ullrich
	/* generate resolv.conf */
141
	system_resolvconf_generate();
142
143 24d15c0c Scott Ullrich
	/* start pflog */
144 51a06872 Scott Ullrich
	echo "Starting PFLOG...";
145 24d15c0c Scott Ullrich
	filter_pflog_start();
146 51a06872 Scott Ullrich
	echo "done.\n";
147 3962b070 Scott Ullrich
148 ab34f4ec Scott Ullrich
	/* start load balancer daemon */
149 17623ab5 Bill Marquette
	relayd_configure();
150 67ee1ec5 Ermal Luçi
151
 	/* reconfigure our gateway monitor */
152 51a06872 Scott Ullrich
	echo "Setting up gateway monitors...";
153 67ee1ec5 Ermal Luçi
 	setup_gateways_monitor();
154 51a06872 Scott Ullrich
	echo "done.\n";
155 12c09555 Scott Ullrich
156
	/* start OpenVPN server & clients */
157 51a06872 Scott Ullrich
	echo "Syncing OpenVPN settings...";
158 7e4329ed Chris Buechler
	openvpn_resync_all();
159 51a06872 Scott Ullrich
	echo "done.\n";
160 d0e94aaf Scott Ullrich
161 a6abbd66 Scott Ullrich
	if($avail > 0 and $avail < 65) {
162 bd042586 Scott Ullrich
		echo "System has less than 65 megabytes of ram {$avail}.  Delaying webConfigurator startup.\n";
163 a6abbd66 Scott Ullrich
		/* start webConfigurator up on final pass */
164
		touch("/tmp/restart_webgui");
165
	} else {
166
		/* start web server */
167
		system_webgui_start();
168
	}
169 d0e94aaf Scott Ullrich
170 1071e028 Scott Ullrich
	/* configure cron service */
171 51a06872 Scott Ullrich
	echo "Configuring CRON...";
172 1071e028 Scott Ullrich
	configure_cron();
173 51a06872 Scott Ullrich
	echo "done.\n";
174
	
175 5b237745 Scott Ullrich
	/* set up static routes */
176
	system_routing_configure();
177 e5cd29a0 Scott Ullrich
178 5b237745 Scott Ullrich
	/* enable routing */
179
	system_routing_enable();
180 d0e94aaf Scott Ullrich
181 5b237745 Scott Ullrich
	/* configure console menu */
182
	system_console_configure();
183 e5cd29a0 Scott Ullrich
184 ef9366bd Scott Ullrich
	/* start the NTP client */
185
	echo "Starting OpenNTP time client...";
186
	system_ntp_configure();
187
	echo "done.\n";
188
189 c73dcb03 Scott Ullrich
	/* Launch on bootup and keep trying to sync.  Exit once time/date has been sync'd. */
190
	mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh");
191 68cd47b3 Scott Ullrich
192 5b237745 Scott Ullrich
	/* start dyndns service */
193
	services_dyndns_configure();
194 d0e94aaf Scott Ullrich
195 5ffb18e0 Scott Ullrich
	/* static IP address? -> attempt DNS update */
196
	if (is_ipaddr($config['interfaces']['wan']['ipaddr']))
197
		services_dnsupdate_process();
198 e5cd29a0 Scott Ullrich
199 a005424e Scott Ullrich
	/* start dnsmasq service */
200
	services_dnsmasq_configure();
201
202 5ffb18e0 Scott Ullrich
	/* start DHCP relay */
203
	services_dhcrelay_configure();
204
205 5b237745 Scott Ullrich
	/* start proxy ARP service */
206
	services_proxyarp_configure();
207
208 88964924 Scott Ullrich
	/* setup pppoe and pptp */
209
	vpn_setup();
210 3d941d72 Scott Ullrich
211 5b237745 Scott Ullrich
	/* start the captive portal */
212
	captiveportal_configure();
213 e5cd29a0 Scott Ullrich
214 5b237745 Scott Ullrich
	/* run any shell commands specified in config.xml */
215
	system_do_shell_commands();
216 e5cd29a0 Scott Ullrich
217 562fca6d Scott Ullrich
	/* setup polling */
218
	setup_polling();
219
220 28d38aa4 Scott Ullrich
	/* setup interface microcode which improves tcp/ip speed */
221 f05740c1 Scott Ullrich
	echo "Setting up microcode and tx/rx offloading...";
222 11e2c67c Scott Ullrich
	setup_microcode();
223 0192adaf Scott Ullrich
	echo "done.\n";
224 d0e94aaf Scott Ullrich
225 11c32d4a Scott Ullrich
	/* start IPsec tunnels */
226 11e2c67c Scott Ullrich
	vpn_ipsec_configure();
227 c6e604d8 Scott Ullrich
228 154349f9 Scott Ullrich
	/* start ftp proxy helpers if they are enabled */
229 f05740c1 Scott Ullrich
	echo "Starting FTP helpers...";
230 154349f9 Scott Ullrich
	system_start_ftp_helpers();
231
	echo "done.\n";
232
233 f4959a69 Scott Ullrich
	/* start SNMP service */
234
	services_snmpd_configure();
235
236 9f966bc9 Scott Ullrich
	/* power down hard drive if needed/set */
237 11e2c67c Scott Ullrich
	system_set_harddisk_standby();
238 9f966bc9 Scott Ullrich
239 ce9e67ce Scott Ullrich
	/* lock down console if necessary */
240
	if(isset($config['system']['disableconsolemenu']))
241
		touch("/var/etc/console_lockdown");
242 f4959a69 Scott Ullrich
243 9ff5048f Seth Mos
	/* Run a filter configure now that most all services have started */
244 2b263ed6 Chris Buechler
	filter_configure_sync();
245 d0e94aaf Scott Ullrich
246 f0842feb Scott Ullrich
	/* load graphing functions */
247 d0e94aaf Scott Ullrich
	enable_rrd_graphing();
248 51a06872 Scott Ullrich
	
249 9ff5048f Seth Mos
	/* start DHCP service */
250 1e19b3b4 Scott Ullrich
	services_dhcpd_configure();
251 a199b93e Scott Ullrich
252 11cbd478 Scott Ullrich
	/* startup OLSR if needed */
253
	setup_wireless_olsr();
254
255 011bff69 Bill Marquette
	/* startup routed if needed */
256
	include_once("/usr/local/pkg/routed/routed.inc");
257
	setup_routed();
258
259 a199b93e Scott Ullrich
	/* enable watchdog if supported */
260
	enable_watchdog();
261 d0e94aaf Scott Ullrich
262 6d80ad3a Scott Ullrich
	/* if <system><afterbootupshellcmd> exists, execute the command */
263 51a06872 Scott Ullrich
	if($config['system']['afterbootupshellcmd'] <> "") {
264
		echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
265 6d80ad3a Scott Ullrich
		mwexec($config['system']['afterbootupshellcmd']);
266 51a06872 Scott Ullrich
	}
267 6d80ad3a Scott Ullrich
268 3c61530f Scott Ullrich
	if($avail < 126) {
269 4bee8672 Scott Ullrich
		require_once("/etc/inc/notices.inc");
270 5b6eac01 Scott Ullrich
		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);
271 6f954b49 Scott Ullrich
		mwexec("sysctl net.inet.tcp.recvspace=4096");
272
		mwexec("sysctl net.inet.tcp.sendspace=4096");
273 c108ec01 Scott Ullrich
	}
274 4313e61a Scott Ullrich
	
275
	/* if we are operating at 1000 then increase timeouts.
276
	   this was never accounted for after moving to 1000 hz */
277
	$kern_hz = `sysctl kern.clockrate | awk '{ print $5 }' | cut -d"," -f1`;
278
	$kern_hz = trim($kern_hz, "\r\n");
279 6c038dc6 Scott Ullrich
	if($kern_hz == "1000") 
280 4313e61a Scott Ullrich
		mwexec("sysctl net.inet.tcp.rexmit_min=30");
281 c108ec01 Scott Ullrich
282 9ff5048f Seth Mos
	/* start the upnp daemon if it is enabled */
283 6f20377b Scott Ullrich
	upnp_start();
284
285 279ee755 Scott Ullrich
	mwexec_bg("/usr/sbin/update_dns_cache.sh");
286 31381202 Scott Ullrich
287 5b237745 Scott Ullrich
	/* done */
288
	unlink("{$g['varrun_path']}/booting");
289 5c60c947 Scott Ullrich
	$g['booting'] = FALSE;
290
291 c73dcb03 Scott Ullrich
?>