mirror of
https://github.com/girlbossceo/conduwuit.git
synced 2025-03-14 18:55:37 +00:00
reloadable configuration
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
184a3b0f0c
commit
b1b6dc0479
3 changed files with 29 additions and 6 deletions
|
@ -1,6 +1,6 @@
|
|||
use std::{fmt::Write, sync::Arc};
|
||||
use std::{fmt::Write, path::PathBuf, sync::Arc};
|
||||
|
||||
use conduwuit::{info, utils::time, warn, Err, Result};
|
||||
use conduwuit::{info, utils::time, warn, Config, Err, Result};
|
||||
use ruma::events::room::message::RoomMessageEventContent;
|
||||
|
||||
use crate::admin_command;
|
||||
|
@ -23,10 +23,26 @@ pub(super) async fn show_config(&self) -> Result<RoomMessageEventContent> {
|
|||
// Construct and send the response
|
||||
Ok(RoomMessageEventContent::text_markdown(format!(
|
||||
"{}",
|
||||
self.services.server.config
|
||||
*self.services.server.config
|
||||
)))
|
||||
}
|
||||
|
||||
#[admin_command]
|
||||
pub(super) async fn reload_config(
|
||||
&self,
|
||||
path: Option<PathBuf>,
|
||||
) -> Result<RoomMessageEventContent> {
|
||||
let path = path.as_deref().into_iter();
|
||||
let config = Config::load(path).and_then(|raw| Config::new(&raw))?;
|
||||
if config.server_name != self.services.server.config.server_name {
|
||||
return Err!("You can't change the server name.");
|
||||
}
|
||||
|
||||
let _old = self.services.server.config.update(config)?;
|
||||
|
||||
Ok(RoomMessageEventContent::text_plain("Successfully reconfigured."))
|
||||
}
|
||||
|
||||
#[admin_command]
|
||||
pub(super) async fn list_features(
|
||||
&self,
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
mod commands;
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::Subcommand;
|
||||
use conduwuit::Result;
|
||||
|
||||
|
@ -14,6 +16,11 @@ pub(super) enum ServerCommand {
|
|||
/// - Show configuration values
|
||||
ShowConfig,
|
||||
|
||||
/// - Reload configuration values
|
||||
ReloadConfig {
|
||||
path: Option<PathBuf>,
|
||||
},
|
||||
|
||||
/// - List the features built into the server
|
||||
ListFeatures {
|
||||
#[arg(short, long)]
|
||||
|
|
|
@ -8,12 +8,12 @@ use std::{
|
|||
|
||||
use tokio::{runtime, sync::broadcast};
|
||||
|
||||
use crate::{config::Config, err, log::Log, metrics::Metrics, Err, Result};
|
||||
use crate::{config, config::Config, err, log::Log, metrics::Metrics, Err, Result};
|
||||
|
||||
/// Server runtime state; public portion
|
||||
pub struct Server {
|
||||
/// Server-wide configuration instance
|
||||
pub config: Config,
|
||||
pub config: config::Manager,
|
||||
|
||||
/// Timestamp server was started; used for uptime.
|
||||
pub started: SystemTime,
|
||||
|
@ -46,7 +46,7 @@ impl Server {
|
|||
#[must_use]
|
||||
pub fn new(config: Config, runtime: Option<runtime::Handle>, log: Log) -> Self {
|
||||
Self {
|
||||
config,
|
||||
config: config::Manager::new(config),
|
||||
started: SystemTime::now(),
|
||||
stopping: AtomicBool::new(false),
|
||||
reloading: AtomicBool::new(false),
|
||||
|
|
Loading…
Add table
Reference in a new issue