Update services for FreeBSD
This commit is contained in:
+108
-26
@@ -645,17 +645,41 @@ function update_file_permissions($text, settings $settings) {
|
||||
*/
|
||||
function upgrade_services($text, settings $settings) {
|
||||
//echo ($text['description-upgrade_services'] ?? "")."\n";
|
||||
$core_files = glob(dirname(__DIR__, 2) . "/core/*/resources/service/*.service");
|
||||
$app_files = glob(dirname(__DIR__, 2) . "/app/*/resources/service/*.service");
|
||||
$service_files = array_merge($core_files, $app_files);
|
||||
|
||||
// Determine the search file name
|
||||
if (stristr(PHP_OS, 'Linux')) {
|
||||
$search_file_name = 'debian';
|
||||
}
|
||||
if (stristr(PHP_OS, 'FreeBSD')) {
|
||||
$search_file_name = 'freebsd';
|
||||
}
|
||||
|
||||
// Get the list of services
|
||||
$core_files = glob(dirname(__DIR__, 4) . "/core/*/resources/service/".$search_file_name.".service");
|
||||
$app_files = glob(dirname(__DIR__, 4) . "/app/*/resources/service/".$search_file_name.".service");
|
||||
$service_files = array_merge($core_files, $app_files);
|
||||
|
||||
if (!empty($service_files)) {
|
||||
foreach($service_files as $file) {
|
||||
// Set a variable for the service name
|
||||
$service_name = find_service_name($file);
|
||||
// Sanitize the service name
|
||||
$service_name = preg_replace('/[^a-zA-Z0-9_]/', '', $service_name);
|
||||
// Send the service name to the console
|
||||
echo " Name: ".$service_name."\n";
|
||||
system("cp " . escapeshellarg($file) . " /etc/systemd/system/" . escapeshellarg($service_name) . ".service");
|
||||
system("systemctl daemon-reload");
|
||||
system("systemctl enable " . escapeshellarg($service_name));
|
||||
system("systemctl start " . escapeshellarg($service_name));
|
||||
// Install and start the service
|
||||
if (stristr(PHP_OS, 'Linux')) {
|
||||
system("cp " . escapeshellarg($file) . " /etc/systemd/system/" . escapeshellarg($service_name) . ".service");
|
||||
system("systemctl daemon-reload");
|
||||
system("systemctl enable " . escapeshellarg($service_name));
|
||||
system("systemctl start " . escapeshellarg($service_name));
|
||||
}
|
||||
if (stristr(PHP_OS, 'FreeBSD')) {
|
||||
system("cp " . $file . " /usr/local/etc/rc.d/".$service_name);
|
||||
system("sysrc " . $service_name . "_enable=\"YES\"");
|
||||
system("chmod 755 /usr/local/etc/rc.d/" . $service_name);
|
||||
system("service " . $service_name . " start");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -671,13 +695,37 @@ function upgrade_services($text, settings $settings) {
|
||||
*/
|
||||
function stop_services($text, settings $settings) {
|
||||
//echo ($text['description-stop_services'] ?? "")."\n";
|
||||
$core_files = glob(dirname(__DIR__, 2) . "/core/*/resources/service/*.service");
|
||||
$app_files = glob(dirname(__DIR__, 2) . "/app/*/resources/service/*.service");
|
||||
|
||||
// Determine the search file name
|
||||
if (stristr(PHP_OS, 'Linux')) {
|
||||
$search_file_name = 'debian';
|
||||
}
|
||||
if (stristr(PHP_OS, 'FreeBSD')) {
|
||||
$search_file_name = 'freebsd';
|
||||
}
|
||||
|
||||
// Get the list of services
|
||||
$core_files = glob(dirname(__DIR__, 4) . "/core/*/resources/service/".$search_file_name.".service");
|
||||
$app_files = glob(dirname(__DIR__, 4) . "/app/*/resources/service/".$search_file_name.".service");
|
||||
$service_files = array_merge($core_files, $app_files);
|
||||
foreach($service_files as $file) {
|
||||
$service_name = find_service_name($file);
|
||||
echo " Name: ".$service_name."\n";
|
||||
system("systemctl stop ".$service_name);
|
||||
|
||||
// Stop each of the services
|
||||
if (!empty($service_files)) {
|
||||
foreach($service_files as $file) {
|
||||
// Set a variable for the service name
|
||||
$service_name = find_service_name($file);
|
||||
// Sanitize the service name
|
||||
$service_name = preg_replace('/[^a-zA-Z0-9_]/', '', $service_name);
|
||||
// Send the service name to the console
|
||||
echo " Name: " . $service_name . "\n";
|
||||
// Stop the service
|
||||
if (stristr(PHP_OS, 'Linux')) {
|
||||
system("systemctl stop " . $service_name);
|
||||
}
|
||||
if (stristr(PHP_OS, 'FreeBSD')) {
|
||||
system("service " . $service_name . " stop");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -691,13 +739,37 @@ function stop_services($text, settings $settings) {
|
||||
*/
|
||||
function restart_services($text, settings $settings) {
|
||||
//echo ($text['description-restart_services'] ?? "")."\n";
|
||||
$core_files = glob(dirname(__DIR__, 2) . "/core/*/resources/service/*.service");
|
||||
$app_files = glob(dirname(__DIR__, 2) . "/app/*/resources/service/*.service");
|
||||
|
||||
// Determine the search file name
|
||||
if (stristr(PHP_OS, 'Linux')) {
|
||||
$search_file_name = 'debian';
|
||||
}
|
||||
if (stristr(PHP_OS, 'FreeBSD')) {
|
||||
$search_file_name = 'freebsd';
|
||||
}
|
||||
|
||||
// Get the list of services
|
||||
$core_files = glob(dirname(__DIR__, 4) . "/core/*/resources/service/".$search_file_name.".service");
|
||||
$app_files = glob(dirname(__DIR__, 4) . "/app/*/resources/service/".$search_file_name.".service");
|
||||
$service_files = array_merge($core_files, $app_files);
|
||||
foreach($service_files as $file) {
|
||||
$service_name = find_service_name($file);
|
||||
echo " Name: ".$service_name."\n";
|
||||
system("systemctl restart ".$service_name);
|
||||
|
||||
// Restart each of the services
|
||||
if (!empty($service_files)) {
|
||||
foreach($service_files as $file) {
|
||||
// Set a variable for the service name
|
||||
$service_name = find_service_name($file);
|
||||
// Sanitize the service name
|
||||
$service_name = preg_replace('/[^a-zA-Z0-9_]/', '', $service_name);
|
||||
// Send the service name to the console
|
||||
echo " Name: ".$service_name."\n";
|
||||
// Restart the service
|
||||
if (stristr(PHP_OS, 'Linux')) {
|
||||
system("systemctl restart ".$service_name);
|
||||
}
|
||||
if (stristr(PHP_OS, 'FreeBSD')) {
|
||||
system("service " . $service_name . " restart");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -709,13 +781,23 @@ function restart_services($text, settings $settings) {
|
||||
* @return string|null The service name if found, otherwise an empty string.
|
||||
*/
|
||||
function find_service_name(string $file) {
|
||||
$parsed = parse_ini_file($file);
|
||||
$exec_cmd = $parsed['ExecStart'];
|
||||
$parts = explode(' ', $exec_cmd);
|
||||
$php_file = $parts[1] ?? '';
|
||||
if (!empty($php_file)) {
|
||||
$path_info = pathinfo($php_file);
|
||||
return $path_info['filename'];
|
||||
if (stristr(PHP_OS, 'Linux')) {
|
||||
$parsed = parse_ini_file($file);
|
||||
$exec_cmd = $parsed['ExecStart'];
|
||||
$parts = explode(' ', $exec_cmd);
|
||||
$php_file = $parts[1] ?? '';
|
||||
if (!empty($php_file)) {
|
||||
$path_info = pathinfo($php_file);
|
||||
return $path_info['filename'];
|
||||
}
|
||||
}
|
||||
if (stristr(PHP_OS, 'FreeBSD')) {
|
||||
$service_content = file_get_contents($file);
|
||||
if (preg_match('/^\s*name\s*=\s*["\']([^"\']+)["\']\s*$/m', $service_content, $name_matches)) {
|
||||
if (!empty($name_matches[1])) {
|
||||
return $name_matches[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user