From ce108ef7f406f90424e93bedff7428ee18e437f4 Mon Sep 17 00:00:00 2001 From: aiooss-anssi Date: Mon, 8 Jan 2024 17:21:44 +0100 Subject: [PATCH] database.py: add init error context --- README.md | 11 +++++++++++ webapp/database.py | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index aa6e716..a3cf0f7 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,17 @@ using: kill -USR2 $(pidof suricata) ``` +### How can I start the webapp in read-only mode? + +A SQLite database is generated in `webapp/database/database.db` on the first run +of the uvicorn webapp. +If you want to host a read-only Shovel instance (e.g. after the end of a CTF +event for further analysis), you may run the webapp in immutable mode using the +following environment variable: +``` +DATABASE_URL=file:database/database.db?immutable=1 +``` + ## Licensing Copyright (C) 2023 ANSSI diff --git a/webapp/database.py b/webapp/database.py index fc6ea89..13ad5a5 100644 --- a/webapp/database.py +++ b/webapp/database.py @@ -114,7 +114,12 @@ async def connect(self): # WAL journal mode allows multiple concurrent readers await self.con.execute("PRAGMA journal_mode=wal") await self.con.execute("PRAGMA synchronous=normal") - await self.init_database_structure() + try: + await self.init_database_structure() + except aiosqlite.OperationalError as e: + raise RuntimeError( + f"unable to create database '{self.database_uri}'" + ) from e async def is_readonly(self) -> bool: assert self.con is not None, "database connection closed"