Allow passing command line params via environment (fixes #4603) (#4729)

* Allow passing command line params via environment (fixes #4603)

* add prefix

---------

Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com>
This commit is contained in:
Nutomic 2024-05-22 14:39:01 +02:00 committed by GitHub
parent 973f39601c
commit 943c31cc72
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 6 deletions

View file

@ -165,7 +165,7 @@ urlencoding = "2.1.3"
enum-map = "2.7" enum-map = "2.7"
moka = { version = "0.12.7", features = ["future"] } moka = { version = "0.12.7", features = ["future"] }
i-love-jesus = { version = "0.1.0" } i-love-jesus = { version = "0.1.0" }
clap = { version = "4.5.4", features = ["derive"] } clap = { version = "4.5.4", features = ["derive", "env"] }
pretty_assertions = "1.4.0" pretty_assertions = "1.4.0"
[dependencies] [dependencies]

View file

@ -70,23 +70,25 @@ use url::Url;
about = "A link aggregator for the fediverse", about = "A link aggregator for the fediverse",
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."
)] )]
// TODO: Instead of defining individual env vars, only specify prefix once supported by clap.
// https://github.com/clap-rs/clap/issues/3221
pub struct CmdArgs { pub struct CmdArgs {
/// Don't run scheduled tasks. /// Don't run scheduled tasks.
/// ///
/// If you are running multiple Lemmy server processes, you probably want to disable scheduled tasks on /// If you are running multiple Lemmy server processes, you probably want to disable scheduled tasks on
/// all but one of the processes, to avoid running the tasks more often than intended. /// all but one of the processes, to avoid running the tasks more often than intended.
#[arg(long, default_value_t = false)] #[arg(long, default_value_t = false, env = "LEMMY_DISABLE_SCHEDULED_TASKS")]
disable_scheduled_tasks: bool, disable_scheduled_tasks: bool,
/// Disables the HTTP server. /// Disables the HTTP server.
/// ///
/// This can be used to run a Lemmy server process that only performs scheduled tasks or activity sending. /// This can be used to run a Lemmy server process that only performs scheduled tasks or activity sending.
#[arg(long, default_value_t = false)] #[arg(long, default_value_t = false, env = "LEMMY_DISABLE_HTTP_SERVER")]
disable_http_server: bool, disable_http_server: bool,
/// Disable sending outgoing ActivityPub messages. /// Disable sending outgoing ActivityPub messages.
/// ///
/// Only pass this for horizontally scaled setups. /// Only pass this for horizontally scaled setups.
/// See https://join-lemmy.org/docs/administration/horizontal_scaling.html for details. /// See https://join-lemmy.org/docs/administration/horizontal_scaling.html for details.
#[arg(long, default_value_t = false)] #[arg(long, default_value_t = false, env = "LEMMY_DISABLE_ACTIVITY_SENDING")]
disable_activity_sending: bool, disable_activity_sending: bool,
/// The index of this outgoing federation process. /// The index of this outgoing federation process.
/// ///
@ -96,12 +98,12 @@ pub struct CmdArgs {
/// Make you have exactly one server with each `i` running, otherwise federation will randomly send duplicates or nothing. /// Make you have exactly one server with each `i` running, otherwise federation will randomly send duplicates or nothing.
/// ///
/// See https://join-lemmy.org/docs/administration/horizontal_scaling.html for more detail. /// See https://join-lemmy.org/docs/administration/horizontal_scaling.html for more detail.
#[arg(long, default_value_t = 1)] #[arg(long, default_value_t = 1, env = "LEMMY_FEDERATE_PROCESS_INDEX")]
federate_process_index: i32, federate_process_index: i32,
/// How many outgoing federation processes you are starting in total. /// How many outgoing federation processes you are starting in total.
/// ///
/// If set, make sure to set --federate-process-index differently for each. /// If set, make sure to set --federate-process-index differently for each.
#[arg(long, default_value_t = 1)] #[arg(long, default_value_t = 1, env = "LEMMY_FEDERATE_PROCESS_COUNT")]
federate_process_count: i32, federate_process_count: i32,
} }