tuwunel_admin/server/
mod.rs1mod admin_notice;
2mod backup_database;
3mod clear_caches;
4mod delete_backups;
5mod list_backups;
6mod list_features;
7mod memory_usage;
8mod regenerate_config;
9mod reload_config;
10mod reload_mods;
11#[cfg(unix)]
12mod restart;
13mod show_config;
14mod shutdown;
15mod uptime;
16mod verify_backup;
17
18use std::{path::PathBuf, sync::Arc};
19
20use clap::Subcommand;
21use tuwunel_core::{Result, implement};
22use tuwunel_database::Database;
23
24use crate::admin_command_dispatch;
25
26#[admin_command_dispatch]
27#[derive(Debug, Subcommand)]
28pub(super) enum ServerCommand {
29 Uptime,
31
32 ShowConfig,
34
35 ReloadConfig {
38 path: Option<PathBuf>,
39 },
40
41 #[command(about = "Regenerate configuration into a server-local file.")]
42 RegenerateConfig {
43 #[arg(help = "Absolute destination path on this server.")]
44 path: PathBuf,
45
46 #[arg(
47 long,
48 help = "Replace an existing destination after saving a backup."
49 )]
50 force: bool,
51
52 #[arg(
53 long,
54 help = "Materialize values currently supplied by the environment."
55 )]
56 include_env: bool,
57
58 #[arg(
59 long,
60 help = "Comment out keys that are not recognized by this binary."
61 )]
62 strip_unknown: bool,
63 },
64
65 ListFeatures {
67 #[arg(short, long)]
68 available: bool,
69
70 #[arg(short, long)]
71 enabled: bool,
72
73 #[arg(short, long)]
74 comma: bool,
75 },
76
77 MemoryUsage,
79
80 ClearCaches,
82
83 BackupDatabase,
86
87 ListBackups,
89
90 VerifyBackup {
93 backup_id: Option<u32>,
96 },
97
98 DeleteBackups {
100 keep: usize,
102 },
103
104 AdminNotice {
106 message: Vec<String>,
107 },
108
109 #[clap(alias = "reload")]
111 ReloadMods,
112
113 #[cfg(unix)]
114 Restart {
116 #[arg(short, long)]
117 force: bool,
118 },
119
120 Shutdown,
122}
123
124#[implement(crate::Context, params = "<'_>")]
129pub(crate) async fn blocking_db<F, T>(&self, f: F) -> Result<T>
130where
131 F: FnOnce(Arc<Database>) -> Result<T> + Send + 'static,
132 T: Send + 'static,
133{
134 let db = Arc::clone(&self.services.db);
135
136 self.services
137 .server
138 .runtime()
139 .spawn_blocking(move || f(db))
140 .await?
141}