Created
January 12, 2015 08:50
-
-
Save undoZen/51033b69cd0397034b8f 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
function isMasterRunning() { | |
var pidFilePath = path.join(__dirname, 'ds.pid'); | |
var strpid; | |
var isRunning; | |
if (fs.existsSync(pidFilePath)) { | |
strpid = fs.readFileSync(pidFilePath, 'utf-8'); | |
isRunning = require('is-running')(parseInt(strpid, 10)); | |
} | |
if (isRunning) { | |
return strpid; | |
} | |
return false; | |
} | |
gulp.task('start', ['build-and-clean'], function () { | |
var strpid = isMasterRunning(); | |
if (strpid) { | |
console.log('pm master is running. sending USR1 signal...'); | |
exec('kill -s USR1 ' + strpid); | |
} else { | |
console.log('pm master is not running. spawning one...'); | |
spawn(process.execPath, [path.join(__dirname, 'master.js')], { | |
cwd: __dirname, | |
env: assign({}, process.env, { | |
NODE_ENV: 'production' | |
}), | |
silent: true, | |
detached: true, | |
stdio: ['ignore', 'ignore', 'ignore'] | |
}) | |
.unref(); | |
} | |
}); | |
gulp.task('stop', function () { | |
var strpid = isMasterRunning(); | |
if (strpid) { | |
console.log('pm master is running. terminating...'); | |
exec('kill -s TERM ' + strpid); | |
} else { | |
console.log('pm master is not running. exiting...'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment