File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments