First actual commit

This commit is contained in:
Josh Sherman 2014-11-25 23:47:04 -05:00
parent 504170bf37
commit 2bd257245a
3 changed files with 86 additions and 3 deletions

24
index.js Normal file
View 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();
}
};