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 ruma::events::room::message::RoomMessageEventContent;
|
||||||
|
|
||||||
use crate::admin_command;
|
use crate::admin_command;
|
||||||
|
@ -23,10 +23,26 @@ pub(super) async fn show_config(&self) -> Result<RoomMessageEventContent> {
|
||||||
// Construct and send the response
|
// Construct and send the response
|
||||||
Ok(RoomMessageEventContent::text_markdown(format!(
|
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]
|
#[admin_command]
|
||||||
pub(super) async fn list_features(
|
pub(super) async fn list_features(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
mod commands;
|
mod commands;
|
||||||
|
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use clap::Subcommand;
|
use clap::Subcommand;
|
||||||
use conduwuit::Result;
|
use conduwuit::Result;
|
||||||
|
|
||||||
|
@ -14,6 +16,11 @@ pub(super) enum ServerCommand {
|
||||||
/// - Show configuration values
|
/// - Show configuration values
|
||||||
ShowConfig,
|
ShowConfig,
|
||||||
|
|
||||||
|
/// - Reload configuration values
|
||||||
|
ReloadConfig {
|
||||||
|
path: Option<PathBuf>,
|
||||||
|
},
|
||||||
|
|
||||||
/// - List the features built into the server
|
/// - List the features built into the server
|
||||||
ListFeatures {
|
ListFeatures {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
|
|
|
@ -8,12 +8,12 @@ use std::{
|
||||||
|
|
||||||
use tokio::{runtime, sync::broadcast};
|
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
|
/// Server runtime state; public portion
|
||||||
pub struct Server {
|
pub struct Server {
|
||||||
/// Server-wide configuration instance
|
/// Server-wide configuration instance
|
||||||
pub config: Config,
|
pub config: config::Manager,
|
||||||
|
|
||||||
/// Timestamp server was started; used for uptime.
|
/// Timestamp server was started; used for uptime.
|
||||||
pub started: SystemTime,
|
pub started: SystemTime,
|
||||||
|
@ -46,7 +46,7 @@ impl Server {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new(config: Config, runtime: Option<runtime::Handle>, log: Log) -> Self {
|
pub fn new(config: Config, runtime: Option<runtime::Handle>, log: Log) -> Self {
|
||||||
Self {
|
Self {
|
||||||
config,
|
config: config::Manager::new(config),
|
||||||
started: SystemTime::now(),
|
started: SystemTime::now(),
|
||||||
stopping: AtomicBool::new(false),
|
stopping: AtomicBool::new(false),
|
||||||
reloading: AtomicBool::new(false),
|
reloading: AtomicBool::new(false),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue