[squeak-dev] competition for SIGTERM

David T. Lewis lewis at mail.msen.com
Mon Apr 27 23:53:15 UTC 2015


On Sun, Apr 26, 2015 at 06:57:51PM -0500, Chris Muller wrote:
> OSProcess provides the ability to set up and wait on any of several
> semaphores which will be signaled if the VM process running the
> current image gets a posix signal.
> 
> A few years ago I added a handler for SqueakSource's startUp: to set
> up a response to TERM, like this:
> 
> restartSigTermHandler
> SigTermHandler ifNotNil: [ SigTermHandler terminate ].
> SigTermHandler :=
>           [ OSProcess accessor restoreSigTerm.
>           OSProcess accessor forwardSigTerm wait.
>           SSRepository current log: 'SIGTERM received, shutting down
> gracefully.'.
>           self shutDown.
>           Smalltalk snapshot: false andQuit: true ] newProcess
>                 name: 'Waiting for SIGTERM for graceful shutdown' ;
>                 resume
> 
> But now I want Magma servers to be able to respond similarly whether
> SqueakSource is loaded in the same image or not.  But if I were to
> introduce the above into Magma, then if SqueakSource was also loaded,
> there would either be two processes waiting to shutdown or one of them
> would run and the other wouldn't.
> 
> So this led me to ask, what is the best way to handle this in a
> general fashion?  This is at the process level, so the first answer I
> came up with was that it would make sense for the out-of-the-box
> behavior to respond to TERM with a "Smalltalk snapshot: false andQuit:
> true" so that each framework can do their own proper thing in
> #shutDown:...   Is this a good idea or what is?

I guess that if you wanted to generalize this, you might follow the
pattern of the system startUp: and shutDown: processing, and maybe have
a class that was responsible for holding on to the processes that wait
for signals. A class could register itself as being interested in SIGTERM
if it implemented a method #sigTerm that did something to respond to
that signal.

I would be cautious about saving the image in response to a SIGTERM,
except in the special case of a server image that wanted to do so. It
is possible to open several VMs on the same image, either on purpose
or by accident, and you would not want all those VMs to be trying to
save the same image when you do "killall squeak". And I think that
SIGTERM is sent to all processes when the system is being rebooted,
so you would not want to be half way through saving your image when
the system goes down.

Dave



More information about the Squeak-dev mailing list