-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
read and write pid using file system
- Loading branch information
1 parent
e6e424f
commit 80e9cf2
Showing
4 changed files
with
67 additions
and
30 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,40 @@ | ||
'use strict'; | ||
'use strict'; | ||
|
||
let cbToCall; | ||
const process = global.process | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const os = require('os'); | ||
|
||
const isProcessOk = (process) => { | ||
return process && | ||
typeof process === 'object' && | ||
typeof process.kill === 'function' && | ||
typeof process.pid === 'number' && | ||
typeof process.on === 'function' | ||
} | ||
let cbToCall; | ||
const process = global.process | ||
|
||
const reloadCbFn = (cb) => { | ||
cbToCall = cb; | ||
}; | ||
|
||
process.on('SIGPIPE', () => { | ||
if (typeof cbToCall === 'function') { | ||
cbToCall(); | ||
} else { | ||
console.error('SIGPIPE triggered but no callback provided to execute!'); | ||
const isProcessOk = (process) => { | ||
return process && | ||
typeof process === 'object' && | ||
typeof process.kill === 'function' && | ||
typeof process.pid === 'number' && | ||
typeof process.on === 'function' | ||
} | ||
}); | ||
|
||
if (!isProcessOk(process)) { | ||
module.exports = () => { | ||
return () => {} | ||
} | ||
} else { | ||
module.exports = reloadCbFn; | ||
} | ||
const reloadCbFn = (cb) => { | ||
cbToCall = cb; | ||
fs.writeFile(path.join(os.tmpdir(), 'rnr.pid'), process.pid.toString(), function (err) { | ||
if (err) return console.log(err); | ||
console.log('rnr.pid saved successfully'); | ||
}); | ||
}; | ||
|
||
process.on('SIGPIPE', () => { | ||
if (typeof cbToCall === 'function') { | ||
cbToCall(); | ||
} else { | ||
console.error('SIGPIPE triggered but no callback provided to execute!'); | ||
} | ||
}); | ||
|
||
if (!isProcessOk(process)) { | ||
module.exports = () => { | ||
return () => {} | ||
} | ||
} else { | ||
module.exports = reloadCbFn; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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