MCPcopy
hub / github.com/Dokploy/dokploy / startLogCleanup

Function startLogCleanup

packages/server/src/utils/access-log/handler.ts:13–50  ·  view source on GitHub ↗
(
	cronExpression = "0 0 * * *",
)

Source from the content-addressed store, hash-verified

11const LOG_CLEANUP_JOB_NAME = "access-log-cleanup";
12
13export 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
52export const stopLogCleanup = async (): Promise<boolean> => {
53 try {

Callers 2

initCronJobsFunction · 0.90
settings.tsFile · 0.90

Calls 4

pathsFunction · 0.90
execAsyncFunction · 0.90
updateWebServerSettingsFunction · 0.90
scheduleJobFunction · 0.50

Tested by

no test coverage detected