This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 271
use npid for pid file support #555
Open
apmorton
wants to merge
1
commit into
erming:master
Choose a base branch
from
apmorton:feature/npid
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -2,19 +2,59 @@ var ClientManager = new require("../clientManager"); | |
var program = require("commander"); | ||
var shout = require("../server"); | ||
var Helper = require("../helper"); | ||
var path = require("path"); | ||
|
||
program | ||
.option("-H, --host <ip>" , "host") | ||
.option("-P, --port <port>" , "port") | ||
.option("-B, --bind <ip>" , "bind") | ||
.option(" --public" , "mode") | ||
.option(" --private" , "mode") | ||
.option(" --silent" , "suppress errors about pid file creation") | ||
.command("start") | ||
.description("Start the server") | ||
.action(function() { | ||
var users = new ClientManager().getUsers(); | ||
var config = Helper.getConfig(); | ||
var mode = config.public; | ||
|
||
if (config.pidFile) { | ||
// setup exception handler to cleanup pid file and log errors | ||
process.on("uncaughtException", function(e) { | ||
console.log("uncaughtException: " + e.stack || e); | ||
process.exit(1); | ||
}); | ||
|
||
// setup signal handlers to cleanly exit process | ||
// which allows the pid file to be removed | ||
process.on("SIGINT", process.exit.bind(process, 0)); | ||
process.on("SIGTERM", process.exit.bind(process, 0)); | ||
|
||
// use the default pid file name if the configuration | ||
// variable is not a string | ||
if (typeof config.pidFile !== "string") { | ||
config.pidFile = "shout.pid"; | ||
} | ||
|
||
// get the absolute path of the pid file to use | ||
var pidFilePath = path.resolve(Helper.HOME, config.pidFile); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as you can see here @JocelynDelalande, although paths are relative to IE, if you specify |
||
|
||
// attempt to create the pid file or die trying | ||
try { | ||
var pid = require("npid").create(pidFilePath); | ||
pid.removeOnExit(); | ||
} catch (e) { | ||
// spit out an error message about pid file creation | ||
if (!program.silent) { | ||
console.log("unable to create pid file: " + pidFilePath); | ||
console.log(e.stack || e); | ||
} | ||
|
||
// process is already running, so bail out now | ||
process.exit(1); | ||
} | ||
} | ||
|
||
if (program.public) { | ||
mode = true; | ||
} else if (program.private) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with other paths in config (ex: ssl key), this should not be relative to HOME folder (+ it's a limitation).