From 3472ed8dd4380ca22fe15a0ef56696ae792d8a8b Mon Sep 17 00:00:00 2001 From: Dillon Shook Date: Wed, 30 Oct 2024 22:34:29 -0400 Subject: [PATCH] Starting to save settings --- src/datastore/DataStore.ts | 5 ++++- src/models/GoAccessInfo.ts | 4 +++- src/user/system/CaptainManager.ts | 20 +++++++++++++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/datastore/DataStore.ts b/src/datastore/DataStore.ts index 5404036..ed4142e 100644 --- a/src/datastore/DataStore.ts +++ b/src/datastore/DataStore.ts @@ -249,7 +249,10 @@ class DataStore { const goAccessInfo = (self.data.get(GOACCESS_INFO) || {}) as GoAccessInfo goAccessInfo.isEnabled = goAccessInfo.isEnabled || false - goAccessInfo.data = goAccessInfo.data || {} + goAccessInfo.data.rotationFrequencyCron = + goAccessInfo.data.rotationFrequencyCron ?? '0 0 1 * *' // monthly + goAccessInfo.data.catchupFrequencyCron = + goAccessInfo.data.catchupFrequencyCron ?? '*/10 * * * *' // every 10 minutes return goAccessInfo } diff --git a/src/models/GoAccessInfo.ts b/src/models/GoAccessInfo.ts index d494377..ed24e0a 100644 --- a/src/models/GoAccessInfo.ts +++ b/src/models/GoAccessInfo.ts @@ -1,6 +1,8 @@ export class GoAccessInfo { public isEnabled: boolean public data: { - temp: boolean + rotationFrequencyCron: string + catchupFrequencyCron: string + logRetentionDays?: number } } diff --git a/src/user/system/CaptainManager.ts b/src/user/system/CaptainManager.ts index f2892f5..39f8385 100644 --- a/src/user/system/CaptainManager.ts +++ b/src/user/system/CaptainManager.ts @@ -681,8 +681,16 @@ class CaptainManager { .then(function () { return self.dataStore.setGoAccessInfo(goAccessInfo) }) + .then(function () { + return dockerApi.ensureContainerStoppedAndRemoved( + CaptainConstants.goAccessContainerName, + CaptainConstants.captainNetworkName + ) + }) .then(function () { if (enabled) { + // const crontab = self.generateGoAccessCrontab(goAccessInfo); + return dockerApi.createStickyContainer( CaptainConstants.goAccessContainerName, CaptainConstants.configs.goAccessImageName, @@ -702,11 +710,6 @@ class CaptainManager { ['apparmor:unconfined'], undefined ) - } else { - return dockerApi.ensureContainerStoppedAndRemoved( - CaptainConstants.goAccessContainerName, - CaptainConstants.captainNetworkName - ) } }) .then(function () { @@ -717,6 +720,13 @@ class CaptainManager { }) } + generateGoAccessCrontab(goAccessInfo: GoAccessInfo): string { + return [ + '* * * * * /realtimeLog.sh', + '*/5 * * * * /processLogs.sh', + ].join('\n') + } + getNodesInfo() { const dockerApi = this.dockerApi