feat: add tunnel restart command

This commit is contained in:
Aiden McClelland
2026-03-18 23:49:29 -06:00
parent d669aa9afb
commit 427c38f23b
4 changed files with 36 additions and 3 deletions

View File

@@ -71,6 +71,13 @@ pub fn tunnel_api<C: Context>() -> ParentHandler<C> {
.with_call_remote::<CliContext>(),
),
)
.subcommand(
"restart",
from_fn_async(restart)
.no_display()
.with_about("about.restart-tunnel")
.with_call_remote::<CliContext>(),
)
.subcommand(
"update",
ParentHandler::<C>::new()
@@ -91,7 +98,13 @@ pub fn tunnel_api<C: Context>() -> ParentHandler<C> {
)
}
pub async fn restart(ctx: TunnelContext) -> Result<(), Error> {
ctx.shutdown.send(Some(true)).ok();
Ok(())
}
#[derive(Deserialize, Serialize, Parser, TS)]
#[group(skip)]
#[serde(rename_all = "camelCase")]
pub struct SubnetParams {
#[ts(type = "string")]
@@ -171,6 +184,7 @@ pub fn device_api<C: Context>() -> ParentHandler<C> {
}
#[derive(Deserialize, Serialize, Parser, TS)]
#[group(skip)]
#[serde(rename_all = "camelCase")]
pub struct AddSubnetParams {
name: InternedString,
@@ -296,6 +310,7 @@ pub async fn remove_subnet(
}
#[derive(Deserialize, Serialize, Parser, TS)]
#[group(skip)]
#[serde(rename_all = "camelCase")]
pub struct AddDeviceParams {
#[ts(type = "string")]
@@ -359,6 +374,7 @@ pub async fn add_device(
}
#[derive(Deserialize, Serialize, Parser, TS)]
#[group(skip)]
#[serde(rename_all = "camelCase")]
pub struct RemoveDeviceParams {
#[ts(type = "string")]
@@ -390,6 +406,7 @@ pub async fn remove_device(
}
#[derive(Deserialize, Serialize, Parser, TS)]
#[group(skip)]
#[serde(rename_all = "camelCase")]
pub struct ListDevicesParams {
#[ts(type = "string")]
@@ -411,6 +428,7 @@ pub async fn list_devices(
}
#[derive(Deserialize, Serialize, Parser, TS)]
#[group(skip)]
#[serde(rename_all = "camelCase")]
pub struct ShowConfigParams {
#[ts(type = "string")]
@@ -477,6 +495,7 @@ pub async fn show_config(
}
#[derive(Deserialize, Serialize, Parser, TS)]
#[group(skip)]
#[serde(rename_all = "camelCase")]
pub struct AddPortForwardParams {
#[ts(type = "string")]
@@ -546,6 +565,7 @@ pub async fn add_forward(
}
#[derive(Deserialize, Serialize, Parser, TS)]
#[group(skip)]
#[serde(rename_all = "camelCase")]
pub struct RemovePortForwardParams {
#[ts(type = "string")]
@@ -568,6 +588,7 @@ pub async fn remove_forward(
}
#[derive(Deserialize, Serialize, Parser, TS)]
#[group(skip)]
#[serde(rename_all = "camelCase")]
pub struct UpdatePortForwardLabelParams {
#[ts(type = "string")]
@@ -597,10 +618,12 @@ pub async fn update_forward_label(
}
#[derive(Deserialize, Serialize, Parser, TS)]
#[group(skip)]
#[serde(rename_all = "camelCase")]
pub struct SetPortForwardEnabledParams {
#[ts(type = "string")]
source: SocketAddrV4,
#[arg(long)]
enabled: bool,
}

View File

@@ -41,6 +41,7 @@ use crate::util::io::read_file_to_string;
use crate::util::sync::{SyncMutex, Watch};
#[derive(Debug, Clone, Default, Deserialize, Serialize, Parser)]
#[group(skip)]
#[serde(rename_all = "kebab-case")]
#[command(rename_all = "kebab-case")]
pub struct TunnelConfig {
@@ -80,7 +81,7 @@ pub struct TunnelContextSeed {
pub net_iface: Watch<OrdMap<GatewayId, NetworkInterfaceInfo>>,
pub forward: PortForwardController,
pub active_forwards: SyncMutex<BTreeMap<SocketAddrV4, Arc<()>>>,
pub shutdown: Sender<()>,
pub shutdown: Sender<Option<bool>>,
}
#[derive(Clone)]
@@ -238,6 +239,7 @@ impl Deref for TunnelContext {
}
#[derive(Debug, Deserialize, Serialize, Parser)]
#[group(skip)]
pub struct TunnelAddrParams {
#[arg(help = "help.arg.tunnel-ip-address")]
pub tunnel: IpAddr,
@@ -305,6 +307,7 @@ impl CallRemote<TunnelContext> for CliContext {
}
#[derive(Debug, Deserialize, Serialize, Parser)]
#[group(skip)]
pub struct TunnelUrlParams {
#[arg(help = "help.arg.tunnel-url")]
pub tunnel: Url,

View File

@@ -22,7 +22,7 @@ pub struct TunnelUpdateResult {
}
#[instrument(skip_all)]
pub async fn check_update(_ctx: TunnelContext, _: Empty) -> Result<TunnelUpdateResult, Error> {
pub async fn check_update(_ctx: TunnelContext) -> Result<TunnelUpdateResult, Error> {
Command::new("apt-get")
.arg("update")
.invoke(ErrorKind::UpdateFailed)
@@ -52,7 +52,7 @@ pub async fn check_update(_ctx: TunnelContext, _: Empty) -> Result<TunnelUpdateR
}
#[instrument(skip_all)]
pub async fn apply_update(_ctx: TunnelContext, _: Empty) -> Result<TunnelUpdateResult, Error> {
pub async fn apply_update(_ctx: TunnelContext) -> Result<TunnelUpdateResult, Error> {
let policy_output = Command::new("apt-cache")
.arg("policy")
.arg("start-tunnel")