Second attempt to make command line options more consistent (#4249)

Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
This commit is contained in:
Nutomic 2023-12-13 15:14:59 +01:00 committed by GitHub
parent 60ffa2a599
commit 6626d35b98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,7 +24,7 @@ use actix_web::{
Result, Result,
}; };
use actix_web_prom::PrometheusMetricsBuilder; use actix_web_prom::PrometheusMetricsBuilder;
use clap::{ArgAction, Parser}; use clap::Parser;
use lemmy_api_common::{ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
lemmy_db_views::structs::SiteView, lemmy_db_views::structs::SiteView,
@ -72,24 +72,23 @@ use url::Url;
long_about = "A link aggregator for the fediverse.\n\nThis is the Lemmy backend API server. This will connect to a PostgreSQL database, run any pending migrations and start accepting API requests." long_about = "A link aggregator for the fediverse.\n\nThis is the Lemmy backend API server. This will connect to a PostgreSQL database, run any pending migrations and start accepting API requests."
)] )]
pub struct CmdArgs { pub struct CmdArgs {
/// Disables running scheduled tasks. /// Don't run scheduled tasks.
/// ///
/// If you are running multiple Lemmy server processes, /// If you are running multiple Lemmy server processes, you probably want to disable scheduled tasks on
/// you probably want to disable scheduled tasks on all but one of the processes, /// all but one of the processes, to avoid running the tasks more often than intended.
/// to avoid running the tasks more often than intended. #[arg(long, default_value_t = false)]
#[arg(long, default_value_t = false, action=ArgAction::Set)]
disable_scheduled_tasks: bool, disable_scheduled_tasks: bool,
/// Whether or not to run the HTTP server. /// Disables the HTTP server.
/// ///
/// This can be used to run a Lemmy server process that only runs scheduled tasks. /// This can be used to run a Lemmy server process that only performs scheduled tasks or activity sending.
#[arg(long, default_value_t = true, action=ArgAction::Set)] #[arg(long, default_value_t = false)]
http_server: bool, disable_http_server: bool,
/// Whether or not to emit outgoing ActivityPub messages. /// Disable sending outgoing ActivityPub messages.
/// ///
/// Set to true for a simple setup. Only set to false for horizontally scaled setups. /// Only pass this for horizontally scaled setups.
/// See https://join-lemmy.org/docs/administration/horizontal_scaling.html for detail. /// See https://join-lemmy.org/docs/administration/horizontal_scaling.html for details.
#[arg(long, default_value_t = true, action=ArgAction::Set)] #[arg(long, default_value_t = false)]
federate_activities: bool, disable_activity_sending: bool,
/// The index of this outgoing federation process. /// The index of this outgoing federation process.
/// ///
/// Defaults to 1/1. If you want to split the federation workload onto n servers, run each server 1≤i≤n with these args: /// Defaults to 1/1. If you want to split the federation workload onto n servers, run each server 1≤i≤n with these args:
@ -114,7 +113,7 @@ pub async fn start_lemmy_server(args: CmdArgs) -> Result<(), LemmyError> {
// return error 503 while running db migrations and startup tasks // return error 503 while running db migrations and startup tasks
let mut startup_server_handle = None; let mut startup_server_handle = None;
if args.http_server { if !args.disable_http_server {
startup_server_handle = Some(create_startup_server()?); startup_server_handle = Some(create_startup_server()?);
} }
@ -194,7 +193,7 @@ pub async fn start_lemmy_server(args: CmdArgs) -> Result<(), LemmyError> {
let request_data = federation_config.to_request_data(); let request_data = federation_config.to_request_data();
let outgoing_activities_task = tokio::task::spawn(handle_outgoing_activities(request_data)); let outgoing_activities_task = tokio::task::spawn(handle_outgoing_activities(request_data));
let server = if args.http_server { let server = if !args.disable_http_server {
if let Some(startup_server_handle) = startup_server_handle { if let Some(startup_server_handle) = startup_server_handle {
startup_server_handle.stop(true).await; startup_server_handle.stop(true).await;
} }
@ -212,7 +211,7 @@ pub async fn start_lemmy_server(args: CmdArgs) -> Result<(), LemmyError> {
} else { } else {
None None
}; };
let federate = args.federate_activities.then(|| { let federate = (!args.disable_activity_sending).then(|| {
start_stop_federation_workers_cancellable( start_stop_federation_workers_cancellable(
Opts { Opts {
process_index: args.federate_process_index, process_index: args.federate_process_index,