Last active
April 10, 2024 20:35
-
-
Save julianoBRL/88aa113f254ca36b81bd41cd1fe94451 to your computer and use it in GitHub Desktop.
PM2 Ecosystem Autoscan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Title: PM2 Ecosystem Autoscan | |
Author: Juliano Lira(Shintaro) | |
Date: 10/04/2024 17:30 | |
*/ | |
const fs = require('node:fs'); | |
const path = require('node:path'); | |
const apps = [] | |
const scanServices = () => { | |
const servicesFolders = fs.readdirSync(__dirname); | |
for (const folder of servicesFolders) { | |
const servicePath = path.join(__dirname, folder); | |
if(fs.lstatSync(servicePath).isDirectory()){ | |
const serviceStartup = fs.readdirSync(servicePath).filter(file => file.match("PM2_Startup.js")); | |
const serviceStartupPath = path.join(servicePath, serviceStartup[0]); | |
const startup = require(serviceStartupPath); | |
if ('startup' in startup) { | |
apps.push(startup.startup); | |
} else { | |
console.log(`[WARNING] The command at ${serviceStartup} is missing a required [startup] property.`); | |
} | |
} | |
} | |
return apps; | |
} | |
module.exports = { | |
apps : scanServices() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment