Created
December 21, 2018 01:54
-
-
Save beall49/ba566b9bf18fcb912262858e05afce96 to your computer and use it in GitHub Desktop.
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
const isNotPM2 = (process.env.PM2_HOME === undefined); | |
if (isNotPM2) { | |
const fs = require('fs'); | |
const appDir = config.getAppDir(); | |
const pidPath = `${appDir}/pid-backup/node.pid`; | |
const newPid = process.pid; | |
const writer = () => { | |
fs.writeFile(pidPath, newPid, async () => { | |
}); | |
}; | |
try { | |
if (!fs.existsSync(pidPath)) { | |
writer(); | |
} else { | |
const pid = fs.readFileSync(pidPath, 'utf8'); | |
if (parseInt(pid) !== newPid) { | |
writer(); | |
} | |
} | |
} catch (error) { | |
console.log(`Couldn't read or write pid, ${error}`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment