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..e412e82 100644 --- a/webapp/database.py +++ b/webapp/database.py @@ -114,7 +114,10 @@ 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"