[ejabberd] blending hot code load and modules

Geoff Cant nem at erlang.geek.nz
Tue Apr 20 22:20:42 MSD 2010


On 2010-04-20, at 11:07 , Brian Acton wrote:

> hi guys,
> 
> i've been writing modules for ejabberd and one of the pain points for me has
> been the inability to use hot code load.
> 
> the normal procedures that I have tried have been
> 
> $ ejabberdctl debug
> 1> mod_last:stop().
> <push new code to ebin>

Unless this step involves telling the ejabberd node to load the new code, erlang will simply keep the old version loaded, which means that when you call

> 2> mod_last:start().

It will just run the old version again.


> or
> 
> $ ejabberdctl debug
> 1> gen_mod:stop_module(Host, mod_last)
> <push new code to ebin>
> 2> gen_mod:start_module(Host, mod_last, []).

Again, unless you cause the new beam file to be loaded, you'll get the old version at step 2.

To get the new code to load you need to call l(module), code:load_file(module) or something similar. The normal erlang code upgrade rules apply (http://www.erlang.org/doc/reference_manual/code_loading.html).

If your module just sets up hooks, but doesn't spawn any processes i.e. you have a library module rather than one that implements a kind of process, then you don't even have to stop and start the module in ejabberd when you're reloading it (provided the new version can cope with any state (ets/mnesia records) created by the old version. Just login to the shell and call 'l(your_module).'

If you spawn processes in your module, then doing a smooth upgrade is more involved but still straight forward. Section 13.3 explains the upgrade process for plain erlang processes. If you spawn gen_server/gen_fsm processes, you'll need to do something like sys:suspend/1 on all processes running your gen_* callback module, l(your_module), sys:change_code/4 on all the processes you suspended and sys:resume/1 them.

Cheers
-Geoff Cant


More information about the ejabberd mailing list