mattijs/node-rsync — pull request #26 by mw-white (2014-12-15 17:00:30+00:00)
Title: Changes to allow process cleanup when parent killed

Hi - great module, very useful!

This change allows the process to be aborted or cleaned up properly with the parent process being killed. I wanted to be able to kill a running rsync from my process, and I was also having problems with rsync processes hanging around if I killed the main process on some machines.

The problem turned out to be that Debian (and likely its derivatives) have /bin/sh symlinked to /bin/dash, and dash doesn't seem to do proper child process control. This change adds a check to see if /bin/sh is /bin/dash, and if so, it will use /bin/bash if it exists. It also returns the cmdProc object to the caller.

It would be used like this:
`var rsyncPid = rsync.execute(....);`

Then, you can kill the rsync subprocess if you like:
`rsyncPid.kill();`

You can also catch signals to clean up rsync processes if the main process is killed:

var quitting = function() {
if (rsyncPid) {
rsyncPid.kill();
}
}

process.on("SIGINT", quitting);
process.on("SIGTERM", quitting);
process.on("exit", quitting);