( cronExpression = "0 0 * * *", )
| 11 | const LOG_CLEANUP_JOB_NAME = "access-log-cleanup"; |
| 12 | |
| 13 | export const startLogCleanup = async ( |
| 14 | cronExpression = "0 0 * * *", |
| 15 | ): Promise<boolean> => { |
| 16 | try { |
| 17 | const existingJob = scheduledJobs[LOG_CLEANUP_JOB_NAME]; |
| 18 | if (existingJob) { |
| 19 | existingJob.cancel(); |
| 20 | } |
| 21 | |
| 22 | scheduleJob(LOG_CLEANUP_JOB_NAME, cronExpression, async () => { |
| 23 | try { |
| 24 | const { DYNAMIC_TRAEFIK_PATH } = paths(); |
| 25 | const accessLogPath = path.join(DYNAMIC_TRAEFIK_PATH, "access.log"); |
| 26 | |
| 27 | if (!fs.existsSync(accessLogPath)) { |
| 28 | console.error("Access log file does not exist"); |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | await execAsync( |
| 33 | `tail -n 1000 ${accessLogPath} > ${accessLogPath}.tmp && mv ${accessLogPath}.tmp ${accessLogPath}`, |
| 34 | ); |
| 35 | await execAsync("docker exec dokploy-traefik kill -USR1 1"); |
| 36 | } catch (error) { |
| 37 | console.error("Error during log cleanup:", error); |
| 38 | } |
| 39 | }); |
| 40 | |
| 41 | await updateWebServerSettings({ |
| 42 | logCleanupCron: cronExpression, |
| 43 | }); |
| 44 | |
| 45 | return true; |
| 46 | } catch (error) { |
| 47 | console.error("Error starting log cleanup:", error); |
| 48 | return false; |
| 49 | } |
| 50 | }; |
| 51 | |
| 52 | export const stopLogCleanup = async (): Promise<boolean> => { |
| 53 | try { |
no test coverage detected