2026-02-14 15:43:24 +01:00
|
|
|
import appHealthMonitor from './apphealthmonitor.js';
|
Migrate codebase from CommonJS to ES Modules
- Convert all require()/module.exports to import/export across 260+ files
- Add "type": "module" to package.json to enable ESM by default
- Add migrations/package.json with "type": "commonjs" to keep db-migrate compatible
- Convert eslint.config.js to ESM with sourceType: "module"
- Replace __dirname/__filename with import.meta.dirname/import.meta.filename
- Replace require.main === module with process.argv[1] === import.meta.filename
- Remove 'use strict' directives (implicit in ESM)
- Convert dynamic require() in switch statements to static import lookup maps
(dns.js, domains.js, backupformats.js, backupsites.js, network.js)
- Extract self-referencing exports.CONSTANT patterns into standalone const
declarations (apps.js, services.js, locks.js, users.js, mail.js, etc.)
- Lazify SERVICES object in services.js to avoid circular dependency TDZ issues
- Add clearMailQueue() to mailer.js for ESM-safe queue clearing in tests
- Add _setMockApp() to ldapserver.js for ESM-safe test mocking
- Add _setMockResolve() wrapper to dig.js for ESM-safe DNS mocking in tests
- Convert backupupload.js to use dynamic imports so --check exits before
loading the module graph (which requires BOX_ENV)
- Update check-install to use ESM import for infra_version.js
- Convert scripts/ (hotfix, release, remote_hotfix.js, find-unused-translations)
- All 1315 tests passing
Migration stats (AI-assisted using Cursor with Claude):
- Wall clock time: ~3-4 hours
- Assistant completions: ~80-100
- Estimated token usage: ~1-2M tokens
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 09:53:14 +01:00
|
|
|
import assert from 'node:assert';
|
2026-02-14 15:43:24 +01:00
|
|
|
import appstore from './appstore.js';
|
Migrate codebase from CommonJS to ES Modules
- Convert all require()/module.exports to import/export across 260+ files
- Add "type": "module" to package.json to enable ESM by default
- Add migrations/package.json with "type": "commonjs" to keep db-migrate compatible
- Convert eslint.config.js to ESM with sourceType: "module"
- Replace __dirname/__filename with import.meta.dirname/import.meta.filename
- Replace require.main === module with process.argv[1] === import.meta.filename
- Remove 'use strict' directives (implicit in ESM)
- Convert dynamic require() in switch statements to static import lookup maps
(dns.js, domains.js, backupformats.js, backupsites.js, network.js)
- Extract self-referencing exports.CONSTANT patterns into standalone const
declarations (apps.js, services.js, locks.js, users.js, mail.js, etc.)
- Lazify SERVICES object in services.js to avoid circular dependency TDZ issues
- Add clearMailQueue() to mailer.js for ESM-safe queue clearing in tests
- Add _setMockApp() to ldapserver.js for ESM-safe test mocking
- Add _setMockResolve() wrapper to dig.js for ESM-safe DNS mocking in tests
- Convert backupupload.js to use dynamic imports so --check exits before
loading the module graph (which requires BOX_ENV)
- Update check-install to use ESM import for infra_version.js
- Convert scripts/ (hotfix, release, remote_hotfix.js, find-unused-translations)
- All 1315 tests passing
Migration stats (AI-assisted using Cursor with Claude):
- Wall clock time: ~3-4 hours
- Assistant completions: ~80-100
- Estimated token usage: ~1-2M tokens
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 09:53:14 +01:00
|
|
|
import AuditSource from './auditsource.js';
|
2026-02-14 15:43:24 +01:00
|
|
|
import backupSites from './backupsites.js';
|
|
|
|
|
import cloudron from './cloudron.js';
|
Migrate codebase from CommonJS to ES Modules
- Convert all require()/module.exports to import/export across 260+ files
- Add "type": "module" to package.json to enable ESM by default
- Add migrations/package.json with "type": "commonjs" to keep db-migrate compatible
- Convert eslint.config.js to ESM with sourceType: "module"
- Replace __dirname/__filename with import.meta.dirname/import.meta.filename
- Replace require.main === module with process.argv[1] === import.meta.filename
- Remove 'use strict' directives (implicit in ESM)
- Convert dynamic require() in switch statements to static import lookup maps
(dns.js, domains.js, backupformats.js, backupsites.js, network.js)
- Extract self-referencing exports.CONSTANT patterns into standalone const
declarations (apps.js, services.js, locks.js, users.js, mail.js, etc.)
- Lazify SERVICES object in services.js to avoid circular dependency TDZ issues
- Add clearMailQueue() to mailer.js for ESM-safe queue clearing in tests
- Add _setMockApp() to ldapserver.js for ESM-safe test mocking
- Add _setMockResolve() wrapper to dig.js for ESM-safe DNS mocking in tests
- Convert backupupload.js to use dynamic imports so --check exits before
loading the module graph (which requires BOX_ENV)
- Update check-install to use ESM import for infra_version.js
- Convert scripts/ (hotfix, release, remote_hotfix.js, find-unused-translations)
- All 1315 tests passing
Migration stats (AI-assisted using Cursor with Claude):
- Wall clock time: ~3-4 hours
- Assistant completions: ~80-100
- Estimated token usage: ~1-2M tokens
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 09:53:14 +01:00
|
|
|
import constants from './constants.js';
|
|
|
|
|
import { CronJob } from 'cron';
|
2026-03-12 22:55:28 +05:30
|
|
|
import logger from './logger.js';
|
2026-02-14 15:43:24 +01:00
|
|
|
import domains from './domains.js';
|
|
|
|
|
import dyndns from './dyndns.js';
|
|
|
|
|
import externalLdap from './externalldap.js';
|
Migrate codebase from CommonJS to ES Modules
- Convert all require()/module.exports to import/export across 260+ files
- Add "type": "module" to package.json to enable ESM by default
- Add migrations/package.json with "type": "commonjs" to keep db-migrate compatible
- Convert eslint.config.js to ESM with sourceType: "module"
- Replace __dirname/__filename with import.meta.dirname/import.meta.filename
- Replace require.main === module with process.argv[1] === import.meta.filename
- Remove 'use strict' directives (implicit in ESM)
- Convert dynamic require() in switch statements to static import lookup maps
(dns.js, domains.js, backupformats.js, backupsites.js, network.js)
- Extract self-referencing exports.CONSTANT patterns into standalone const
declarations (apps.js, services.js, locks.js, users.js, mail.js, etc.)
- Lazify SERVICES object in services.js to avoid circular dependency TDZ issues
- Add clearMailQueue() to mailer.js for ESM-safe queue clearing in tests
- Add _setMockApp() to ldapserver.js for ESM-safe test mocking
- Add _setMockResolve() wrapper to dig.js for ESM-safe DNS mocking in tests
- Convert backupupload.js to use dynamic imports so --check exits before
loading the module graph (which requires BOX_ENV)
- Update check-install to use ESM import for infra_version.js
- Convert scripts/ (hotfix, release, remote_hotfix.js, find-unused-translations)
- All 1315 tests passing
Migration stats (AI-assisted using Cursor with Claude):
- Wall clock time: ~3-4 hours
- Assistant completions: ~80-100
- Estimated token usage: ~1-2M tokens
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 09:53:14 +01:00
|
|
|
import eventlog from './eventlog.js';
|
2026-02-14 15:43:24 +01:00
|
|
|
import janitor from './janitor.js';
|
|
|
|
|
import mail from './mail.js';
|
|
|
|
|
import metrics from './metrics.js';
|
|
|
|
|
import network from './network.js';
|
|
|
|
|
import oidcServer from './oidcserver.js';
|
Migrate codebase from CommonJS to ES Modules
- Convert all require()/module.exports to import/export across 260+ files
- Add "type": "module" to package.json to enable ESM by default
- Add migrations/package.json with "type": "commonjs" to keep db-migrate compatible
- Convert eslint.config.js to ESM with sourceType: "module"
- Replace __dirname/__filename with import.meta.dirname/import.meta.filename
- Replace require.main === module with process.argv[1] === import.meta.filename
- Remove 'use strict' directives (implicit in ESM)
- Convert dynamic require() in switch statements to static import lookup maps
(dns.js, domains.js, backupformats.js, backupsites.js, network.js)
- Extract self-referencing exports.CONSTANT patterns into standalone const
declarations (apps.js, services.js, locks.js, users.js, mail.js, etc.)
- Lazify SERVICES object in services.js to avoid circular dependency TDZ issues
- Add clearMailQueue() to mailer.js for ESM-safe queue clearing in tests
- Add _setMockApp() to ldapserver.js for ESM-safe test mocking
- Add _setMockResolve() wrapper to dig.js for ESM-safe DNS mocking in tests
- Convert backupupload.js to use dynamic imports so --check exits before
loading the module graph (which requires BOX_ENV)
- Update check-install to use ESM import for infra_version.js
- Convert scripts/ (hotfix, release, remote_hotfix.js, find-unused-translations)
- All 1315 tests passing
Migration stats (AI-assisted using Cursor with Claude):
- Wall clock time: ~3-4 hours
- Assistant completions: ~80-100
- Estimated token usage: ~1-2M tokens
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 09:53:14 +01:00
|
|
|
import paths from './paths.js';
|
2026-02-14 15:43:24 +01:00
|
|
|
import reverseProxy from './reverseproxy.js';
|
Migrate codebase from CommonJS to ES Modules
- Convert all require()/module.exports to import/export across 260+ files
- Add "type": "module" to package.json to enable ESM by default
- Add migrations/package.json with "type": "commonjs" to keep db-migrate compatible
- Convert eslint.config.js to ESM with sourceType: "module"
- Replace __dirname/__filename with import.meta.dirname/import.meta.filename
- Replace require.main === module with process.argv[1] === import.meta.filename
- Remove 'use strict' directives (implicit in ESM)
- Convert dynamic require() in switch statements to static import lookup maps
(dns.js, domains.js, backupformats.js, backupsites.js, network.js)
- Extract self-referencing exports.CONSTANT patterns into standalone const
declarations (apps.js, services.js, locks.js, users.js, mail.js, etc.)
- Lazify SERVICES object in services.js to avoid circular dependency TDZ issues
- Add clearMailQueue() to mailer.js for ESM-safe queue clearing in tests
- Add _setMockApp() to ldapserver.js for ESM-safe test mocking
- Add _setMockResolve() wrapper to dig.js for ESM-safe DNS mocking in tests
- Convert backupupload.js to use dynamic imports so --check exits before
loading the module graph (which requires BOX_ENV)
- Update check-install to use ESM import for infra_version.js
- Convert scripts/ (hotfix, release, remote_hotfix.js, find-unused-translations)
- All 1315 tests passing
Migration stats (AI-assisted using Cursor with Claude):
- Wall clock time: ~3-4 hours
- Assistant completions: ~80-100
- Estimated token usage: ~1-2M tokens
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 09:53:14 +01:00
|
|
|
import safe from 'safetydance';
|
2026-02-14 15:43:24 +01:00
|
|
|
import scheduler from './scheduler.js';
|
|
|
|
|
import system from './system.js';
|
|
|
|
|
import updater from './updater.js';
|
Migrate codebase from CommonJS to ES Modules
- Convert all require()/module.exports to import/export across 260+ files
- Add "type": "module" to package.json to enable ESM by default
- Add migrations/package.json with "type": "commonjs" to keep db-migrate compatible
- Convert eslint.config.js to ESM with sourceType: "module"
- Replace __dirname/__filename with import.meta.dirname/import.meta.filename
- Replace require.main === module with process.argv[1] === import.meta.filename
- Remove 'use strict' directives (implicit in ESM)
- Convert dynamic require() in switch statements to static import lookup maps
(dns.js, domains.js, backupformats.js, backupsites.js, network.js)
- Extract self-referencing exports.CONSTANT patterns into standalone const
declarations (apps.js, services.js, locks.js, users.js, mail.js, etc.)
- Lazify SERVICES object in services.js to avoid circular dependency TDZ issues
- Add clearMailQueue() to mailer.js for ESM-safe queue clearing in tests
- Add _setMockApp() to ldapserver.js for ESM-safe test mocking
- Add _setMockResolve() wrapper to dig.js for ESM-safe DNS mocking in tests
- Convert backupupload.js to use dynamic imports so --check exits before
loading the module graph (which requires BOX_ENV)
- Update check-install to use ESM import for infra_version.js
- Convert scripts/ (hotfix, release, remote_hotfix.js, find-unused-translations)
- All 1315 tests passing
Migration stats (AI-assisted using Cursor with Claude):
- Wall clock time: ~3-4 hours
- Assistant completions: ~80-100
- Estimated token usage: ~1-2M tokens
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 09:53:14 +01:00
|
|
|
import util from 'node:util';
|
|
|
|
|
|
2026-03-12 22:55:28 +05:30
|
|
|
const { log, trace } = logger('cron');
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2020-05-28 10:56:51 -07:00
|
|
|
// IMPORTANT: These patterns are together because they spin tasks which acquire a lock
|
|
|
|
|
// If the patterns overlap all the time, then the task may not ever get a chance to run!
|
2020-05-30 09:44:33 -07:00
|
|
|
// If you change this change dashboard patterns in settings.html
|
2020-05-28 10:56:51 -07:00
|
|
|
const DEFAULT_CLEANUP_BACKUPS_PATTERN = '00 30 1,3,5,23 * * *',
|
2020-08-19 21:39:58 -07:00
|
|
|
DEFAULT_AUTOUPDATE_PATTERN = '00 00 1,3,5,23 * * *';
|
2020-05-28 10:56:51 -07:00
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2021-01-31 20:47:33 -08:00
|
|
|
const gJobs = {
|
2020-08-19 21:39:58 -07:00
|
|
|
autoUpdater: null,
|
2025-07-25 08:36:09 +02:00
|
|
|
backups: new Map(),
|
2020-08-19 21:39:58 -07:00
|
|
|
updateChecker: null,
|
2019-02-06 15:47:56 +01:00
|
|
|
systemChecks: null,
|
2023-08-04 13:41:13 +05:30
|
|
|
mailStatusCheck: null,
|
2019-08-19 13:50:44 -07:00
|
|
|
diskSpaceChecker: null,
|
2017-11-27 12:40:13 -08:00
|
|
|
certificateRenew: null,
|
|
|
|
|
cleanupBackups: null,
|
|
|
|
|
cleanupEventlog: null,
|
|
|
|
|
cleanupTokens: null,
|
2025-03-05 11:29:13 +01:00
|
|
|
cleanupOidc: null,
|
2017-11-27 12:40:13 -08:00
|
|
|
dockerVolumeCleaner: null,
|
2018-11-10 00:18:56 -08:00
|
|
|
dynamicDns: null,
|
2018-10-22 11:39:42 -07:00
|
|
|
schedulerSync: null,
|
2022-11-09 15:21:38 +01:00
|
|
|
appHealthMonitor: null,
|
2025-02-17 19:01:53 +01:00
|
|
|
externalLdapSyncer: null,
|
2025-05-18 16:26:33 +02:00
|
|
|
checkDomainConfigs: null,
|
2025-07-16 22:07:54 +02:00
|
|
|
collectStats: null,
|
|
|
|
|
subscriptionChecker: null,
|
2017-11-27 12:40:13 -08:00
|
|
|
};
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
// cron format
|
|
|
|
|
// Seconds: 0-59
|
|
|
|
|
// Minutes: 0-59
|
|
|
|
|
// Hours: 0-23
|
|
|
|
|
// Day of Month: 1-31
|
|
|
|
|
// Months: 0-11
|
|
|
|
|
// Day of Week: 0-6
|
|
|
|
|
|
2022-07-25 15:27:25 +02:00
|
|
|
function getCronSeed() {
|
2022-07-29 08:55:01 +02:00
|
|
|
let hour = null;
|
|
|
|
|
let minute = null;
|
|
|
|
|
|
2022-08-10 22:07:05 +02:00
|
|
|
const seedData = safe.fs.readFileSync(paths.CRON_SEED_FILE, 'utf8') || '';
|
|
|
|
|
const parts = seedData.split(':');
|
|
|
|
|
if (parts.length === 2) {
|
|
|
|
|
hour = parseInt(parts[0]) || null;
|
|
|
|
|
minute = parseInt(parts[1]) || null;
|
2022-07-29 08:55:01 +02:00
|
|
|
}
|
|
|
|
|
|
2022-08-10 22:07:05 +02:00
|
|
|
if ((hour == null || hour < 0 || hour > 23) || (minute == null || minute < 0 || minute > 60)) {
|
2022-08-08 20:33:21 +02:00
|
|
|
hour = Math.floor(24 * Math.random());
|
|
|
|
|
minute = Math.floor(60 * Math.random());
|
2022-07-29 08:55:01 +02:00
|
|
|
|
2026-03-12 22:55:28 +05:30
|
|
|
log(`getCronSeed: writing new cron seed file with ${hour}:${minute} to ${paths.CRON_SEED_FILE}`);
|
2022-07-29 08:55:01 +02:00
|
|
|
|
|
|
|
|
safe.fs.writeFileSync(paths.CRON_SEED_FILE, `${hour}:${minute}`);
|
2022-07-25 15:27:25 +02:00
|
|
|
}
|
|
|
|
|
|
2022-07-29 08:55:01 +02:00
|
|
|
return { hour, minute };
|
2022-07-25 15:27:25 +02:00
|
|
|
}
|
|
|
|
|
|
2026-02-14 16:34:34 +01:00
|
|
|
async function handleBackupScheduleChanged(site) {
|
|
|
|
|
assert.strictEqual(typeof site, 'object');
|
|
|
|
|
|
|
|
|
|
const tz = await cloudron.getTimeZone();
|
|
|
|
|
|
2026-03-12 22:55:28 +05:30
|
|
|
log(`handleBackupScheduleChanged: schedule ${site.schedule} (${tz})`);
|
2026-02-14 16:34:34 +01:00
|
|
|
|
|
|
|
|
if (gJobs.backups.has(site.id)) gJobs.backups.get(site.id).stop();
|
|
|
|
|
gJobs.backups.delete(site.id);
|
|
|
|
|
|
|
|
|
|
if (site.schedule === constants.CRON_PATTERN_NEVER) return;
|
|
|
|
|
|
|
|
|
|
const job = CronJob.from({
|
|
|
|
|
cronTime: site.schedule,
|
|
|
|
|
onTick: async () => {
|
|
|
|
|
const t = await backupSites.get(site.id);
|
|
|
|
|
if (!t) return;
|
2026-03-12 22:55:28 +05:30
|
|
|
await safe(backupSites.startBackupTask(t, AuditSource.CRON), { debug: log });
|
2026-02-14 16:34:34 +01:00
|
|
|
},
|
|
|
|
|
start: true,
|
|
|
|
|
timeZone: tz
|
|
|
|
|
});
|
|
|
|
|
gJobs.backups.set(site.id, job);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function handleAutoupdatePatternChanged(pattern) {
|
|
|
|
|
assert.strictEqual(typeof pattern, 'string');
|
|
|
|
|
|
|
|
|
|
const tz = await cloudron.getTimeZone();
|
|
|
|
|
|
2026-03-12 22:55:28 +05:30
|
|
|
log(`autoupdatePatternChanged: pattern - ${pattern} (${tz})`);
|
2026-02-14 16:34:34 +01:00
|
|
|
|
|
|
|
|
if (gJobs.autoUpdater) gJobs.autoUpdater.stop();
|
|
|
|
|
gJobs.autoUpdater = null;
|
|
|
|
|
|
|
|
|
|
if (pattern === constants.CRON_PATTERN_NEVER) return;
|
|
|
|
|
|
|
|
|
|
gJobs.autoUpdater = CronJob.from({
|
|
|
|
|
cronTime: pattern,
|
2026-03-12 22:55:28 +05:30
|
|
|
onTick: async () => await safe(updater.autoUpdate(AuditSource.CRON), { debug: log }),
|
2026-02-14 16:34:34 +01:00
|
|
|
start: true,
|
|
|
|
|
timeZone: tz
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleDynamicDnsChanged(enabled) {
|
|
|
|
|
assert.strictEqual(typeof enabled, 'boolean');
|
|
|
|
|
|
2026-03-12 22:55:28 +05:30
|
|
|
log('Dynamic DNS setting changed to %s', enabled);
|
2026-02-14 16:34:34 +01:00
|
|
|
|
|
|
|
|
if (gJobs.dynamicDns) gJobs.dynamicDns.stop();
|
|
|
|
|
gJobs.dynamicDns = null;
|
|
|
|
|
|
|
|
|
|
if (!enabled) return;
|
|
|
|
|
|
|
|
|
|
gJobs.dynamicDns = CronJob.from({
|
|
|
|
|
// until we can be smarter about actual IP changes, lets ensure it every 10minutes
|
|
|
|
|
cronTime: '00 */10 * * * *',
|
2026-03-12 22:55:28 +05:30
|
|
|
onTick: async () => { await safe(dyndns.refreshDns(AuditSource.CRON), { debug: log }); },
|
2026-02-14 16:34:34 +01:00
|
|
|
start: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function handleExternalLdapChanged(config) {
|
|
|
|
|
assert.strictEqual(typeof config, 'object');
|
|
|
|
|
|
|
|
|
|
if (gJobs.externalLdapSyncer) gJobs.externalLdapSyncer.stop();
|
|
|
|
|
gJobs.externalLdapSyncer = null;
|
|
|
|
|
|
|
|
|
|
if (config.provider === 'noop') return;
|
|
|
|
|
|
|
|
|
|
gJobs.externalLdapSyncer = CronJob.from({
|
|
|
|
|
cronTime: '00 00 */4 * * *', // every 4 hours
|
2026-03-12 22:55:28 +05:30
|
|
|
onTick: async () => await safe(externalLdap.startSyncer(AuditSource.CRON), { debug: log }),
|
2026-02-14 16:34:34 +01:00
|
|
|
start: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-18 13:25:42 -07:00
|
|
|
async function startJobs() {
|
2022-07-29 08:55:01 +02:00
|
|
|
const { hour, minute } = getCronSeed();
|
2022-07-25 15:27:25 +02:00
|
|
|
|
2026-03-12 22:55:28 +05:30
|
|
|
log(`startJobs: starting cron jobs with hour ${hour} and minute ${minute}`);
|
2020-10-07 14:47:51 -07:00
|
|
|
|
2024-04-19 18:19:41 +02:00
|
|
|
gJobs.systemChecks = CronJob.from({
|
2022-07-29 08:55:01 +02:00
|
|
|
cronTime: `00 ${minute} 2 * * *`, // once a day. if you change this interval, change the notification messages with correct duration
|
2026-03-12 22:55:28 +05:30
|
|
|
onTick: async () => await safe(system.runSystemChecks(), { debug: log }),
|
2023-08-04 13:41:13 +05:30
|
|
|
start: true
|
|
|
|
|
});
|
|
|
|
|
|
2024-04-19 18:19:41 +02:00
|
|
|
gJobs.mailStatusCheck = CronJob.from({
|
2023-08-04 13:41:13 +05:30
|
|
|
cronTime: `00 ${minute} 2 * * *`, // once a day. if you change this interval, change the notification messages with correct duration
|
2026-03-12 22:55:28 +05:30
|
|
|
onTick: async () => await safe(mail.checkStatus(), { debug: log }),
|
2020-02-10 12:17:21 -08:00
|
|
|
start: true
|
2016-12-28 14:21:41 -08:00
|
|
|
});
|
|
|
|
|
|
2024-04-19 18:19:41 +02:00
|
|
|
gJobs.diskSpaceChecker = CronJob.from({
|
2019-08-19 13:50:44 -07:00
|
|
|
cronTime: '00 30 * * * *', // every 30 minutes. if you change this interval, change the notification messages with correct duration
|
2026-03-12 22:55:28 +05:30
|
|
|
onTick: async () => await safe(system.checkDiskSpace(), { debug: log }),
|
2020-02-10 12:17:21 -08:00
|
|
|
start: true
|
2019-08-19 13:50:44 -07:00
|
|
|
});
|
|
|
|
|
|
2020-07-29 20:27:06 -07:00
|
|
|
// this is run separately from the update itself so that the user can disable automatic updates but can still get a notification
|
2024-04-19 18:19:41 +02:00
|
|
|
gJobs.updateCheckerJob = CronJob.from({
|
2022-07-29 08:55:01 +02:00
|
|
|
cronTime: `00 ${minute} 1,5,9,13,17,21,23 * * *`,
|
2026-03-12 22:55:28 +05:30
|
|
|
onTick: async () => await safe(updater.checkForUpdates({ stableOnly: true }), { debug: log }),
|
2020-02-10 12:17:21 -08:00
|
|
|
start: true
|
2016-12-28 14:21:41 -08:00
|
|
|
});
|
|
|
|
|
|
2024-04-19 18:19:41 +02:00
|
|
|
gJobs.cleanupTokens = CronJob.from({
|
2016-12-28 14:21:41 -08:00
|
|
|
cronTime: '00 */30 * * * *', // every 30 minutes
|
2026-03-12 22:55:28 +05:30
|
|
|
onTick: async () => await safe(janitor.cleanupTokens(), { debug: log }),
|
2020-02-10 12:17:21 -08:00
|
|
|
start: true
|
2016-12-28 14:21:41 -08:00
|
|
|
});
|
|
|
|
|
|
2025-03-05 11:29:13 +01:00
|
|
|
gJobs.cleanupOidc = CronJob.from({
|
|
|
|
|
cronTime: '00 10 * * * *', // every hour ten minutes past
|
2026-03-12 22:55:28 +05:30
|
|
|
onTick: async () => await safe(oidcServer.cleanupExpired(), { debug: log }),
|
2025-03-05 11:29:13 +01:00
|
|
|
start: true
|
|
|
|
|
});
|
|
|
|
|
|
2024-04-19 18:19:41 +02:00
|
|
|
gJobs.cleanupBackups = CronJob.from({
|
2020-05-28 10:56:51 -07:00
|
|
|
cronTime: DEFAULT_CLEANUP_BACKUPS_PATTERN,
|
2025-07-25 14:54:51 +02:00
|
|
|
onTick: async () => {
|
2025-09-29 14:44:42 +02:00
|
|
|
for (const backupSite of await backupSites.list()) {
|
2026-03-12 22:55:28 +05:30
|
|
|
await safe(backupSites.startCleanupTask(backupSite, AuditSource.CRON), { debug: log });
|
2025-07-25 14:54:51 +02:00
|
|
|
}
|
|
|
|
|
},
|
2020-02-10 12:17:21 -08:00
|
|
|
start: true
|
2016-12-28 14:21:41 -08:00
|
|
|
});
|
|
|
|
|
|
2024-04-19 18:19:41 +02:00
|
|
|
gJobs.cleanupEventlog = CronJob.from({
|
2016-12-28 14:21:41 -08:00
|
|
|
cronTime: '00 */30 * * * *', // every 30 minutes
|
2026-03-12 22:55:28 +05:30
|
|
|
onTick: async () => await safe(eventlog.cleanup({ creationTime: new Date(Date.now() - 90 * 60 * 24 * 60 * 1000) }), { debug: log }), // 90 days ago
|
2020-02-10 12:17:21 -08:00
|
|
|
start: true
|
2016-12-28 14:21:41 -08:00
|
|
|
});
|
|
|
|
|
|
2024-04-19 18:19:41 +02:00
|
|
|
gJobs.dockerVolumeCleaner = CronJob.from({
|
2016-12-28 14:21:41 -08:00
|
|
|
cronTime: '00 00 */12 * * *', // every 12 hours
|
2026-03-12 22:55:28 +05:30
|
|
|
onTick: async () => await safe(janitor.cleanupDockerVolumes(), { debug: log }),
|
2020-02-10 12:17:21 -08:00
|
|
|
start: true
|
2016-12-28 14:21:41 -08:00
|
|
|
});
|
|
|
|
|
|
2024-04-19 18:19:41 +02:00
|
|
|
gJobs.schedulerSync = CronJob.from({
|
2019-07-26 10:10:14 -07:00
|
|
|
cronTime: constants.TEST ? '*/10 * * * * *' : '00 */1 * * * *', // every minute
|
2026-03-12 22:55:28 +05:30
|
|
|
onTick: async () => await safe(scheduler.sync(), { debug: log }),
|
2020-02-10 12:17:21 -08:00
|
|
|
start: true
|
2016-12-28 14:21:41 -08:00
|
|
|
});
|
|
|
|
|
|
2022-07-25 15:27:25 +02:00
|
|
|
// randomized per Cloudron based on hourlySeed
|
2024-04-19 18:19:41 +02:00
|
|
|
gJobs.certificateRenew = CronJob.from({
|
2022-07-29 08:55:01 +02:00
|
|
|
cronTime: `00 10 ${hour} * * *`,
|
2026-03-12 22:55:28 +05:30
|
|
|
onTick: async () => await safe(reverseProxy.startRenewCerts({}, AuditSource.CRON), { debug: log }),
|
2020-02-10 12:17:21 -08:00
|
|
|
start: true
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
2017-07-21 16:13:44 +02:00
|
|
|
|
2025-02-17 19:01:53 +01:00
|
|
|
gJobs.checkDomainConfigs = CronJob.from({
|
|
|
|
|
cronTime: `00 ${minute} 5 * * *`, // once a day
|
2026-03-12 22:55:28 +05:30
|
|
|
onTick: async () => await safe(domains.checkConfigs(AuditSource.CRON), { debug: log }),
|
2025-02-17 19:01:53 +01:00
|
|
|
start: true
|
|
|
|
|
});
|
|
|
|
|
|
2024-04-19 18:19:41 +02:00
|
|
|
gJobs.appHealthMonitor = CronJob.from({
|
2018-10-22 11:39:42 -07:00
|
|
|
cronTime: '*/10 * * * * *', // every 10 seconds
|
2026-03-12 22:55:28 +05:30
|
|
|
onTick: async () => await safe(appHealthMonitor.run(10), { debug: log }), // 10 is the max run time
|
2020-02-10 12:17:21 -08:00
|
|
|
start: true
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-18 16:26:33 +02:00
|
|
|
gJobs.collectStats = CronJob.from({
|
|
|
|
|
cronTime: '*/20 * * * * *', // every 20 seconds. if you change this, change carbon config
|
2026-03-12 22:55:28 +05:30
|
|
|
onTick: async () => await safe(metrics.sendToGraphite(), { debug: log }),
|
2025-05-18 16:26:33 +02:00
|
|
|
start: true
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-16 22:07:54 +02:00
|
|
|
gJobs.subscriptionChecker = CronJob.from({
|
2025-09-29 16:26:01 +02:00
|
|
|
cronTime: `00 ${minute} ${hour} * * *`, // once a day based on seed to randomize
|
2026-03-12 22:55:28 +05:30
|
|
|
onTick: async () => await safe(appstore.checkSubscription(), { debug: log }),
|
2025-07-16 22:07:54 +02:00
|
|
|
start: true
|
|
|
|
|
});
|
|
|
|
|
|
2025-09-29 14:44:42 +02:00
|
|
|
for (const backupSite of await backupSites.list()) {
|
2025-09-12 09:48:37 +02:00
|
|
|
await handleBackupScheduleChanged(backupSite);
|
2025-07-25 08:36:09 +02:00
|
|
|
}
|
2023-08-04 11:43:39 +05:30
|
|
|
await handleAutoupdatePatternChanged(await updater.getAutoupdatePattern());
|
|
|
|
|
await handleDynamicDnsChanged(await network.getDynamicDns());
|
2024-01-13 15:53:14 +01:00
|
|
|
await handleExternalLdapChanged(await externalLdap.getConfig());
|
2020-02-10 12:17:21 -08:00
|
|
|
}
|
|
|
|
|
|
2021-09-07 09:57:49 -07:00
|
|
|
async function stopJobs() {
|
2025-07-25 08:36:09 +02:00
|
|
|
for (const jobName in gJobs) {
|
|
|
|
|
if (!gJobs[jobName]) continue;
|
|
|
|
|
if (util.types.isMap(gJobs[jobName])) {
|
|
|
|
|
gJobs[jobName].forEach((job) => job.stop());
|
|
|
|
|
gJobs[jobName] = new Map();
|
|
|
|
|
} else {
|
|
|
|
|
gJobs[jobName].stop();
|
|
|
|
|
gJobs[jobName] = null;
|
|
|
|
|
}
|
2017-11-27 12:40:13 -08:00
|
|
|
}
|
2015-07-20 00:09:47 -07:00
|
|
|
}
|
2026-02-14 15:43:24 +01:00
|
|
|
|
2026-02-14 16:34:34 +01:00
|
|
|
async function handleTimeZoneChanged(tz) {
|
|
|
|
|
assert.strictEqual(typeof tz, 'string');
|
|
|
|
|
|
2026-03-12 22:55:28 +05:30
|
|
|
log('handleTimeZoneChanged: recreating all jobs');
|
2026-02-14 16:34:34 +01:00
|
|
|
await stopJobs();
|
|
|
|
|
await scheduler.deleteJobs(); // have to re-create with new tz
|
|
|
|
|
await startJobs();
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 15:43:24 +01:00
|
|
|
export default {
|
|
|
|
|
startJobs,
|
|
|
|
|
|
|
|
|
|
stopJobs,
|
|
|
|
|
|
|
|
|
|
handleBackupScheduleChanged,
|
|
|
|
|
handleTimeZoneChanged,
|
|
|
|
|
handleAutoupdatePatternChanged,
|
|
|
|
|
handleDynamicDnsChanged,
|
|
|
|
|
handleExternalLdapChanged,
|
|
|
|
|
|
|
|
|
|
DEFAULT_AUTOUPDATE_PATTERN,
|
|
|
|
|
};
|