[pbs-devel] [PATCH v2 proxmox-backup 09/15] pbs-manager: add 'send-command' command
Hannes Laimer
h.laimer at proxmox.com
Mon Aug 30 13:14:59 CEST 2021
Relays a command to the superuser commandSocket, this is necessary
because the path to the socket is prefixed with a '\0' and can therefore
not really be addressed from outside the rust code.
---
src/bin/proxmox-backup-manager.rs | 41 +++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs
index 93d6de57..a07f69f1 100644
--- a/src/bin/proxmox-backup-manager.rs
+++ b/src/bin/proxmox-backup-manager.rs
@@ -197,6 +197,43 @@ async fn task_stop(param: Value) -> Result<Value, Error> {
Ok(Value::Null)
}
+#[api(
+ input: {
+ properties: {
+ command: {
+ description: "The command.",
+ type: String,
+ },
+ args: {
+ description: "The argument string.",
+ optional: true,
+ type: String,
+ }
+ }
+ }
+)]
+/// Send command to control socket.
+async fn send_command(param: Value) -> Result<Value, Error> {
+ let command_str = required_string_param(¶m, "command")?;
+ let args = match required_string_param(¶m, "args") {
+ Ok(args) => args,
+ Err(_) => "",
+ };
+
+ let api_pid = proxmox_backup::server::read_pid(pbs_buildcfg::PROXMOX_BACKUP_API_PID_FN)?;
+ let sock = proxmox_backup::server::ctrl_sock_from_pid(api_pid);
+ proxmox_backup::server::send_raw_command(
+ sock,
+ &format!(
+ "{{\"command\":\"{}\",\"args\":\"{}\"}}\n",
+ command_str, args
+ ),
+ )
+ .await?;
+
+ Ok(Value::Null)
+}
+
fn task_mgmt_cli() -> CommandLineInterface {
let task_log_cmd_def = CliCommand::new(&API_METHOD_TASK_LOG)
@@ -392,6 +429,10 @@ fn main() {
.insert("report",
CliCommand::new(&API_METHOD_REPORT)
)
+ .insert(
+ "send-command",
+ CliCommand::new(&API_METHOD_SEND_COMMAND).arg_param(&["command"]),
+ )
.insert("versions",
CliCommand::new(&API_METHOD_GET_VERSIONS)
);
--
2.30.2
More information about the pbs-devel
mailing list