mirror of
https://github.com/pockethost/pockethost.git
synced 2025-03-30 15:08:30 +00:00
feat(pockethost): add compaction health check
This commit is contained in:
parent
daa75028c9
commit
1395412382
@ -32,9 +32,14 @@ module.exports = {
|
||||
script: 'pnpm prod:cli pocketbase update',
|
||||
},
|
||||
{
|
||||
name: `health`,
|
||||
name: `health-check`,
|
||||
restart_delay: 60 * 1000, // 1 minute
|
||||
script: 'pnpm prod:cli health',
|
||||
script: 'pnpm prod:cli health check',
|
||||
},
|
||||
{
|
||||
name: `health-compact`,
|
||||
restart_delay: 60 * 1000, // 1 minute
|
||||
script: 'pnpm prod:cli health compact',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
import { exec } from 'child_process'
|
||||
import { globSync } from 'glob'
|
||||
import { DATA_ROOT } from '../../../../core'
|
||||
|
||||
export const compact = async () => {
|
||||
const files = [`data`, `logs`].flatMap((db) =>
|
||||
globSync(`${DATA_ROOT()}/*/pb_data/${db}.db{-shm,-wal}`),
|
||||
)
|
||||
|
||||
files.map(async (file) => {
|
||||
console.log(`Compacting ${file}`)
|
||||
exec(`sqlite3 ${file} ".tables"`)
|
||||
})
|
||||
console.log(`Compaction complete`)
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
import { Command } from 'commander'
|
||||
import { LoggerService } from '../../../../core'
|
||||
import { checkHealth } from './checkHealth'
|
||||
|
||||
type Options = {
|
||||
debug: boolean
|
||||
@ -8,13 +7,29 @@ type Options = {
|
||||
|
||||
export const HealthCommand = () => {
|
||||
const cmd = new Command(`health`)
|
||||
.description(`Perform a health check on the PocketHost system`)
|
||||
.action(async (options: Options) => {
|
||||
const logger = LoggerService().create(`HealthCommand`)
|
||||
const { dbg, error, info, warn } = logger
|
||||
info(`Starting`)
|
||||
|
||||
await checkHealth()
|
||||
})
|
||||
.addCommand(
|
||||
new Command(`check`)
|
||||
.description(`Perform a health check on the PocketHost system`)
|
||||
.action(async (options: Options) => {
|
||||
const logger = LoggerService().create(`HealthCommand`)
|
||||
const { dbg, error, info, warn } = logger
|
||||
info(`Starting`)
|
||||
const { checkHealth } = await import(`./checkHealth`)
|
||||
await checkHealth()
|
||||
}),
|
||||
)
|
||||
.addCommand(
|
||||
new Command(`compact`)
|
||||
.description(
|
||||
`Compact SQLite databases by removing old SHM and WAL files`,
|
||||
)
|
||||
.action(async (options: Options) => {
|
||||
const logger = LoggerService().create(`HealthCommand`)
|
||||
const { dbg, error, info, warn } = logger
|
||||
info(`Starting`)
|
||||
const { compact } = await import(`./compact`)
|
||||
await compact()
|
||||
}),
|
||||
)
|
||||
return cmd
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user