aboutsummaryrefslogtreecommitdiffstats
path: root/crates/atuin-server
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@atuin.sh>2026-01-28 13:46:51 -0800
committerGitHub <noreply@github.com>2026-01-28 13:46:51 -0800
commitdcde0e26e478e695c083820447b11c3c206944b4 (patch)
treecb1633124cab29143129686ea8c4a9ab78e74cfe /crates/atuin-server
parentfeat: add option to use tmux display-popup (#3058) (diff)
downloadatuin-dcde0e26e478e695c083820447b11c3c206944b4.zip
feat: move atuin-server to its own binary (#3112)
A combined binary was an early dev decision, when I thought most users would be self hosting. It is now clear that in actual fact, most users do not self host. So let's avoid forcing every user to have a copy of the server literally linked in, and let's stop building server deps over and over. The deployment for this shouldn't change. `dist` will build a binary for this automatically, and will also add it to the installer. The latter is perhaps something we should explore changing too! <!-- Thank you for making a PR! Bug fixes are always welcome, but if you're adding a new feature or changing an existing one, we'd really appreciate if you open an issue, post on the forum, or drop in on Discord --> ## Checks - [ ] I am happy for maintainers to push small adjustments to this PR, to speed up the review cycle - [ ] I have checked that there are no existing pull requests for the same thing
Diffstat (limited to 'crates/atuin-server')
-rw-r--r--crates/atuin-server/Cargo.toml12
-rw-r--r--crates/atuin-server/src/bin/main.rs73
2 files changed, 85 insertions, 0 deletions
diff --git a/crates/atuin-server/Cargo.toml b/crates/atuin-server/Cargo.toml
index 04bf61e7..edda2532 100644
--- a/crates/atuin-server/Cargo.toml
+++ b/crates/atuin-server/Cargo.toml
@@ -10,9 +10,19 @@ license = { workspace = true }
homepage = { workspace = true }
repository = { workspace = true }
+[lib]
+name = "atuin_server"
+path = "src/lib.rs"
+
+[[bin]]
+name = "atuin-server"
+path = "src/bin/main.rs"
+
[dependencies]
atuin-common = { path = "../atuin-common", version = "18.11.0" }
atuin-server-database = { path = "../atuin-server-database", version = "18.11.0" }
+atuin-server-postgres = { path = "../atuin-server-postgres", version = "18.11.0" }
+atuin-server-sqlite = { path = "../atuin-server-sqlite", version = "18.11.0" }
tracing = { workspace = true }
time = { workspace = true }
@@ -32,3 +42,5 @@ argon2 = "0.5"
semver = { workspace = true }
metrics-exporter-prometheus = { version = "0.18", default-features = false }
metrics = "0.24"
+clap = { workspace = true }
+tracing-subscriber = { workspace = true }
diff --git a/crates/atuin-server/src/bin/main.rs b/crates/atuin-server/src/bin/main.rs
new file mode 100644
index 00000000..960bdf6e
--- /dev/null
+++ b/crates/atuin-server/src/bin/main.rs
@@ -0,0 +1,73 @@
+#![forbid(unsafe_code)]
+
+use std::net::SocketAddr;
+
+use atuin_server::{Settings, example_config, launch, launch_metrics_server};
+use atuin_server_database::DbType;
+use atuin_server_postgres::Postgres;
+use atuin_server_sqlite::Sqlite;
+
+use clap::Parser;
+use eyre::{Context, Result, eyre};
+use tracing_subscriber::{EnvFilter, fmt, prelude::*};
+
+#[derive(Parser, Debug)]
+#[clap(
+ name = "atuin-server",
+ about = "Atuin sync server",
+ version,
+ infer_subcommands = true
+)]
+enum Cmd {
+ /// Start the server
+ Start {
+ /// The host address to bind
+ #[clap(long)]
+ host: Option<String>,
+
+ /// The port to bind
+ #[clap(long, short)]
+ port: Option<u16>,
+ },
+
+ /// Print server example configuration
+ DefaultConfig,
+}
+
+#[tokio::main]
+async fn main() -> Result<()> {
+ let cmd = Cmd::parse();
+
+ tracing_subscriber::registry()
+ .with(fmt::layer())
+ .with(EnvFilter::from_default_env())
+ .init();
+
+ tracing::trace!(command = ?cmd, "server command");
+
+ match cmd {
+ Cmd::Start { host, port } => {
+ let settings = Settings::new().wrap_err("could not load server settings")?;
+ let host = host.as_ref().unwrap_or(&settings.host).clone();
+ let port = port.unwrap_or(settings.port);
+ let addr = SocketAddr::new(host.parse()?, port);
+
+ if settings.metrics.enable {
+ tokio::spawn(launch_metrics_server(
+ settings.metrics.host.clone(),
+ settings.metrics.port,
+ ));
+ }
+
+ match settings.db_settings.db_type() {
+ DbType::Postgres => launch::<Postgres>(settings, addr).await,
+ DbType::Sqlite => launch::<Sqlite>(settings, addr).await,
+ DbType::Unknown => Err(eyre!("db_uri must start with postgres:// or sqlite://")),
+ }
+ }
+ Cmd::DefaultConfig => {
+ println!("{}", example_config());
+ Ok(())
+ }
+ }
+}