PHP Deployment Scripts
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.
 
 

70 lines
2.2 KiB

<?php
namespace init_systems;
// Used by: RHEL, Fedora, Debian, Ubuntu, Arch, openSUSE
class systemd {
private static function _doRoot(): string {
$root = \neato::becomeRoot();
if ($root === true) {
return "";
}
if ($root === false) {
throw new \Exception("Unable to su as root");
}
return $root . " ";
}
private static function getValidActionForService(string $action): string|false {
return match($action) {
'start'=>'start',
'stop'=>'stop',
'status'=>'status',
'restart'=>'restart',
'reload'=>'reload',
'enable'=>'enable',
'disable'=>'disable',
'mask'=>'mask', // disable
'unmask'=>'unmask', // re-enable
'reboot'=>'reboot',
'poweroff'=>'poweroff',
'list-units'=>'list-units',
'list-unit-files'=>'list-unit-files',
'isolate'=>'isolate', // Change system runlevel target
'log'=>'journalctl -u', // View service log
'realtime'=>'journalctl -f', // watch live logs
default=>false,
};
}
private static function getValidActionForSystemCtl(string $action): string|false {
return match($action) {
'start'=>'start',
'stop'=>'stop',
'status'=>'status',
'restart'=>'restart',
'reload'=>'reload',
'enable'=>'enable',
'disable'=>'disable',
default=>false,
};
}
public static function service(string $name, string $action = 'restart') {
$my_action = self::getValidActionForService($action);
exec(self::_doRoot() . \neato::get_super_user_bin . 'service ' . 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 = 'enable') {
$my_action = self::getValidActionForSystemCtl($action);
exec(self::_doRoot() . \neato::get_bin . 'systemctl ' . safeCmd($my_action, $name), $output, $exit_code);
checkForError($exit_code, "Unable to {$action} Service called: {$name}");
return $exit_code;
}
}