add base functionality to YggdrasilService implementors (not tested)

This commit is contained in:
Nikolay Brovko 2020-01-26 15:30:05 +03:00
parent c3ca4e0055
commit 6f7cfb10d0
No known key found for this signature in database
GPG Key ID: 32258A3DEC9B6F07
3 changed files with 36 additions and 10 deletions

View File

@ -17,13 +17,26 @@ namespace Yggtk {
public class YggdrasilServiceOpenRC : Object, YggdrasilService { public class YggdrasilServiceOpenRC : Object, YggdrasilService {
public bool get_status () { public bool get_status () throws SpawnError {
return false; string cmd_stdout, cmd_stderr;
int cmd_status = -1;
Process.spawn_command_line_sync ("rc-service yggdrasil status", out cmd_stdout, out cmd_stderr, out cmd_status);
if (cmd_status != 0 || cmd_stderr.length > 0 || cmd_stdout.contains ("stopped")) {
return false;
}
return true;
} }
public void start () {} public void start () throws SpawnError {
Process.spawn_command_line_sync ("pkexec rc-service yggdrasil start");
}
public void stop () {} public void stop () throws SpawnError {
Process.spawn_command_line_sync ("pkexec rc-service yggdrasil stop");
}
} }

View File

@ -17,13 +17,26 @@ namespace Yggtk {
public class YggdrasilServiceSystemd : Object, YggdrasilService { public class YggdrasilServiceSystemd : Object, YggdrasilService {
public bool get_status () { public bool get_status () throws SpawnError {
string cmd_stdout;
int cmd_status = -1;
Process.spawn_command_line_sync ("systemctl status yggdrasil", out cmd_stdout, null, out cmd_status);
if (cmd_status == 0 && cmd_stdout.contains ("active (running)")) {
return true;
}
return false; return false;
} }
public void start () {} public void start () throws SpawnError {
Process.spawn_command_line_sync ("pkexec systemctl start yggdrasil");
}
public void stop () {} public void stop () throws SpawnError {
Process.spawn_command_line_sync ("pkexec systemctl stop yggdrasil");
}
} }

View File

@ -17,9 +17,9 @@ namespace Yggtk {
public interface YggdrasilService : Object { public interface YggdrasilService : Object {
public abstract bool get_status (); public abstract bool get_status () throws SpawnError;
public abstract void start (); public abstract void start () throws SpawnError;
public abstract void stop (); public abstract void stop () throws SpawnError;
} }