First actual commit
This commit is contained in:
parent
504170bf37
commit
2bd257245a
3 changed files with 86 additions and 3 deletions
24
index.js
Normal file
24
index.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
var fs = require('fs-extra');
|
||||
var running = require('running');
|
||||
|
||||
module.exports = {
|
||||
lock: function(name, callback) {
|
||||
var filename = '/var/run/' + name + '.pid';
|
||||
|
||||
// Checks if PID file exists
|
||||
if (fs.existsSync(filename)) {
|
||||
// Checks if the PID is still active
|
||||
var pid = fs.readFileSync(filename, 'utf8');
|
||||
|
||||
if (running(pid)) {
|
||||
console.log('PID ' + pid + ' found in ' + filename + ' is running.');
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Writes the PID
|
||||
fs.writeFileSync(filename, process.pid);
|
||||
|
||||
callback && callback();
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue