I am creating a small proprietary game server manager in Node.js; currently it runs the game by spawning via child_process
:
var server = spawn(cmd, args, { cwd: 'something' });
So long as the manager continues to run I can pipe commands and deal with the child as I would like. However, consider the possibility that my manager crashes or is closed. How would I then reattach to the previously spawned child process (which was still running while the manager was down)? I can store pidfiles to try and reconnect based on pid; but I'm not sure how to get a child_process
object with access to the child's stdio
objects.
I really would like this to be recoverable; any help is appreciated, thanks!
Please note: The game servers are proprietary, some examples are Minecraft, Source DS, etc. Assume i do not have access to the sever source.
EDIT
After reading some source code from node's child_process
it looks like if you specify a property in the options called stdinStream
, stdoutStream
, or stderrStream
it should just open a socket to it. (See lines 428 - 496). So the issue then is, how do I stop spawn from actually doing a spawn and instead just settings its values based on a specified pid and streams I pass. (I would get my stdinStream
by doing fs.createWriteStream('/proc/PID/fd/0');
which should work since that fd is created as a pipe.)
stdin
of the child process, since I have little experience with *nix sockets how could I accomplish regaining a 'pipe' to the child'sstdin
? – Heydon