chokidar-socket-emitter icon indicating copy to clipboard operation
chokidar-socket-emitter copied to clipboard

Detect is emitter already running

Open ArmorDarks opened this issue 8 years ago • 6 comments

Thanks for the lib!

I wonder, is it possible somehow to detect is emitter already running? Or make so that invoking emitter second time (when it is already running) will not fail and simple ignore invocation?

ArmorDarks avatar Jul 24 '17 20:07 ArmorDarks

@ArmorDarks You sure could. Most unix init scripts do just that. (edge cases, but alas!)

Log the process ID of the emitter (or perhaps the parent in which launched it, however you prefer) to a file after forking the chokidar emitter. future executions simply involve a check against this logged PID to decide whether or not to fail and terminate before a further launch.

i8degrees avatar Dec 09 '17 02:12 i8degrees

@i8degrees Thanks! Though, wow, that sounded slightly more complicated than it should be...

Anyway, I guess this library isn't maintained anyway, so there little chances that it will be extended or a PR will be accepted, right, @capaj?

ArmorDarks avatar Dec 09 '17 11:12 ArmorDarks

@ArmorDarks I haven't touched this codebas in quite a while, but I will certainly merge a PR if you make it well. Feel free to update dependencies as well while you're at it.

capaj avatar Dec 09 '17 12:12 capaj

@capaj Thanks for the reply! I'll try to investigate how to do this since I do not have a clear picture yet. @i8degrees give me a good path to watch, but still, there are some things to be figured out...

ArmorDarks avatar Dec 09 '17 13:12 ArmorDarks

@ArmorDarks nods I thought the same myself for many years! It is actually a rather clever, simple design that is proven the test of time.

  • process management (do it yourself)

    • launching a daemon (server) from your own script
      • https://nodejs.org/dist/latest-v8.x/docs/api/child_process.html#child_process_asynchronous_process_creation
      • https://nodejs.org/dist/latest-v8.x/docs/api/child_process.html#child_process_subprocess_pid
    • managing the daemon -- chokidar-socket-emitter -- from its own codebase
      • https://nodejs.org/dist/latest-v8.x/docs/api/process.html#process_process_pid
  • third-party process management

    • https://www.freebsd.org/cgi/man.cgi?query=daemon&sektion=8
    • http://supervisord.org/index.html
    • http://pm2.keymetrics.io/
  • history

    • https://en.wikipedia.org/wiki/UNIX_System_V
    • https://en.wikipedia.org/wiki/Init

I kept this list short, so to try a gentle introduction. You will often find in OSS server distributions a contrib directory that contains process scripts for various platforms. This would be an excellent place to start looking for reference implementation details. Sorry, no distribution name comes to mind, but you'll find a plethora in FreeBSD ports.

Good luck!

P.S. Remember, what is important (generally speaking, perhaps not in your case?) are emitters that you depend on, so that you can keep from touching third-party emitters that may be running. This is one reason how PID lists can be nice.

i8degrees avatar Dec 09 '17 20:12 i8degrees

The necessity of disk operation is no-go for me since it will impact our build system performance, which means the harder time during development. But thanks for the lead, I will look into it.

ArmorDarks avatar Dec 09 '17 20:12 ArmorDarks