mirror of
https://github.com/unraid/api.git
synced 2025-12-31 13:39:52 -06:00
feat: add logrotate cron again
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
import { WriteFlashFileService } from '@app/unraid-api/cron/write-flash-file.service';
|
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { ScheduleModule } from '@nestjs/schedule';
|
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({
|
@Module({
|
||||||
imports: [ScheduleModule.forRoot()],
|
imports: [ScheduleModule.forRoot()],
|
||||||
providers: [WriteFlashFileService],
|
providers: [WriteFlashFileService, LogRotateService],
|
||||||
})
|
})
|
||||||
export class CronModule {}
|
export class CronModule {}
|
||||||
|
|||||||
24
api/src/unraid-api/cron/log-rotate.service.ts
Normal file
24
api/src/unraid-api/cron/log-rotate.service.ts
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -67,7 +67,7 @@ describe('FileModificationService', () => {
|
|||||||
|
|
||||||
it('should load modifications', async () => {
|
it('should load modifications', async () => {
|
||||||
const mods = await service.loadModifications();
|
const mods = await service.loadModifications();
|
||||||
expect(mods).toHaveLength(2);
|
expect(mods).toHaveLength(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should apply modifications', async () => {
|
it('should apply modifications', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user