add routes and helpers for starting, stopping and restarting the sbot
This commit is contained in:
33
peach-web/src/routes/settings/scuttlebutt/restart.rs
Normal file
33
peach-web/src/routes/settings/scuttlebutt/restart.rs
Normal file
@ -0,0 +1,33 @@
|
||||
use log::info;
|
||||
use rouille::Response;
|
||||
|
||||
use crate::utils::{flash::FlashResponse, sbot::systemctl_sbot_cmd};
|
||||
|
||||
// ROUTE: /settings/scuttlebutt/restart
|
||||
|
||||
/// Attempt to restart the go-sbot.service process.
|
||||
/// Redirect to the Scuttlebutt settings menu and communicate the outcome of
|
||||
/// 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") {
|
||||
// if stop was successful, try to start the process
|
||||
Ok(_) => match systemctl_sbot_cmd("start") {
|
||||
Ok(_) => (
|
||||
"flash_name=success".to_string(),
|
||||
"flash_msg=Sbot process has been restarted".to_string(),
|
||||
),
|
||||
Err(e) => (
|
||||
"flash_name=error".to_string(),
|
||||
format!("flash_msg=Failed to start the sbot process: {}", e),
|
||||
),
|
||||
},
|
||||
Err(e) => (
|
||||
"flash_name=error".to_string(),
|
||||
format!("flash_msg=Failed to stop the sbot process: {}", e),
|
||||
),
|
||||
};
|
||||
|
||||
// redirect to the scuttlebutt settings menu
|
||||
Response::redirect_303("/settings/scuttlebutt").add_flash(flash_name, flash_msg)
|
||||
}
|
Reference in New Issue
Block a user