mirror of
https://forgejo.ellis.link/continuwuation/continuwuity/
synced 2026-05-25 12:14:02 +00:00
fix: Don't panic when running startup admin commands
This commit is contained in:
+9
-1
@@ -39,7 +39,15 @@ pub(crate) async fn run(services: Arc<Services>) -> Result<()> {
|
||||
.runtime()
|
||||
.spawn(serve::serve(services.clone(), handle.clone(), tx.subscribe()));
|
||||
|
||||
// Focal point
|
||||
// Run startup admin commands.
|
||||
// This has to be done after the admin service is initialized otherwise it
|
||||
// panics.
|
||||
services.admin.startup_execute().await?;
|
||||
|
||||
// Print first-run banner if necessary. This needs to be done after the startup
|
||||
// admin commands are run in case one of them created the first user.
|
||||
services.firstrun.print_first_run_banner();
|
||||
|
||||
debug!("Running");
|
||||
let res = tokio::select! {
|
||||
res = &mut listener => res.map_err(Error::from).unwrap_or_else(Err),
|
||||
|
||||
@@ -26,7 +26,7 @@ pub(super) async fn console_auto_stop(&self) {
|
||||
|
||||
/// Execute admin commands after startup
|
||||
#[implement(super::Service)]
|
||||
pub(crate) async fn startup_execute(&self) -> Result {
|
||||
pub async fn startup_execute(&self) -> Result {
|
||||
// List of commands to execute
|
||||
let commands = &self.services.server.config.admin_execute;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
use askama::Template;
|
||||
use async_trait::async_trait;
|
||||
use conduwuit::{Result, utils::ReadyExt};
|
||||
use conduwuit::{Result, info, utils::ReadyExt};
|
||||
use futures::StreamExt;
|
||||
use ruma::{UserId, events::room::message::RoomMessageEventContent};
|
||||
|
||||
@@ -146,6 +146,8 @@ struct WelcomeMessage<'a> {
|
||||
.send_loud_message(RoomMessageEventContent::text_markdown(welcome_message))
|
||||
.await?;
|
||||
|
||||
info!("{user} has been invited to the admin room as the first user.");
|
||||
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
@@ -162,7 +164,7 @@ pub fn get_first_account_token(&self) -> Option<ValidToken> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn print_first_run_banner(&self) {
|
||||
pub fn print_first_run_banner(&self) {
|
||||
use yansi::Paint;
|
||||
// This function is specially called by the core after all other
|
||||
// services have started. It runs last to ensure that the banner it
|
||||
|
||||
@@ -149,13 +149,6 @@ pub async fn start(self: &Arc<Self>) -> Result<Arc<Self>> {
|
||||
|
||||
debug_info!("Services startup complete.");
|
||||
|
||||
// Run startup admin commands
|
||||
self.admin.startup_execute().await?;
|
||||
|
||||
// Prin first-run banner if necessary. This needs to be done after the startup
|
||||
// admin commands are run in case one of them created the first user.
|
||||
self.firstrun.print_first_run_banner();
|
||||
|
||||
Ok(Arc::clone(self))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user