Skip to content

Commit 4f85f66

Browse files
committed
feat: add logrotate cron again
1 parent f5c7ad9 commit 4f85f66

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { WriteFlashFileService } from '@app/unraid-api/cron/write-flash-file.service';
21
import { Module } from '@nestjs/common';
32
import { ScheduleModule } from '@nestjs/schedule';
43

4+
import { WriteFlashFileService } from '@app/unraid-api/cron/write-flash-file.service';
5+
import { LogRotateService } from '@app/unraid-api/cron/log-rotate.service';
6+
57
@Module({
68
imports: [ScheduleModule.forRoot()],
7-
providers: [WriteFlashFileService],
9+
providers: [WriteFlashFileService, LogRotateService],
810
})
911
export class CronModule {}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Injectable, Logger } from '@nestjs/common';
2+
import { Cron } from '@nestjs/schedule';
3+
import { existsSync } from 'fs';
4+
5+
import { execa } from 'execa';
6+
7+
@Injectable()
8+
export class LogRotateService {
9+
private readonly logger = new Logger(LogRotateService.name);
10+
11+
logRotatePath: string = '/usr/sbin/logrotate';
12+
configPath: string = '/etc/logrotate.conf';
13+
@Cron('0 * * * *')
14+
async handleCron() {
15+
try {
16+
if (existsSync(this.logRotatePath)) {
17+
this.logger.debug('Running logrotate');
18+
await execa(`/usr/sbin/logrotate`, ['/etc/logrotate.conf']);
19+
}
20+
} catch (error) {
21+
this.logger.error(error);
22+
}
23+
}
24+
}

api/src/unraid-api/unraid-file-modifier/unraid-file-modifier.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('FileModificationService', () => {
6767

6868
it('should load modifications', async () => {
6969
const mods = await service.loadModifications();
70-
expect(mods).toHaveLength(2);
70+
expect(mods).toHaveLength(3);
7171
});
7272

7373
it('should apply modifications', async () => {

0 commit comments

Comments
 (0)