nodeGame and SIGTERM

108 views
Skip to first unread message

Don Morrison

unread,
Apr 12, 2022, 5:16:14 PM4/12/22
to nodeGame
I may be misinterpreting what I’m seeing, but it appears to me that
nodeGame is for some reason arranging that the node process in which
it is running ignores the SIGTERM signal. This is a bit awkward if you
want to run nodeGame under systemd — in the usual systemd
configuration it means it takes a minute and a half to stop, and, in
fact, it’s then being stopped rather brutally by SIGKILL, which is
probably worse than whatever evil it’s trying to avoid by ignoring
SIGTERM :-).

Have I correctly sussed out what’s going on? If so, is there anyway to
tell nodeGame/launcher.js “don’t do that” so that SIGTERM will bring
down the process as expected?


--
Don Morrison <df...@cmu.edu>
“The world was full of things I didn’t want to know.”
— Robert Penn Warren, /All the King’s Men/

Stefano B

unread,
Apr 12, 2022, 5:28:08 PM4/12/22
to node...@googlegroups.com
SIGTERM is being _mostly_ ignored now. What would be the desired behavior? It should notify all the games, players should be notified, and gracefully shutdown. Currently it just terminates phantom clients (which have disabled in v7 anyway).

You could add your own 

    process.on('SIGTERM', function() {
        // SOMETHING
    });

I believe it should work even if you define it inside your game. If not, you should edit/comment out the code in ServerNode.js
 

--
You received this message because you are subscribed to the Google Groups "nodeGame" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodegame+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodegame/CAO9hiFXKS2tb4v2zNahrmB2vJW2sfFjcVU7JwOqu5UsHPoWpaw%40mail.gmail.com.

Don Morrison

unread,
Apr 12, 2022, 6:09:55 PM4/12/22
to nodeGame
On Tue, Apr 12, 2022 at 5:28 PM Stefano B <stefanoba...@gmail.com> wrote:
> SIGTERM is being _mostly_ ignored now. What would be the desired behavior?

Exactly the same as ^C (SIGINT), I’d think: shut the thing down as
gracefully as practical, but shut it down.

> You could add your own
>
> process.on('SIGTERM', function() {
> // SOMETHING
> });
>

Is there some sensible place I can add that? Changing the nodeGame
source seems suboptimal since that will cause trouble whenever we
upgrade, and I’m confident I won’t remember what I’ve done to go back
and do it again :-) And putting it into a particular game is a problem
since we’re adding and subtracting games over time and there is no
guarantee that any particular one will always be there. Can it maybe
go into one of the files in nodegame/conf? Though I guess even those
get overwritten on upgrade; but I guess having to remember to copy
over the old conf/ directory along with games_available/ is better
than nothing.

I guess the ideal might be if in some future version there were a
command line option to launcher.js that controls this?

I guess for now I’ll try to remember to kill it with prejudice by hand
whenever I want to restart it (and accept that it’ll delay rebooting
the machine a bit, too :-).

Thanks!


--
Don Morrison <d...@ringing.org>
“It is hard in human actions to arrive by reasoning at any rule
so exact as to exclude Fortune from her rights in the matter.”
— Michel de Montaigne, “Let business wait till tomorrow,”
tr. Donald M Frame

Stefano B

unread,
Apr 13, 2022, 6:04:34 AM4/13/22
to node...@googlegroups.com
Maybe in nodegame/conf is the least worst solution. 
About the best implementation in future releases, I need to understand the use case.
What are you doing after SIGTERM? Simply shutting down?

--
You received this message because you are subscribed to the Google Groups "nodeGame" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodegame+u...@googlegroups.com.

Don Morrison

unread,
Apr 13, 2022, 9:54:34 AM4/13/22
to nodeGame
On Wed, Apr 13, 2022 at 6:04 AM Stefano B <stefanoba...@gmail.com> wrote:
> Maybe in nodegame/conf is the least worst solution.
> About the best implementation in future releases, I need to understand the use case.
> What are you doing after SIGTERM? Simply shutting down?

Yes, using SIGTERM to shut down. The standard mechanism for bringing
services up and down and so on on Ubuntu (and many other Linux
distributions) is systemd. Its normal way of configuring things shuts
stuff down by

• sending SIGTERM
• waiting for the process it had started to stop
• then returning

If the process doesn’t stop in 90 seconds it then sends SIGKILL, which
is a pretty big hammer, not letting the process do an tidying. And,
also that 90 seconds is a long time to wait (especially compared to
the less than a tenth of a second it takes to start, which should be
the harder part :-) if all you’re trying to do is restart nodeGame to
make a small change to its configuration.

Note that if lancher.js took a command line option, say --mumble, that
told it to go ahead an honor SIGTERM, then systemd could be configured
to just start things using something like “node launcher.js --mumble”
and all would be well. I guess ideally nodeGame should be structured
in such a way (maybe it is already) that games could note SIGTERM and
do some tidying like closing databases and so on; or, even saying
“wow, someone is actually actively running this game please wait until
it’s done” — now even if all is quiescent and no one is actually
running a game it refuses to actually shut down, and we have to hammer
it with SIGKILL after 90 seconds which really doesn’t let anyone do
any cleanup at all.

The primary use case is restarting nodeGame to incorporate changes to
one or more of its games. The secondary use case is shutting down or
rebooting the host machine (which will wait until systemd tells it
nodeGame has stopped). The tertiary use case is other reasons we might
need to stop nodeGame, such as upgrading, changing its global
configuration, moving where the code is stored on the physical box,
stuff like that.

In principle systemd is sufficiently configurable we should be able to
make it do things differently than its default behavior, but I’ve not
been able to figure that out sufficiently to make it work well. Right
now I’m just shooting things with SIGKILL, which is always a little
iffy.

To give a little context, in the past, other folks in our lab found
the whole thing sufficiently difficult to understand that they’d each
just run their own instance of nodeGame using a different port,
running under their own terminal, and eventually killing it with ^C;
or nohupping it into the background, and trying to keeptrack of the
process number, or trying to look it up again later with pgrep or
something, so they could some back and kill --int it later, which many
times ended up with folks accidentally killing the wrong process and
making a mess of things. We’ve got a new physical server and I’m
trying to make the world simpler and tidier on it so folks only have
to move links in and out of nodegame/games/ and we don’t have to shoot
processes by hand and keep opening new ports in the firewall.

Hope that’s clear. Thanks!


--
Don Morrison <d...@ringing.org>
“Human work must be done thoroughly and honourably because
we are now men; whether we ever expect to be angels, or ever
were slugs, being practically no matter.”
— John Ruskin, /Fors Clavigera/

Stefano B

unread,
Apr 13, 2022, 12:17:26 PM4/13/22
to node...@googlegroups.com
Thanks for the detailed explanation. I guess probably listening to SIGTERM should be on by default. 

More generally, it seems that it would be a great deal if people could add/stop/restart games without restarting the whole nodeGame server, right? 

--
You received this message because you are subscribed to the Google Groups "nodeGame" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodegame+u...@googlegroups.com.

Don Morrison

unread,
Apr 13, 2022, 3:16:23 PM4/13/22
to nodeGame
On Wed, Apr 13, 2022 at 12:17 PM Stefano B
<stefanoba...@gmail.com> wrote:
> More generally, it seems that it would be a great deal if people
> could add/stop/restart games without restarting the whole nodeGame
> server, right?

That would be extremely welcome!


--
Don Morrison <d...@ringing.org>
“The universe winds down. That’s how it’s made.”
— John M Ford, “Against Entropy”
Reply all
Reply to author
Forward
0 new messages