Update services for FreeBSD
This commit is contained in:
@@ -319,39 +319,46 @@ class services {
|
|||||||
$services = [];
|
$services = [];
|
||||||
|
|
||||||
if ($source == 'files') {
|
if ($source == '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
|
// Get the list of services
|
||||||
$core_files = glob(dirname(__DIR__, 4) . "/core/*/resources/service/*.service");
|
$core_files = glob(dirname(__DIR__, 4) . "/core/*/resources/service/".$search_file_name.".service");
|
||||||
$app_files = glob(dirname(__DIR__, 4) . "/app/*/resources/service/*.service");
|
$app_files = glob(dirname(__DIR__, 4) . "/app/*/resources/service/".$search_file_name.".service");
|
||||||
$service_files = array_merge($core_files, $app_files);
|
$service_files = array_merge($core_files, $app_files);
|
||||||
|
|
||||||
// Build the services array
|
// Build the services array
|
||||||
$services = [];
|
$services = [];
|
||||||
if (stristr(PHP_OS, 'Linux')) {
|
|
||||||
$i = 0;
|
|
||||||
$service_status = [];
|
|
||||||
foreach($service_files as $file) {
|
|
||||||
// Get the service name
|
|
||||||
$service_name = $this->find_service_name($file);
|
|
||||||
|
|
||||||
// Get the service status
|
$i = 0;
|
||||||
if ($details) {
|
$service_status = [];
|
||||||
$service_status = $this->is_running($service_name);
|
foreach($service_files as $file) {
|
||||||
}
|
// Get the service name
|
||||||
|
$service_name = $this->find_service_name($file);
|
||||||
|
|
||||||
// Build the services array
|
// Get the service status
|
||||||
$services[$i]['name'] = $service_name;
|
if ($details) {
|
||||||
$services[$i]['file'] = $file;
|
$service_status = $this->is_running($service_name);
|
||||||
|
|
||||||
// Add the service status to the array
|
|
||||||
if ($details) {
|
|
||||||
$services[$i]['pid'] = $service_status['pid'];
|
|
||||||
$services[$i]['status'] = $service_status['status'];
|
|
||||||
$services[$i]['etime'] = $service_status['etime'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Increment
|
|
||||||
$i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Build the services array
|
||||||
|
$services[$i]['name'] = $service_name;
|
||||||
|
$services[$i]['file'] = $file;
|
||||||
|
|
||||||
|
// Add the service status to the array
|
||||||
|
if ($details) {
|
||||||
|
$services[$i]['pid'] = $service_status['pid'];
|
||||||
|
$services[$i]['status'] = $service_status['status'];
|
||||||
|
$services[$i]['etime'] = $service_status['etime'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Increment
|
||||||
|
$i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,32 +377,32 @@ class services {
|
|||||||
unset($sql, $parameters);
|
unset($sql, $parameters);
|
||||||
|
|
||||||
$services = [];
|
$services = [];
|
||||||
if (stristr(PHP_OS, 'Linux')) {
|
|
||||||
$i = 0;
|
|
||||||
$service_status = [];
|
|
||||||
foreach($database_services as $row) {
|
|
||||||
// Get the service status
|
|
||||||
if ($details) {
|
|
||||||
$service_status = $this->is_running($row['service_name']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build the services array
|
$i = 0;
|
||||||
$services[$i]['name'] = $row['service_name'];
|
$service_status = [];
|
||||||
$services[$i]['file'] = $row['service_file'];
|
foreach($database_services as $row) {
|
||||||
$services[$i]['enabled'] = $row['service_enabled'];
|
// Get the service status
|
||||||
//$services[$i]['file'] = $file;
|
if ($details) {
|
||||||
|
$service_status = $this->is_running($row['service_name']);
|
||||||
// Add the service status to the array
|
|
||||||
if ($details) {
|
|
||||||
$services[$i]['pid'] = $service_status['pid'];
|
|
||||||
$services[$i]['status'] = $service_status['status'];
|
|
||||||
$services[$i]['etime'] = $service_status['etime'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Increment
|
|
||||||
$i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Build the services array
|
||||||
|
$services[$i]['name'] = $row['service_name'];
|
||||||
|
$services[$i]['file'] = $row['service_file'];
|
||||||
|
$services[$i]['enabled'] = $row['service_enabled'];
|
||||||
|
//$services[$i]['file'] = $file;
|
||||||
|
|
||||||
|
// Add the service status to the array
|
||||||
|
if ($details) {
|
||||||
|
$services[$i]['pid'] = $service_status['pid'];
|
||||||
|
$services[$i]['status'] = $service_status['status'];
|
||||||
|
$services[$i]['etime'] = $service_status['etime'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Increment
|
||||||
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the service array
|
// Return the service array
|
||||||
@@ -571,14 +578,20 @@ class services {
|
|||||||
|
|
||||||
// Upgrade the service
|
// Upgrade the service
|
||||||
if (stristr(PHP_OS, 'Linux')) {
|
if (stristr(PHP_OS, 'Linux')) {
|
||||||
system("cp " . escapeshellarg($service['file']) . " /etc/systemd/system/" . escapeshellarg($service['name']) . ".service");
|
system("cp " . escapeshellarg($service['file']) . " /etc/systemd/system/" . escapeshellarg($service_name) . ".service");
|
||||||
system("systemctl daemon-reload");
|
system("systemctl daemon-reload");
|
||||||
system("systemctl enable " . escapeshellarg($service['name']));
|
system("systemctl enable " . escapeshellarg($service_name));
|
||||||
system("systemctl start " . escapeshellarg($service['name']));
|
system("systemctl start " . escapeshellarg($service_name));
|
||||||
}
|
}
|
||||||
if (stristr(PHP_OS, 'BSD')) {
|
if (stristr(PHP_OS, 'BSD')) {
|
||||||
if ($service['enabled'] == 'true') {
|
if ($service['enabled'] == 'true') {
|
||||||
system("service ".escapeshellarg($service['name']). "start");
|
// Install the service
|
||||||
|
system("cp " . $service['file'] . " /usr/local/etc/rc.d/".$service_name);
|
||||||
|
system("sysrc " . $service_name . "_enable=\"YES\"");
|
||||||
|
system("chmod 755 /usr/local/etc/rc.d/" . $service_name);
|
||||||
|
|
||||||
|
// Start the service
|
||||||
|
system("service ".escapeshellarg(service_name). "start");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -761,13 +774,23 @@ class services {
|
|||||||
* @return string|null The service name if found, otherwise an empty string.
|
* @return string|null The service name if found, otherwise an empty string.
|
||||||
*/
|
*/
|
||||||
public function find_service_name(string $file) {
|
public function find_service_name(string $file) {
|
||||||
$parsed = parse_ini_file($file);
|
if (stristr(PHP_OS, 'Linux')) {
|
||||||
$exec_cmd = $parsed['ExecStart'];
|
$parsed = parse_ini_file($file);
|
||||||
$parts = explode(' ', $exec_cmd);
|
$exec_cmd = $parsed['ExecStart'];
|
||||||
$php_file = $parts[1] ?? '';
|
$parts = explode(' ', $exec_cmd);
|
||||||
if (!empty($php_file)) {
|
$php_file = $parts[1] ?? '';
|
||||||
$path_info = pathinfo($php_file);
|
if (!empty($php_file)) {
|
||||||
return $path_info['filename'];
|
$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 '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|||||||
+108
-26
@@ -645,17 +645,41 @@ function update_file_permissions($text, settings $settings) {
|
|||||||
*/
|
*/
|
||||||
function upgrade_services($text, settings $settings) {
|
function upgrade_services($text, settings $settings) {
|
||||||
//echo ($text['description-upgrade_services'] ?? "")."\n";
|
//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");
|
// Determine the search file name
|
||||||
$service_files = array_merge($core_files, $app_files);
|
|
||||||
if (stristr(PHP_OS, 'Linux')) {
|
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) {
|
foreach($service_files as $file) {
|
||||||
|
// Set a variable for the service name
|
||||||
$service_name = find_service_name($file);
|
$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";
|
echo " Name: ".$service_name."\n";
|
||||||
system("cp " . escapeshellarg($file) . " /etc/systemd/system/" . escapeshellarg($service_name) . ".service");
|
// Install and start the service
|
||||||
system("systemctl daemon-reload");
|
if (stristr(PHP_OS, 'Linux')) {
|
||||||
system("systemctl enable " . escapeshellarg($service_name));
|
system("cp " . escapeshellarg($file) . " /etc/systemd/system/" . escapeshellarg($service_name) . ".service");
|
||||||
system("systemctl start " . escapeshellarg($service_name));
|
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) {
|
function stop_services($text, settings $settings) {
|
||||||
//echo ($text['description-stop_services'] ?? "")."\n";
|
//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);
|
$service_files = array_merge($core_files, $app_files);
|
||||||
foreach($service_files as $file) {
|
|
||||||
$service_name = find_service_name($file);
|
// Stop each of the services
|
||||||
echo " Name: ".$service_name."\n";
|
if (!empty($service_files)) {
|
||||||
system("systemctl stop ".$service_name);
|
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) {
|
function restart_services($text, settings $settings) {
|
||||||
//echo ($text['description-restart_services'] ?? "")."\n";
|
//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);
|
$service_files = array_merge($core_files, $app_files);
|
||||||
foreach($service_files as $file) {
|
|
||||||
$service_name = find_service_name($file);
|
// Restart each of the services
|
||||||
echo " Name: ".$service_name."\n";
|
if (!empty($service_files)) {
|
||||||
system("systemctl restart ".$service_name);
|
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.
|
* @return string|null The service name if found, otherwise an empty string.
|
||||||
*/
|
*/
|
||||||
function find_service_name(string $file) {
|
function find_service_name(string $file) {
|
||||||
$parsed = parse_ini_file($file);
|
if (stristr(PHP_OS, 'Linux')) {
|
||||||
$exec_cmd = $parsed['ExecStart'];
|
$parsed = parse_ini_file($file);
|
||||||
$parts = explode(' ', $exec_cmd);
|
$exec_cmd = $parsed['ExecStart'];
|
||||||
$php_file = $parts[1] ?? '';
|
$parts = explode(' ', $exec_cmd);
|
||||||
if (!empty($php_file)) {
|
$php_file = $parts[1] ?? '';
|
||||||
$path_info = pathinfo($php_file);
|
if (!empty($php_file)) {
|
||||||
return $path_info['filename'];
|
$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 '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user