mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-04-02 14:59:26 +02:00
Address code review: extract DB wait function, fix Docker socket API, improve UID/GID docs
Co-authored-by: DocwatZ <227472400+DocwatZ@users.noreply.github.com>
This commit is contained in:
parent
7b207edbb3
commit
6ff633886c
|
|
@ -111,7 +111,7 @@ function collectNetworkMetrics() {
|
||||||
return nets
|
return nets
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Collect Docker container status via Docker socket */
|
/** Collect Docker container status via Docker socket using Node.js http module */
|
||||||
async function collectDockerMetrics() {
|
async function collectDockerMetrics() {
|
||||||
const containers = []
|
const containers = []
|
||||||
|
|
||||||
|
|
@ -119,21 +119,29 @@ async function collectDockerMetrics() {
|
||||||
const socketPath = '/var/run/docker.sock'
|
const socketPath = '/var/run/docker.sock'
|
||||||
if (!existsSync(socketPath)) return containers
|
if (!existsSync(socketPath)) return containers
|
||||||
|
|
||||||
const response = await fetch('http://localhost/containers/json?all=true', {
|
// Use Node.js http module for Unix socket support (fetch API does not support socketPath)
|
||||||
socketPath,
|
const { request } = await import('node:http')
|
||||||
}).catch(() => null)
|
const data = await new Promise((resolve, reject) => {
|
||||||
|
const req = request({ socketPath, path: '/containers/json?all=true', method: 'GET' }, (res) => {
|
||||||
if (response && response.ok) {
|
let body = ''
|
||||||
const data = await response.json()
|
res.on('data', (chunk) => { body += chunk })
|
||||||
for (const container of data) {
|
res.on('end', () => {
|
||||||
containers.push({
|
try { resolve(JSON.parse(body)) } catch { resolve([]) }
|
||||||
id: container.Id?.substring(0, 12),
|
|
||||||
name: container.Names?.[0]?.replace(/^\//, ''),
|
|
||||||
image: container.Image,
|
|
||||||
state: container.State,
|
|
||||||
status: container.Status,
|
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
|
req.on('error', () => resolve([]))
|
||||||
|
req.setTimeout(5000, () => { req.destroy(); resolve([]) })
|
||||||
|
req.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
for (const container of data) {
|
||||||
|
containers.push({
|
||||||
|
id: container.Id?.substring(0, 12),
|
||||||
|
name: container.Names?.[0]?.replace(/^\//, ''),
|
||||||
|
image: container.Image,
|
||||||
|
state: container.State,
|
||||||
|
status: container.Status,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// Docker metrics may not be available
|
// Docker metrics may not be available
|
||||||
|
|
|
||||||
|
|
@ -105,17 +105,23 @@ If using the Nginx proxy (port 80):
|
||||||
|
|
||||||
### Permissions
|
### Permissions
|
||||||
|
|
||||||
TrueNAS uses ACLs for dataset permissions. Set the dataset owner:
|
TrueNAS uses ACLs for dataset permissions. Set the dataset owner to match the container user:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# For Docker Compose deployments
|
# Default container user is UID 1000. Verify with:
|
||||||
|
docker compose exec nomad-app id
|
||||||
|
|
||||||
|
# Set ownership accordingly
|
||||||
chown -R 1000:1000 /mnt/pool/apps/project-nomad/storage
|
chown -R 1000:1000 /mnt/pool/apps/project-nomad/storage
|
||||||
```
|
```
|
||||||
|
|
||||||
Or configure ACLs in the TrueNAS UI:
|
Or configure ACLs in the TrueNAS UI:
|
||||||
1. Go to **Storage** → select your dataset → **Edit Permissions**
|
1. Go to **Storage** → select your dataset → **Edit Permissions**
|
||||||
2. Set User: `1000`, Group: `1000`
|
2. Set User to the UID shown by the command above (default: `1000`)
|
||||||
3. Apply recursively
|
3. Set Group to the GID shown (default: `1000`)
|
||||||
|
4. Apply recursively
|
||||||
|
|
||||||
|
> **Note:** If your TrueNAS user mapping differs, adjust the UID/GID to match your container runtime configuration.
|
||||||
|
|
||||||
## Updating on TrueNAS
|
## Updating on TrueNAS
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,23 @@ DB_PORT="${DB_PORT:-3306}"
|
||||||
MAX_RETRIES=60
|
MAX_RETRIES=60
|
||||||
RETRY_INTERVAL=2
|
RETRY_INTERVAL=2
|
||||||
|
|
||||||
|
wait_for_tcp() {
|
||||||
|
local host="$1"
|
||||||
|
local port="$2"
|
||||||
|
node -e "
|
||||||
|
const net = require('net');
|
||||||
|
const s = new net.Socket();
|
||||||
|
s.setTimeout(2000);
|
||||||
|
s.connect($port, '$host', () => { s.destroy(); process.exit(0); });
|
||||||
|
s.on('error', () => process.exit(1));
|
||||||
|
s.on('timeout', () => { s.destroy(); process.exit(1); });
|
||||||
|
" 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
echo "Waiting for database at ${DB_HOST}:${DB_PORT}..."
|
echo "Waiting for database at ${DB_HOST}:${DB_PORT}..."
|
||||||
retries=0
|
retries=0
|
||||||
while [ $retries -lt $MAX_RETRIES ]; do
|
while [ $retries -lt $MAX_RETRIES ]; do
|
||||||
if curl -sf "http://${DB_HOST}:${DB_PORT}" >/dev/null 2>&1 || \
|
if wait_for_tcp "${DB_HOST}" "${DB_PORT}"; then
|
||||||
node -e "const net = require('net'); const s = new net.Socket(); s.setTimeout(2000); s.connect(${DB_PORT}, '${DB_HOST}', () => { s.destroy(); process.exit(0); }); s.on('error', () => process.exit(1)); s.on('timeout', () => { s.destroy(); process.exit(1); });" 2>/dev/null; then
|
|
||||||
echo "Database is ready!"
|
echo "Database is ready!"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user