feat: add logrotate cron again

This commit is contained in:
Eli Bosley
2025-01-29 11:39:50 -05:00
parent b1d9ad7ef1
commit 097415f6b8
3 changed files with 29 additions and 3 deletions

View File

@@ -1,9 +1,11 @@
import { WriteFlashFileService } from '@app/unraid-api/cron/write-flash-file.service';
import { Module } from '@nestjs/common';
import { ScheduleModule } from '@nestjs/schedule';
import { WriteFlashFileService } from '@app/unraid-api/cron/write-flash-file.service';
import { LogRotateService } from '@app/unraid-api/cron/log-rotate.service';
@Module({
imports: [ScheduleModule.forRoot()],
providers: [WriteFlashFileService],
providers: [WriteFlashFileService, LogRotateService],
})
export class CronModule {}

View File

@@ -0,0 +1,24 @@
import { Injectable, Logger } from '@nestjs/common';
import { Cron } from '@nestjs/schedule';
import { existsSync } from 'fs';
import { execa } from 'execa';
@Injectable()
export class LogRotateService {
private readonly logger = new Logger(LogRotateService.name);
logRotatePath: string = '/usr/sbin/logrotate';
configPath: string = '/etc/logrotate.conf';
@Cron('0 * * * *')
async handleCron() {
try {
if (existsSync(this.logRotatePath)) {
this.logger.debug('Running logrotate');
await execa(`/usr/sbin/logrotate`, ['/etc/logrotate.conf']);
}
} catch (error) {
this.logger.error(error);
}
}
}

View File

@@ -67,7 +67,7 @@ describe('FileModificationService', () => {
it('should load modifications', async () => {
const mods = await service.loadModifications();
expect(mods).toHaveLength(2);
expect(mods).toHaveLength(3);
});
it('should apply modifications', async () => {