1
|
#!/usr/local/bin/php-cgi -f
|
2
|
<?php
|
3
|
/*
|
4
|
* rc.start_packages
|
5
|
*
|
6
|
* part of pfSense (https://www.pfsense.org)
|
7
|
* Copyright (c) 2004-2013 BSD Perimeter
|
8
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
9
|
* Copyright (c) 2014-2021 Rubicon Communications, LLC (Netgate)
|
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("config.inc");
|
26
|
require_once("functions.inc");
|
27
|
require_once("filter.inc");
|
28
|
require_once("shaper.inc");
|
29
|
require_once("captiveportal.inc");
|
30
|
require_once("pkg-utils.inc");
|
31
|
require_once("pfsense-utils.inc");
|
32
|
require_once("service-utils.inc");
|
33
|
|
34
|
if (file_exists("{$g['tmp_path']}/.rc.start_packages.running")) {
|
35
|
$stat = stat("{$g['tmp_path']}/.rc.start_packages.running");
|
36
|
if (time() - $stat['mtime'] >= 90) {
|
37
|
@unlink("{$g['tmp_path']}/.rc.start_packages.running");
|
38
|
} else {
|
39
|
log_error("Skipping STARTing packages process because previous/another instance is already running");
|
40
|
return;
|
41
|
}
|
42
|
}
|
43
|
|
44
|
if (file_exists("{$g['conf_path']}/needs_package_sync")) {
|
45
|
log_error("Skipping STARTing packages process because package reinstallation is pending.");
|
46
|
return;
|
47
|
}
|
48
|
|
49
|
@file_put_contents("{$g['tmp_path']}/.rc.start_packages.running", "");
|
50
|
|
51
|
log_error("Restarting/Starting all packages.");
|
52
|
|
53
|
$rcfiles = glob(RCFILEPREFIX . "*.sh");
|
54
|
if (!$rcfiles) {
|
55
|
$rcfiles = array();
|
56
|
} else {
|
57
|
$rcfiles = array_flip($rcfiles);
|
58
|
if (!$rcfiles) {
|
59
|
$rcfiles = array();
|
60
|
}
|
61
|
}
|
62
|
|
63
|
if (is_array($config['installedpackages']['package'])) {
|
64
|
foreach ($config['installedpackages']['package'] as $pkgid => $package) {
|
65
|
echo " Starting package {$package['name']}...";
|
66
|
sync_package($package['name']);
|
67
|
$internal_name = get_package_internal_name($package);
|
68
|
start_service($internal_name, true);
|
69
|
unset($rcfiles[RCFILEPREFIX . strtolower($internal_name) . ".sh"]);
|
70
|
echo "done.\n";
|
71
|
}
|
72
|
}
|
73
|
|
74
|
$shell = @popen("/bin/sh", "w");
|
75
|
if ($shell) {
|
76
|
foreach ($rcfiles as $rcfile => $number) {
|
77
|
echo " Starting {$rcfile}...";
|
78
|
fwrite($shell, "{$rcfile} start >>/tmp/bootup_messages 2>&1 &");
|
79
|
echo "done.\n";
|
80
|
}
|
81
|
|
82
|
pclose($shell);
|
83
|
}
|
84
|
|
85
|
@unlink("{$g['tmp_path']}/.rc.start_packages.running");
|
86
|
?>
|