Skip to content

Commit 5b64cb8

Browse files
committed
database.py: add init error context
1 parent b954a33 commit 5b64cb8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ using:
9292
kill -USR2 $(pidof suricata)
9393
```
9494

95+
### How can I start the webapp in read-only mode?
96+
97+
A SQLite database is generated in `webapp/database/database.db` on the first run
98+
of the uvicorn webapp.
99+
If you want to host a read-only Shovel instance (e.g. after the end of a CTF
100+
event for further analysis), you may run the webapp in immutable mode using the
101+
following environment variable:
102+
```
103+
DATABASE_URL=file:database/database.db?immutable=1
104+
```
105+
95106
## Licensing
96107

97108
Copyright (C) 2023 ANSSI

webapp/database.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ async def connect(self):
114114
# WAL journal mode allows multiple concurrent readers
115115
await self.con.execute("PRAGMA journal_mode=wal")
116116
await self.con.execute("PRAGMA synchronous=normal")
117-
await self.init_database_structure()
117+
try:
118+
await self.init_database_structure()
119+
except aiosqlite.OperationalError as e:
120+
raise RuntimeError(f"unable to create database '{self.database_uri}'") from e
118121

119122
async def is_readonly(self) -> bool:
120123
assert self.con is not None, "database connection closed"

0 commit comments

Comments
 (0)