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 localRepoPath = '/home/pi/Lunaris/';
const processName = 'index.js';
schedule.scheduleJob('0 1 * * *', () => {
exec(`cd ${localRepoPath} && git fetch`, (error, stdout, stderr) => {
@@ -10,28 +11,34 @@ schedule.scheduleJob('0 1 * * *', () => {
console.error(`exec error: ${error}`);
return;
}
if (stdout.includes('[new branch]')) {
exec('pm2 stop index.js', (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
exec(`cd ${localRepoPath} && git pull`, (error, stdout, stderr) => {
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;
}
const now = new Date();
console.log(`Repository updated at ${now.toLocaleString()}`);
exec('pm2 start index.js', (error, stdout, stderr) => {
exec(`cd ${localRepoPath} && git pull`, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log('Lunaris started');
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`);
});
});
});
});
}
}
});
});
});