Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

pidfile support #11

Open
wants to merge 2 commits into from

1 participant

@JustinTulloss

I added a command option that enables spark to write pids out to a file, which is nice when you're using external monitoring tools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 7, 2010
  1. @JustinTulloss
  2. @JustinTulloss

    removed unused variable

    JustinTulloss authored
This page is out of date. Refresh to see the latest.
Showing with 39 additions and 0 deletions.
  1. +39 −0 bin/spark
View
39 bin/spark
@@ -74,6 +74,7 @@ var usage = ''
+ ' --ssl-key PATH SSL key file\n'
+ ' --ssl-crt PATH SSL certificate file\n'
+ ' -n, --workers NUM Number of worker processes to spawn\n'
+ + ' -p, --pidfile PATH File to store PID of server and any child PIDs\n'
+ ' -I, --include PATH Unshift the given path to require.paths\n'
+ ' -E, --env NAME Set environment, defaults to "development"\n'
+ ' -M, --mode NAME Alias of -E, --env\n'
@@ -299,6 +300,17 @@ function startWorker() {
});
stdin.addListener('fd', function(fd){
var app = requireApp(getAppPath());
+ if (env.pidfile) {
+ fs.open(env.pidfile, 'a+', function(err, fd) {
+ if (err) {
+ sys.error(err)
+ return;
+ }
+ else {
+ fs.write(fd, process.pid + '\n');
+ }
+ });
+ }
sys.error('Spark server(' + process.pid + ') listening on '
+ 'http' + (env.sslKey ? 's' : '') + '://'
+ (env.host || '*') + ':' + env.port
@@ -380,6 +392,11 @@ function start() {
// Ignore
}
});
+
+ if (env.pidfile) {
+ fs.unlinkSync(env.pidfile);
+ }
+
process.exit();
});
});
@@ -389,6 +406,18 @@ function start() {
// Load the app module
var app = requireApp(path);
+ if (env.pidfile) {
+ console.log('writing pidfile');
+ fs.open(env.pidfile, 'w', function(err, fd) {
+ if (err) {
+ sys.error(err)
+ return;
+ }
+ else {
+ fs.write(fd, process.pid + '\n');
+ }
+ });
+ }
sys.error('Spark server(' + process.pid + ') listening on '
+ 'http' + (env.sslKey ? 's' : '') + '://'
+ (env.host || '*') + ':' + env.port
@@ -396,6 +425,12 @@ function start() {
enableSSL(app, env);
app.listen(env.port, env.host);
+ process.on('exit', function() {
+ if (env.pidfile) {
+ fs.unlinkSync(env.pidfile);
+ }
+ });
+
changeUser();
}
@@ -497,6 +532,10 @@ function parseArguments(args, cmd) {
case '--ssl-crt':
env.sslCrt = fs.readFileSync(requireArg('--ssl-crt'), 'ascii');
break;
+ case '-p':
+ case '--pidfile':
+ env.pidfile = requireArg('--pidfile');
+ break;
default:
if (arg[0] === '-') {
arg = arg.substr(2);
Something went wrong with that request. Please try again.