From 3cc3f27dae23034b4a234284797e18b55bd4e84d Mon Sep 17 00:00:00 2001 From: Eli Bosley Date: Wed, 29 Jan 2025 13:08:41 -0500 Subject: [PATCH] feat: coderabbit suggestion --- api/src/unraid-api/cron/log-rotate.service.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/api/src/unraid-api/cron/log-rotate.service.ts b/api/src/unraid-api/cron/log-rotate.service.ts index 19c7da9c9..7920b9430 100644 --- a/api/src/unraid-api/cron/log-rotate.service.ts +++ b/api/src/unraid-api/cron/log-rotate.service.ts @@ -13,12 +13,20 @@ export class LogRotateService { @Cron('0 * * * *') async handleCron() { try { - if (existsSync(this.logRotatePath)) { - this.logger.debug('Running logrotate'); - await execa(`/usr/sbin/logrotate`, ['/etc/logrotate.conf']); + if (!existsSync(this.logRotatePath)) { + throw new Error(`Logrotate binary not found at ${this.logRotatePath}`); } + if (!existsSync(this.configPath)) { + throw new Error(`Logrotate config not found at ${this.configPath}`); + } + this.logger.debug('Running logrotate'); + const result = await execa(this.logRotatePath, [this.configPath]); + if (result.failed) { + throw new Error(`Logrotate execution failed: ${result.stderr}`); + } + this.logger.debug('Logrotate completed successfully'); } catch (error) { - this.logger.error(error); + this.logger.debug('Failed to run logrotate with error' + error); } } }