From b3789858f031242e6cc5c34a6823ac360902c7a0 Mon Sep 17 00:00:00 2001 From: LESO Date: Thu, 29 Jun 2023 02:08:51 +0200 Subject: [PATCH] Create maintenance.js --- maintenance.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 maintenance.js diff --git a/maintenance.js b/maintenance.js new file mode 100644 index 0000000..016cd07 --- /dev/null +++ b/maintenance.js @@ -0,0 +1,39 @@ +Sure, here is an updated version of the script that will log the date and time when the repository was updated: + +const { exec } = require('child_process'); +const schedule = require('node-schedule'); + +const repoUrl = 'https://github.com/Myxelium/Lunaris/'; +const localRepoPath = '/home/pi/Lunaris/'; + +schedule.scheduleJob('0 1 * * *', () => { + exec(`cd ${localRepoPath} && git fetch`, (error, stdout, stderr) => { + if (error) { + console.error(`exec error: ${error}`); + return; + } + if (stdout.includes('[new branch]')) { + exec('pm2 stop Lunaris', (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 Lunaris', (error, stdout, stderr) => { + if (error) { + console.error(`exec error: ${error}`); + return; + } + console.log('Lunaris started'); + }); + }); + }); + } + }); +});