remy / servedir

Creates a simple node based web server for a directory
92 stars 15 forks source link

Ability to stop servedir instance from command line #16

Open JamesMGreene opened 12 years ago

JamesMGreene commented 12 years ago

Wanted: Ability to stop servedir instance from command line, with the same basic input combos as the command to start them. For example:

Not 100% sure what the last one would do:

  1. Stop the servedir instance only if it matched both inputs
  2. Stop the servedir instances (possibly 2+) that match each individual input

Please consider it. Thanks!

JamesMGreene commented 12 years ago

Any update, @kitcambridge? :)

ghost commented 12 years ago

So...here's what I've come up with:

  1. The servedir executable would need to be converted into a wrapper that supports the start and stop commands. We can't have multiple servers listening on the same port, so I think we can simplify stop to accept just a port argument. Both start and stop would use the default port if it is not specified.
  2. servedir start would be responsible for starting a new background process (the actual server, launched using require("child_process").fork), recording its PID (I can't think of a better way of achieving this than a temporary file), then exiting normally. The child process would continue to run in the background and accept connections.
  3. servedir stop would read the PID from the temporary file, then delete the file and kill the child process.

Potential problems with this approach:

  1. It's incredibly quick and dirty, but perhaps too much for servedir's core (I'm particularly uncomfortable with using a temporary file to store the PID). You might be better off implementing this yourself.
  2. More importantly, the forks are not free—you'd be launching a separate Node process per server.
JamesMGreene commented 12 years ago

@kitcambridge: Thanks for the analysis work. I would be inclined to agree that this is probably best left out of servedir core, rather in favor of a generic Node "ProcMon"/"Task Manager" kind of module. Know of any modules like that?

WebReflection commented 12 years ago

guys I have implemented what James asked for via chef for polpetta and if you want I can use first argument with polpetta or serverdir so we can use chef for both projects. Right now it's coupled via path.join(__dirname, "polpetta") but if you put "serverdir" and move chef inside the same folder I believe the logic will simply work as expected. Have a look if you are interested, cheers

JamesMGreene commented 12 years ago

Nice. Way to overachieve, @WebReflection. :)

WebReflection commented 12 years ago

cheers, there's some Windows 7 gotcha in my Atom's based PCrap but with Mac and Linux serverdir is already supported with latest chef ;)