Skip to content

Commit 11ac36c

Browse files
committed
feat: coderabbit suggestion
1 parent 4f85f66 commit 11ac36c

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

api/src/unraid-api/cron/log-rotate.service.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,20 @@ export class LogRotateService {
1313
@Cron('0 * * * *')
1414
async handleCron() {
1515
try {
16-
if (existsSync(this.logRotatePath)) {
17-
this.logger.debug('Running logrotate');
18-
await execa(`/usr/sbin/logrotate`, ['/etc/logrotate.conf']);
16+
if (!existsSync(this.logRotatePath)) {
17+
throw new Error(`Logrotate binary not found at ${this.logRotatePath}`);
1918
}
19+
if (!existsSync(this.configPath)) {
20+
throw new Error(`Logrotate config not found at ${this.configPath}`);
21+
}
22+
this.logger.debug('Running logrotate');
23+
const result = await execa(this.logRotatePath, [this.configPath]);
24+
if (result.failed) {
25+
throw new Error(`Logrotate execution failed: ${result.stderr}`);
26+
}
27+
this.logger.debug('Logrotate completed successfully');
2028
} catch (error) {
21-
this.logger.error(error);
29+
this.logger.debug('Failed to run logrotate with error' + error);
2230
}
2331
}
2432
}

0 commit comments

Comments
 (0)