From b24fb387b961e9fe2cab67d6b3aa5b99b3d5fd2a Mon Sep 17 00:00:00 2001 From: notplants Date: Wed, 27 Jul 2022 19:03:36 +0200 Subject: [PATCH] Fix supervisorctl --- .../routes/settings/scuttlebutt/configure.rs | 4 ++-- .../routes/settings/scuttlebutt/restart.rs | 6 ++--- .../src/routes/settings/scuttlebutt/start.rs | 4 ++-- .../src/routes/settings/scuttlebutt/stop.rs | 4 ++-- peach-web/src/utils/sbot.rs | 22 +++++++++++++------ 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/peach-web/src/routes/settings/scuttlebutt/configure.rs b/peach-web/src/routes/settings/scuttlebutt/configure.rs index d2a54cf..8c85348 100644 --- a/peach-web/src/routes/settings/scuttlebutt/configure.rs +++ b/peach-web/src/routes/settings/scuttlebutt/configure.rs @@ -243,13 +243,13 @@ pub fn handle_form(request: &Request, restart: bool) -> Response { match data.startup { true => { debug!("Enabling go-sbot.service"); - if let Err(e) = sbot::systemctl_sbot_cmd("enable") { + if let Err(e) = sbot::system_sbot_cmd("enable") { warn!("Failed to enable go-sbot.service: {}", e) } } false => { debug!("Disabling go-sbot.service"); - if let Err(e) = sbot::systemctl_sbot_cmd("disable") { + if let Err(e) = sbot::system_sbot_cmd("disable") { warn!("Failed to disable go-sbot.service: {}", e) } } diff --git a/peach-web/src/routes/settings/scuttlebutt/restart.rs b/peach-web/src/routes/settings/scuttlebutt/restart.rs index 3e25b73..4322d5b 100644 --- a/peach-web/src/routes/settings/scuttlebutt/restart.rs +++ b/peach-web/src/routes/settings/scuttlebutt/restart.rs @@ -1,7 +1,7 @@ use log::info; use rouille::Response; -use crate::utils::{flash::FlashResponse, sbot::systemctl_sbot_cmd}; +use crate::utils::{flash::FlashResponse, sbot}; // ROUTE: /settings/scuttlebutt/restart @@ -10,9 +10,9 @@ use crate::utils::{flash::FlashResponse, sbot::systemctl_sbot_cmd}; /// the attempt via a flash message. pub fn restart_sbot() -> Response { info!("Restarting go-sbot.service"); - let (flash_name, flash_msg) = match systemctl_sbot_cmd("stop") { + let (flash_name, flash_msg) = match sbot::system_sbot_cmd("stop") { // if stop was successful, try to start the process - Ok(_) => match systemctl_sbot_cmd("start") { + Ok(_) => match sbot::system_sbot_cmd("start") { Ok(_) => ( "flash_name=success".to_string(), "flash_msg=Sbot process has been restarted".to_string(), diff --git a/peach-web/src/routes/settings/scuttlebutt/start.rs b/peach-web/src/routes/settings/scuttlebutt/start.rs index 2ee7f4e..4dbcf9b 100644 --- a/peach-web/src/routes/settings/scuttlebutt/start.rs +++ b/peach-web/src/routes/settings/scuttlebutt/start.rs @@ -1,7 +1,7 @@ use log::info; use rouille::Response; -use crate::utils::{flash::FlashResponse, sbot::systemctl_sbot_cmd}; +use crate::utils::{flash::FlashResponse, sbot}; // ROUTE: /settings/scuttlebutt/start @@ -10,7 +10,7 @@ use crate::utils::{flash::FlashResponse, sbot::systemctl_sbot_cmd}; /// the attempt via a flash message. pub fn start_sbot() -> Response { info!("Starting go-sbot.service"); - let (flash_name, flash_msg) = match systemctl_sbot_cmd("start") { + let (flash_name, flash_msg) = match sbot::system_sbot_cmd("start") { Ok(_) => ( "flash_name=success".to_string(), "flash_msg=Sbot process has been started".to_string(), diff --git a/peach-web/src/routes/settings/scuttlebutt/stop.rs b/peach-web/src/routes/settings/scuttlebutt/stop.rs index d548698..256957a 100644 --- a/peach-web/src/routes/settings/scuttlebutt/stop.rs +++ b/peach-web/src/routes/settings/scuttlebutt/stop.rs @@ -1,7 +1,7 @@ use log::info; use rouille::Response; -use crate::utils::{flash::FlashResponse, sbot::systemctl_sbot_cmd}; +use crate::utils::{flash::FlashResponse, sbot}; // ROUTE: /settings/scuttlebutt/stop @@ -10,7 +10,7 @@ use crate::utils::{flash::FlashResponse, sbot::systemctl_sbot_cmd}; /// the attempt via a flash message. pub fn stop_sbot() -> Response { info!("Stopping go-sbot.service"); - let (flash_name, flash_msg) = match systemctl_sbot_cmd("stop") { + let (flash_name, flash_msg) = match sbot::system_sbot_cmd("stop") { Ok(_) => ( "flash_name=success".to_string(), "flash_msg=Sbot process has been stopped".to_string(), diff --git a/peach-web/src/utils/sbot.rs b/peach-web/src/utils/sbot.rs index c3310a5..e192560 100644 --- a/peach-web/src/utils/sbot.rs +++ b/peach-web/src/utils/sbot.rs @@ -37,15 +37,22 @@ pub fn system_sbot_cmd(cmd: &str) -> Result { .arg(config_manager::get_config_value("GO_SBOT_SERVICE")?) .output()?; Ok(output) - }, + } "supervisord" => { match cmd { "enable" => { // TODO: implement this - }, + let output = Command::new("echo") + .arg("implement this (enable)") + .output()?; + Ok(output) + } "disable" => { - // TODO: implement this - }, + let output = Command::new("echo") + .arg("implement this (disable)") + .output()?; + Ok(output) + } _ => { let output = Command::new("supervisorctl") .arg(cmd) @@ -54,10 +61,11 @@ pub fn system_sbot_cmd(cmd: &str) -> Result { Ok(output) } } - }, - _ => { - PeachWebError::System(format!("Invalid configuration for SYSTEM_MANAGER: {:?}", system_manager)) } + _ => Err(PeachWebError::System(format!( + "Invalid configuration for SYSTEM_MANAGER: {:?}", + system_manager + ))), } }