Single-binary self-hosted uptime monitoring and status pages on Rust axum: HTTP probes, Lighthouse audits, SEO crawler, and PDF reports.
axumdockerrustself-hostedsqlitestatus-pageuptime-monitoringvite
1use sqlx::sqlite::{SqliteConnectOptions, SqliteJournalMode, SqlitePoolOptions, SqliteSynchronous};
2use sqlx::SqlitePool;
3use std::path::Path;
4use std::str::FromStr;
5use std::time::Duration;
6
7pub async fn init(data_dir: &Path) -> anyhow::Result<SqlitePool> {
8 let db_path = data_dir.join("db.sqlite3");
9 let url = format!("sqlite://{}", db_path.display());
10
11 if !db_path.exists() {
12 std::fs::File::create(&db_path)?;
13 }
14
15 let opts = SqliteConnectOptions::from_str(&url)?
16 .create_if_missing(true)
17 .journal_mode(SqliteJournalMode::Wal)
18 .synchronous(SqliteSynchronous::Normal)
19 .busy_timeout(Duration::from_secs(5))
20 .foreign_keys(true);
21
22 let pool = SqlitePoolOptions::new()
23 .max_connections(8)
24 .connect_with(opts)
25 .await?;
26
27 sqlx::migrate!("./migrations").run(&pool).await?;
28 Ok(pool)
29}
30
31pub fn now_ms() -> i64 {
32 chrono::Utc::now().timestamp_millis()
33}