Update maintenance.js

This commit is contained in:
2023-06-29 03:44:58 +02:00
committed by GitHub
parent f7a386754a
commit e6f07d9713

View File

@@ -3,6 +3,7 @@ const schedule = require('node-schedule');
const repoUrl = 'https://github.com/Myxelium/Lunaris/'; const repoUrl = 'https://github.com/Myxelium/Lunaris/';
const localRepoPath = '/home/pi/Lunaris/'; const localRepoPath = '/home/pi/Lunaris/';
const processName = 'index.js';
schedule.scheduleJob('0 1 * * *', () => { schedule.scheduleJob('0 1 * * *', () => {
exec(`cd ${localRepoPath} && git fetch`, (error, stdout, stderr) => { exec(`cd ${localRepoPath} && git fetch`, (error, stdout, stderr) => {
@@ -10,8 +11,13 @@ schedule.scheduleJob('0 1 * * *', () => {
console.error(`exec error: ${error}`); console.error(`exec error: ${error}`);
return; return;
} }
if (stdout.includes('[new branch]')) { exec(`cd ${localRepoPath} && git rev-list HEAD...origin/master --count`, (error, stdout, stderr) => {
exec('pm2 stop index.js', (error, stdout, stderr) => { if (error) {
console.error(`exec error: ${error}`);
return;
}
if (parseInt(stdout) > 0) {
exec(`pm2 stop ${processName}`, (error, stdout, stderr) => {
if (error) { if (error) {
console.error(`exec error: ${error}`); console.error(`exec error: ${error}`);
return; return;
@@ -23,15 +29,16 @@ schedule.scheduleJob('0 1 * * *', () => {
} }
const now = new Date(); const now = new Date();
console.log(`Repository updated at ${now.toLocaleString()}`); console.log(`Repository updated at ${now.toLocaleString()}`);
exec('pm2 start index.js', (error, stdout, stderr) => { exec(`pm2 start ${processName}`, (error, stdout, stderr) => {
if (error) { if (error) {
console.error(`exec error: ${error}`); console.error(`exec error: ${error}`);
return; return;
} }
console.log('Lunaris started'); console.log(`${processName} started`);
}); });
}); });
}); });
} }
}); });
}); });
});