Skip to content

Instantly share code, notes, and snippets.

@beall49
Created December 21, 2018 01:54
Show Gist options
  • Save beall49/ba566b9bf18fcb912262858e05afce96 to your computer and use it in GitHub Desktop.
Save beall49/ba566b9bf18fcb912262858e05afce96 to your computer and use it in GitHub Desktop.
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