summaryrefslogtreecommitdiffstats
path: root/src/etc/rc.start_packages
blob: defe81400eef8e96da13112d98891f2ac36c2063 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/local/bin/php-cgi -f
<?php
/*
 * rc.start_packages
 *
 * part of pfSense (https://www.pfsense.org)
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

require_once("config.inc");
require_once("functions.inc");
require_once("filter.inc");
require_once("shaper.inc");
require_once("captiveportal.inc");
require_once("pkg-utils.inc");
require_once("pfsense-utils.inc");
require_once("service-utils.inc");

if (file_exists("{$g['tmp_path']}/.rc.start_packages.running")) {
	$stat = stat("{$g['tmp_path']}/.rc.start_packages.running");
	if (time() - $stat['mtime'] >= 90) {
		@unlink("{$g['tmp_path']}/.rc.start_packages.running");
	} else {
		log_error("Skipping STARTing packages process because previous/another instance is already running");
		return;
	}
}

@file_put_contents("{$g['tmp_path']}/.rc.start_packages.running", "");

log_error("Restarting/Starting all packages.");

$rcfiles = glob(RCFILEPREFIX . "*.sh");
if (!$rcfiles) {
	$rcfiles = array();
} else {
	$rcfiles = array_flip($rcfiles);
	if (!$rcfiles) {
		$rcfiles = array();
	}
}

if (is_array($config['installedpackages']['package'])) {
	foreach ($config['installedpackages']['package'] as $pkgid => $package) {
		echo " Starting package {$package['name']}...";
		sync_package($package['name']);
		$internal_name = get_package_internal_name($package);
		start_service($internal_name);
		unset($rcfiles[RCFILEPREFIX . strtolower($internal_name) . ".sh"]);
		echo "done.\n";
	}
}

$shell = @popen("/bin/sh", "w");
if ($shell) {
	foreach ($rcfiles as $rcfile => $number) {
		echo " Starting {$rcfile}...";
		fwrite($shell, "{$rcfile} start >>/tmp/bootup_messages 2>&1 &");
		echo "done.\n";
	}

	pclose($shell);
}

@unlink("{$g['tmp_path']}/.rc.start_packages.running");
?>
OpenPOWER on IntegriCloud