You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
41 lines
1.1 KiB
<?php
|
|
|
|
namespace traits;
|
|
|
|
trait init_systems {
|
|
|
|
private static function get_init_system(): string|false {
|
|
$a_init_systems = [
|
|
'/etc/systemd'=>'systemd',
|
|
'/etc/init.d'=>'sys_v_init',
|
|
'/etc/init'=>'upstart',
|
|
'/etc/runlevels'=>'open_rc',
|
|
'/etc/runit'=>'runit',
|
|
];
|
|
foreach($a_init_systems as $init_dir=>$init_system_name) {
|
|
if (file_exists($init_dir) && is_dir($init_dir)) {
|
|
return $init_system_name;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static function service(string $name, string $action = 'restart') {
|
|
$my_init = self::get_init_system();
|
|
if ($my_init === false) {
|
|
return false;
|
|
}
|
|
$namespaced = "\\init_systems\\{$my_init}::service";
|
|
return $namespaced($name, $action);
|
|
}
|
|
|
|
public static function systemctl(string $name, string $action = 'enable') {
|
|
$my_init = self::get_init_system();
|
|
if ($my_init === false) {
|
|
return false;
|
|
}
|
|
$namespaced = "\\init_systems\\{$my_init}::systemctl";
|
|
return $namespaced($name, $action);
|
|
}
|
|
|
|
}
|
|
|