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.
45 lines
1.3 KiB
45 lines
1.3 KiB
<?php
|
|
|
|
namespace init_systems;
|
|
|
|
class sys_v_init {
|
|
|
|
private static function get_valid_action_for_service(string $action): string|false {
|
|
return match($action) {
|
|
'start'=>'start',
|
|
'stop'=>'stop',
|
|
'status'=>'status',
|
|
'restart'=>'restart',
|
|
'reload'=>'reload',
|
|
'enable'=>'enable',
|
|
'disable'=>'disable',
|
|
default=>false,
|
|
};
|
|
}
|
|
|
|
private static function get_valid_action_for_system_ctl(string $action): string|false {
|
|
return match($action) {
|
|
'list'=>'--list',
|
|
'on'=>'on',
|
|
'off'=>'off',
|
|
default=>false,
|
|
};
|
|
}
|
|
|
|
public static function service(string $name, string $action = 'restart') {
|
|
$my_action = self::get_valid_action_for_service($action);
|
|
exec(\neato::get_super_user_bin . '/etc/init.d/' . safeCmd($name, $my_action), $output, $exit_code);
|
|
display($output);
|
|
checkForError($exit_code, "Unable to {$action} Service called: {$name}");
|
|
return $exit_code;
|
|
}
|
|
|
|
public static function systemctl(string $name, string $action = 'on') {
|
|
$my_action = self::get_valid_action_for_system_ctl($action);
|
|
exec(\neato::get_bin . 'chkconfig ' . safeCmd($action, $name), $output, $exit_code);
|
|
checkForError($exit_code, "Unable to {$action} Service called: {$name}");
|
|
return $exit_code;
|
|
}
|
|
|
|
|
|
}
|
|
|