From 6f7cfb10d02eec5c852846f69252139ec95da36d Mon Sep 17 00:00:00 2001 From: Nikolay Brovko Date: Sun, 26 Jan 2020 15:30:05 +0300 Subject: [PATCH] add base functionality to YggdrasilService implementors (not tested) --- src/yggdrasil-service-openrc.vala | 21 +++++++++++++++++---- src/yggdrasil-service-systemd.vala | 19 ++++++++++++++++--- src/yggdrasil-service.vala | 6 +++--- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/yggdrasil-service-openrc.vala b/src/yggdrasil-service-openrc.vala index 1623223..d4321b3 100644 --- a/src/yggdrasil-service-openrc.vala +++ b/src/yggdrasil-service-openrc.vala @@ -17,13 +17,26 @@ namespace Yggtk { public class YggdrasilServiceOpenRC : Object, YggdrasilService { - public bool get_status () { - return false; + public bool get_status () throws SpawnError { + 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"); + } } diff --git a/src/yggdrasil-service-systemd.vala b/src/yggdrasil-service-systemd.vala index 2863bbb..3fa0646 100644 --- a/src/yggdrasil-service-systemd.vala +++ b/src/yggdrasil-service-systemd.vala @@ -17,13 +17,26 @@ namespace Yggtk { 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; } - 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"); + } } diff --git a/src/yggdrasil-service.vala b/src/yggdrasil-service.vala index a7818cb..03e08d0 100644 --- a/src/yggdrasil-service.vala +++ b/src/yggdrasil-service.vala @@ -17,9 +17,9 @@ namespace Yggtk { public interface YggdrasilService : Object { - public abstract bool get_status (); - public abstract void start (); - public abstract void stop (); + public abstract bool get_status () throws SpawnError; + public abstract void start () throws SpawnError; + public abstract void stop () throws SpawnError; }