mirror of
https://gitlab.com/octospacc/Configs.git
synced 2025-06-05 21:59:36 +02:00
[Server] new system JS scripts
This commit is contained in:
66
Server/Root/etc/diycron.zx.mjs
Executable file
66
Server/Root/etc/diycron.zx.mjs
Executable file
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env zx
|
||||
let Jobs = {};
|
||||
|
||||
const ResetJobs = () => (Jobs = {
|
||||
Backup: false,
|
||||
Certs: false,
|
||||
});
|
||||
ResetJobs();
|
||||
|
||||
const Work = (Job, Funct) => {
|
||||
if (!Jobs[Job]) {
|
||||
Jobs[Job] = true;
|
||||
Funct();
|
||||
};
|
||||
};
|
||||
|
||||
echo`=====[ diycron started at ${new Date()} ]=====`;
|
||||
|
||||
while (true) {
|
||||
|
||||
const T = new Date();
|
||||
//T.Y = T.getFullYear()
|
||||
T.M = (T.getMonth() +1);
|
||||
T.D = T.getDate();
|
||||
T.h = T.getHours();
|
||||
T.m = T.getMinutes();
|
||||
//T.s = T.getSeconds();
|
||||
T.is = (question) => {
|
||||
let allTrue = true;
|
||||
for (let predicate in question) {
|
||||
let word = predicate.replace('_', '');
|
||||
let oracle = {
|
||||
//Y: T.Y,
|
||||
M: T.M,
|
||||
D: T.D,
|
||||
h: T.h,
|
||||
m: T.m,
|
||||
//s: T.s,
|
||||
}[word];
|
||||
if (predicate.endsWith('_') && predicate.startsWith('_')) {
|
||||
!((oracle % question[predicate]) == 0) && (allTrue = false);
|
||||
} else if (predicate.endsWith('_')) {
|
||||
!(oracle <= question[predicate]) && (allTrue = false);
|
||||
} else if (predicate.startsWith('_')) {
|
||||
!(oracle >= question[predicate]) && (allTrue = false);
|
||||
} else {
|
||||
!(oracle == question[predicate]) && (allTrue = false);
|
||||
};
|
||||
};
|
||||
return allTrue;
|
||||
};
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
//T.is({ h:'03', m_:'05' })
|
||||
// && Work('Backup', ()=>{ $`zx /Main/Server/Scripts/BackupAll.zx.mjs` });
|
||||
|
||||
T.is({ _D_:'9', h:'04', m_:'05' })
|
||||
&& Work('Certs', ()=>{ $`sh /Main/Server/Scripts/RenewCerts.sh` });
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
(T.h=='00' && T.m=='00') && ResetJobs();
|
||||
await sleep(7500);
|
||||
|
||||
};
|
Reference in New Issue
Block a user