modifications to system commands
This commit is contained in:
parent
6407495292
commit
ceb7e502ce
|
@ -57,6 +57,7 @@ pub fn get_peach_config_defaults() -> HashMap<String, String> {
|
|||
("DYN_NAMESERVER", "ns.peachcloud.org"),
|
||||
("DYN_ENABLED", "false"),
|
||||
("SSB_ADMIN_IDS", ""),
|
||||
("SYSTEM_MANAGER", "systemd"),
|
||||
("ADMIN_PASSWORD_HASH", "47"),
|
||||
("TEMPORARY_PASSWORD_HASH", ""),
|
||||
("GO_SBOT_DATADIR", "/home/peach/.ssb-go"),
|
||||
|
|
|
@ -18,6 +18,7 @@ pub enum PeachWebError {
|
|||
Json(JsonError),
|
||||
OsString,
|
||||
PeachLib { source: PeachError, msg: String },
|
||||
System(String),
|
||||
Yaml(YamlError),
|
||||
}
|
||||
|
||||
|
@ -31,6 +32,7 @@ impl std::error::Error for PeachWebError {
|
|||
PeachWebError::Json(ref source) => Some(source),
|
||||
PeachWebError::OsString => None,
|
||||
PeachWebError::PeachLib { ref source, .. } => Some(source),
|
||||
PeachWebError::System(_) => None,
|
||||
PeachWebError::Yaml(ref source) => Some(source),
|
||||
}
|
||||
}
|
||||
|
@ -54,6 +56,9 @@ impl std::fmt::Display for PeachWebError {
|
|||
"Filesystem error: failed to convert OsString to String for go-ssb directory path"
|
||||
),
|
||||
PeachWebError::PeachLib { ref source, .. } => write!(f, "{}", source),
|
||||
PeachWebError::System(ref msg) => {
|
||||
write!(f, "system error: {}", msg)
|
||||
}
|
||||
PeachWebError::Yaml(ref source) => write!(f, "Serde YAML error: {}", source),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,23 +24,50 @@ use crate::{error::PeachWebError, utils::sbot};
|
|||
|
||||
// SBOT HELPER FUNCTIONS
|
||||
|
||||
/// Executes a systemctl command for the go-sbot.service process.
|
||||
pub fn systemctl_sbot_cmd(cmd: &str) -> Result<Output, PeachWebError> {
|
||||
let output = Command::new("sudo")
|
||||
.arg("systemctl")
|
||||
.arg(cmd)
|
||||
.arg(config_manager::get_config_value("GO_SBOT_SERVICE")?)
|
||||
.output()?;
|
||||
Ok(output)
|
||||
/// On non-docker based deployments (peachcloud, yunohost), we use systemctl
|
||||
/// On docker-based deployments, we use supervisord
|
||||
/// This utility function calls the correct system calls based on these parameters.
|
||||
pub fn system_sbot_cmd(cmd: &str) -> Result<Output, PeachWebError> {
|
||||
let system_manager = config_manager::get_config_value("SYSTEM_MANAGER")?;
|
||||
match system_manager.as_str() {
|
||||
"systemd" => {
|
||||
let output = Command::new("sudo")
|
||||
.arg("systemctl")
|
||||
.arg(cmd)
|
||||
.arg(config_manager::get_config_value("GO_SBOT_SERVICE")?)
|
||||
.output()?;
|
||||
Ok(output)
|
||||
},
|
||||
"supervisord" => {
|
||||
match cmd {
|
||||
"enable" => {
|
||||
// TODO: implement this
|
||||
},
|
||||
"disable" => {
|
||||
// TODO: implement this
|
||||
},
|
||||
_ => {
|
||||
let output = Command::new("supervisorctl")
|
||||
.arg(cmd)
|
||||
.arg(config_manager::get_config_value("GO_SBOT_SERVICE")?)
|
||||
.output()?;
|
||||
Ok(output)
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
PeachWebError::System(format!("Invalid configuration for SYSTEM_MANAGER: {:?}", system_manager))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Executes a systemctl stop command followed by start command.
|
||||
/// Executes a system stop command followed by start command.
|
||||
/// Returns a redirect with a flash message stating the output of the restart attempt.
|
||||
pub fn restart_sbot_process() -> (String, String) {
|
||||
debug!("Restarting go-sbot.service");
|
||||
match systemctl_sbot_cmd("stop") {
|
||||
match system_sbot_cmd("stop") {
|
||||
// if stop was successful, try to start the process
|
||||
Ok(_) => match systemctl_sbot_cmd("start") {
|
||||
Ok(_) => match system_sbot_cmd("start") {
|
||||
Ok(_) => (
|
||||
"success".to_string(),
|
||||
"Updated configuration and restarted the sbot process".to_string(),
|
||||
|
|
Loading…
Reference in New Issue