Add more commands

This commit is contained in:
Myx
2023-07-02 01:54:47 +02:00
parent eccad8d147
commit 398382a7f1
18 changed files with 434 additions and 144 deletions

View File

@@ -1,44 +1,47 @@
/* eslint-disable no-shadow */
const { exec } = require('child_process');
const schedule = require('node-schedule');
const ConsolerLogger = require('./utils/logger');
const repoUrl = 'https://github.com/Myxelium/Lunaris/';
const localRepoPath = '/home/pi/Lunaris/';
const processName = 'index.js';
const logger = new ConsolerLogger();
schedule.scheduleJob('0 1 * * *', () => {
exec(`cd ${localRepoPath} && git fetch`, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
exec(`cd ${localRepoPath} && git rev-list HEAD...origin/master --count`, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
if (parseInt(stdout) > 0) {
exec(`pm2 stop ${processName}`, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
exec(`cd ${localRepoPath} && git pull`, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
const now = new Date();
console.log(`Repository updated at ${now.toLocaleString()}`);
exec(`pm2 start ${processName}`, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`${processName} started`);
});
});
});
}
});
});
});
exec(`cd ${localRepoPath} && git fetch`, (error) => {
if (error) {
logger.error(`exec error: ${error}`);
return;
}
exec(`cd ${localRepoPath} && git rev-list HEAD...origin/master --count`, (error, stdout) => {
if (error) {
logger.error(`exec error: ${error}`);
return;
}
if (parseInt(stdout, 10) > 0) {
exec(`pm2 stop ${processName}`, (error) => {
if (error) {
logger.error(`exec error: ${error}`);
return;
}
exec(`cd ${localRepoPath} && git pull`, (error) => {
if (error) {
logger.error(`exec error: ${error}`);
return;
}
const now = new Date();
logger.log(`Repository updated at ${now.toLocaleString()}`);
exec(`pm2 start ${processName}`, (error) => {
if (error) {
logger.error(`exec error: ${error}`);
return;
}
logger.log(`${processName} started`);
});
});
});
}
});
});
});