blah238
blah238

Reputation: 1856

Stopping nodejs service does not kill node process when wrapped in "script" command

I am running a turnkey-node (Debian Wheezy) appliance in VirtualBox on a Windows XP 32-bit host.

Within the Debian guest I've made a few modifications so that it runs my own NodeJS application rather than the default one.

I've also modified the example run.sh script so that instead of directly running node, it runs the script command which in turn runs node so that I can log its output to a file and trick node into thinking it's using a TTY so as to retain color escape sequences in the log output, as discussed here, here and here.

This all works great except when it's time to shutdown the nodejs service -- the script, sh and node processes all continue to live on after the service is stopped.

Any ideas why this is happening? I am guessing the included nodejs init script wasn't intended to be used like this but I wouldn't know the first thing about changing it to fix this.

Here are the changes I mentioned:

There were also a couple of minor modifications in order to get nodejs working with the VirtualBox shared folder feature, but that's aside the point I think.

Upvotes: 0

Views: 997

Answers (1)

BraveNewCurrency
BraveNewCurrency

Reputation: 13065

put an exec before your script.

When you just say "foo" in a script, the script forks off a child and runs it, then when it exits, the shell continues on to the next command. So your "init" sees the "shell" as it's child, and node is the grandchild.

If you say exec script -qfc "node server.js" server.log, then you're telling the shell not to fork a child, but directly execute the command and never return. That way, your init scripts will see node as it's child, and directly send node signals.

Upvotes: 1

Related Questions