Skip to content

Commit 4e26775

Browse files
committed
Auto-detect database driver in dbinit.sh instead of hardcoding pgsql
dbinit.sh now reads DBDriver from netxmsd.conf to support MariaDB/MySQL without manual workarounds. For PostgreSQL, a new NETXMS_PG_TYPE env var allows selecting between pure PostgreSQL (default) and TimescaleDB.
1 parent 55e823c commit 4e26775

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

CLAUDE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ make clean-pin
5252
### Database Initialization
5353

5454
- Server container includes `dbinit.sh` for initial schema setup if it's empty
55+
- `dbinit.sh` auto-detects the database driver from `DBDriver` in `netxmsd.conf`
56+
- For PostgreSQL, the `NETXMS_PG_TYPE` environment variable selects between `pgsql` (default) and `tsdb` (TimescaleDB)
57+
- For MariaDB/MySQL, `nxdbmgr init` auto-detects the correct SQL template
5558
- Database management utilities available via `nxdbmgr` commands
5659

5760
## Configuration System

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,23 @@ services:
106106
- KEYSTORE_PASSWORD=your_keystore_password
107107
```
108108
109+
## Database Driver Selection
110+
111+
The database initialization script (`dbinit.sh`) automatically detects the database driver from the `DBDriver` setting in `netxmsd.conf`. Supported drivers:
112+
113+
- **PostgreSQL** (`pgsql`): default, no additional configuration needed
114+
- **TimescaleDB**: set environment variable `NETXMS_PG_TYPE=tsdb` on the `init` service
115+
- **MariaDB/MySQL** (`mariadb` or `mysql`): set `DBDriver` in `netxmsd.conf` accordingly and swap the database image in `compose.yaml`
116+
117+
Example for TimescaleDB:
118+
119+
```yaml
120+
services:
121+
init:
122+
environment:
123+
- NETXMS_PG_TYPE=tsdb
124+
```
125+
109126
## Database Operations
110127

111128
```sh

server/files/dbinit.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
nxdbmgr -q get DBLockStatus
44
exitcode=$?
55
if [ "$exitcode" -eq 5 ]; then
6-
nxdbmgr init pgsql
6+
driver=$(grep -im1 '^DBDriver' /etc/netxmsd.conf | cut -d= -f2 | tr -d '[:space:]' | sed 's/\.ddr$//' | tr '[:upper:]' '[:lower:]')
7+
if [ "$driver" = "pgsql" ]; then
8+
nxdbmgr init "${NETXMS_PG_TYPE:-pgsql}"
9+
else
10+
nxdbmgr init
11+
fi
712
else
813
exit $exitcode
914
fi

0 commit comments

Comments
 (0)