Project

General

Profile

Download (9.85 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php-cgi -f
2
<?php
3
/*
4
 * rc.bootup
5
 *
6
 * originally based on m0n0wall (http://m0n0.ch/wall)
7
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
 * Copyright (c) 2009 Erik Kristensen
9
 * Copyright (c) 2005-2016 Rubicon Communications, LLC (Netgate). All rights reserved.
10
 * All rights reserved.
11
 *
12
 * Licensed under the Apache License, Version 2.0 (the "License");
13
 * you may not use this file except in compliance with the License.
14
 * You may obtain a copy of the License at
15
 *
16
 * http://www.apache.org/licenses/LICENSE-2.0
17
 *
18
 * Unless required by applicable law or agreed to in writing, software
19
 * distributed under the License is distributed on an "AS IS" BASIS,
20
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
 * See the License for the specific language governing permissions and
22
 * limitations under the License.
23
 */
24

    
25
require_once("pkg-utils.inc");
26

    
27
echo " done.\n";
28

    
29
echo "Initializing...";
30
echo ".";
31
require_once("/etc/inc/globals.inc");
32
echo ".";
33
require_once("/etc/inc/led.inc");
34
led_normalize();
35
echo ".";
36
if (led_count() >= 3) {
37
	led_kitt();
38
}
39

    
40
/* let the other functions know we're booting */
41
$pkg_interface = 'console';
42
$g['booting'] = true;
43

    
44
/* parse the configuration and include all functions used below */
45
require_once("/etc/inc/config.inc");
46
echo ".";
47
require_once("/etc/inc/config.console.inc");
48
echo ".";
49
require_once("/etc/inc/auth.inc");
50
echo ".";
51
require_once("/etc/inc/functions.inc");
52
echo ".";
53
require_once("/etc/inc/filter.inc");
54
echo ".";
55
require_once("/etc/inc/shaper.inc");
56
echo ".";
57
require_once("/etc/inc/ipsec.inc");
58
echo ".";
59
require_once("/etc/inc/vpn.inc");
60
echo ".";
61
require_once("/etc/inc/openvpn.inc");
62
echo ".";
63
require_once("/etc/inc/captiveportal.inc");
64
echo ".";
65
require_once("/etc/inc/rrd.inc");
66
echo ".";
67
require_once("/etc/inc/pfsense-utils.inc");
68
echo ".";
69

    
70
/* get system memory amount */
71
$memory = get_memory();
72
$physmem = $memory[0];
73
$realmem = $memory[1];
74
echo " done.\n";
75

    
76

    
77
/* save dmesg output to file */
78
system_dmesg_save();
79

    
80
/* check whether config reset is desired (via hardware button on WRAP/ALIX) */
81
system_check_reset_button();
82

    
83
/* remove previous firmware upgrade if present */
84
if (file_exists("/root/firmware.tgz")) {
85
	unlink("/root/firmware.tgz");
86
}
87

    
88
/* Reinstall of packages after reboot has been requested */
89
if (file_exists('/conf/needs_package_sync_after_reboot')) {
90
	touch('/conf/needs_package_sync');
91
	@unlink('/conf/needs_package_sync_after_reboot');
92
}
93

    
94
/* Triggering of the initial setup wizard after reboot has been requested */
95
if (file_exists('/conf/trigger_initial_wizard_after_reboot')) {
96
	touch('/conf/trigger_initial_wizard');
97
	@unlink('/conf/trigger_initial_wizard_after_reboot');
98
}
99

    
100
/* start devd (dhclient now uses it) */
101
echo "Starting device manager (devd)...";
102
mute_kernel_msgs();
103
start_devd();
104
set_device_perms();
105
unmute_kernel_msgs();
106
echo "done.\n";
107

    
108
echo "Loading configuration...";
109
parse_config_bootup();
110
echo "done.\n";
111

    
112
mwexec("/usr/sbin/gnid > {$g['vardb_path']}/uniqueid 2>/dev/null");
113

    
114
/* run any early shell commands specified in config.xml */
115
system_do_shell_commands(1);
116

    
117
// Only do the alternate interface checks if:
118
// 1) The user has not yet run the initial wizard; and
119
// 2) The user has not used the console menu to setup interface assignments
120
if (file_exists("/conf/trigger_initial_wizard") && !file_exists("/conf/assign_complete")) {
121
	check_for_alternate_interfaces();
122
}
123

    
124
/*
125
 *	Determine if we need to throw a interface exception
126
 *	and ask the user to reassign interfaces.  This will
127
 *	avoid a reboot and that is a good thing.
128
 */
129
while (is_interface_mismatch() == true) {
130
	led_assigninterfaces();
131
	if (isset($config['revision'])) {
132
		if (file_exists("{$g['tmp_path']}/missing_interfaces")) {
133
			echo "Warning: Configuration references interfaces that do not exist: " . file_get_contents("{$g['tmp_path']}/missing_interfaces") . "\n";
134
		}
135
		echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
136
	} else {
137
		echo "\nDefault interfaces not found -- Running interface assignment option.\n";
138
	}
139
	$ifaces = get_interface_list();
140
	if (is_array($ifaces)) {
141
		foreach ($ifaces as $iface => $ifdata) {
142
			interfaces_bring_up($iface);
143
		}
144
	}
145
	set_networking_interfaces_ports();
146
	led_kitt();
147
}
148

    
149
/* convert config and clean backups */
150
echo "Updating configuration...";
151
convert_config();
152
echo "done.\n";
153

    
154
echo "Checking config backups consistency...";
155
cleanup_backupcache(true);
156
echo "done.\n";
157

    
158
/* read in /etc/sysctl.conf and set values if needed */
159
echo "Setting up extended sysctls...";
160
system_setup_sysctl();
161
echo "done.\n";
162

    
163
/* enable optional crypto modules */
164
load_crypto();
165

    
166
/* enable optional thermal sensor modules */
167
load_thermal_hardware();
168

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

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

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

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

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

    
184
/* Log the RAM disk restore messages. */
185
if (file_exists("/var/log/restore_ramdisk_store.boot")) {
186
	exec("logger -f /var/log/restore_ramdisk_store.boot");
187
}
188

    
189
echo "Starting Secure Shell Services...";
190
send_event("service reload sshd");
191
echo "done.\n";
192

    
193
/* setup interface microcode which improves tcp/ip speed */
194
echo "Setting up interfaces microcode...";
195
setup_microcode();
196
echo "done.\n";
197

    
198
/* set up interfaces */
199
if (!$debugging) {
200
	mute_kernel_msgs();
201
}
202
interfaces_configure();
203
interfaces_sync_setup();
204
if (!$debugging) {
205
	unmute_kernel_msgs();
206
}
207

    
208
/* re-make hosts file after configuring interfaces */
209
system_hosts_generate();
210

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

    
216
/* generate resolv.conf */
217
system_resolvconf_generate();
218

    
219
/* setup altq + pf */
220
filter_configure_sync();
221

    
222
/* start pflog */
223
echo "Starting PFLOG...";
224
filter_pflog_start();
225
echo "done.\n";
226

    
227
/* reconfigure our gateway monitor */
228
echo "Setting up gateway monitors...";
229
setup_gateways_monitor();
230
echo "done.\n";
231

    
232
/* set up static routes */
233
system_routing_configure();
234

    
235
/* start dnsmasq service */
236
services_dnsmasq_configure();
237

    
238
/* start unbound service */
239
services_unbound_configure();
240

    
241
echo "Synchronizing user settings...";
242
local_sync_accounts();
243
echo "done.\n";
244

    
245
if ($realmem > 0 and $realmem < 65) {
246
	echo "System has less than 65 megabytes of ram {$realmem}.  Delaying webConfigurator startup.\n";
247
	/* start webConfigurator up on final pass */
248
	mwexec("/usr/local/sbin/pfSctl -c 'service restart webgui'");
249
} else {
250
	/* start web server */
251
	system_webgui_start();
252
}
253

    
254
/* configure cron service */
255
echo "Configuring CRON...";
256
configure_cron();
257
echo "done.\n";
258

    
259
/* enable routing */
260
system_routing_enable();
261

    
262
/* Enable ntpd */
263
echo "Starting NTP time client...";
264
system_ntp_configure();
265
echo "done.\n";
266

    
267
/* start load balancer daemon */
268
relayd_configure();
269

    
270
/* configure console menu and serial port*/
271
setup_serial_port();
272

    
273
/* start DHCP service */
274
services_dhcpd_configure();
275

    
276
/* start dhcpleases dhcp hosts leases program */
277
system_dhcpleases_configure();
278

    
279
/* start DHCP relay */
280
services_dhcrelay_configure();
281

    
282
/* start DHCP6 relay */
283
services_dhcrelay6_configure();
284

    
285
/* dyndns service updates */
286
send_event("service reload dyndnsall");
287

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

    
291
/* setup pppoe and pptp */
292
vpn_setup();
293

    
294
/* start the captive portal */
295
captiveportal_configure();
296

    
297
/* start Voucher support */
298
voucher_configure();
299

    
300
/* run any shell commands specified in config.xml */
301
system_do_shell_commands();
302

    
303
/* start IPsec tunnels */
304
$ipsec_dynamic_hosts = vpn_ipsec_configure();
305

    
306
/* start SNMP service */
307
services_snmpd_configure();
308

    
309
/* power down hard drive if needed/set */
310
system_set_harddisk_standby();
311

    
312
/* lock down console if necessary */
313
reload_ttys();
314

    
315
/* load graphing functions */
316
enable_rrd_graphing();
317

    
318
/* enable watchdog if supported */
319
enable_watchdog();
320

    
321
/* if <system><afterbootupshellcmd> exists, execute the command */
322
if ($config['system']['afterbootupshellcmd'] <> "") {
323
	echo "Running afterbootupshellcmd {$config['system']['afterbootupshellcmd']}\n";
324
	mwexec($config['system']['afterbootupshellcmd']);
325
}
326

    
327
if ($physmem < $g['minimum_ram_warning']) {
328
	require_once("/etc/inc/notices.inc");
329
	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);
330
	set_sysctl(array(
331
		"net.inet.tcp.recvspace" => "4096",
332
		"net.inet.tcp.sendspace" => "4096"
333
	));
334
}
335

    
336
/* if we are operating at 1000 then increase timeouts.
337
   this was never accounted for after moving to 1000 hz */
338
$kern_hz = get_single_sysctl('kern.clockrate');
339
$kern_hz = substr($kern_hz, strpos($kern_hz, "hz = ") + 5);
340
$kern_hz = substr($kern_hz, 0, strpos($kern_hz, ","));
341
if ($kern_hz == "1000") {
342
	set_single_sysctl("net.inet.tcp.rexmit_min" , "30");
343
}
344

    
345
/* start the igmpproxy daemon */
346
services_igmpproxy_configure();
347

    
348
/* start the upnp daemon if it is enabled */
349
upnp_start();
350

    
351
/* If powerd is enabled, lets launch it */
352
activate_powerd();
353

    
354
/* Set preferred protocol */
355
prefer_ipv4_or_ipv6();
356

    
357
/* Resync / Reinstall packages if need be */
358
if (file_exists('/conf/needs_package_sync')) {
359
	mark_subsystem_dirty('packagelock');
360
	if (package_reinstall_all()) {
361
		@unlink('/conf/needs_package_sync');
362
	}
363
	clear_subsystem_dirty('packagelock');
364
}
365

    
366
/* Detect installed binary pkgs that are not registered in the system */
367
register_all_installed_packages();
368

    
369
/* Give syslogd a kick after everything else has been initialized, otherwise it can occasionally
370
   fail to route syslog messages properly on both IPv4 and IPv6 */
371
system_syslogd_start();
372

    
373
/* done */
374
unset($g['booting']);
375
@unlink("{$g['varrun_path']}/booting");
376

    
377
/* If there are ipsec dynamic hosts try again to reload the tunnels as rc.newipsecdns does */
378
if ($ipsec_dynamic_hosts) {
379
	vpn_ipsec_configure();
380
}
381
if ($ipsec_dynamic_hosts || !empty($filterdns)) {
382
	filter_configure();
383
}
384

    
385
led_normalize();
386

    
387

    
388
?>
(19-19/78)