[ejabberd] Re: Adding virtual hosts without restarting ejabberd

Magnus Henoch mange at freemail.hu
Wed May 31 19:11:24 MSD 2006


Lucas Nussbaum <lucas at lucas-nussbaum.net> writes:

> Hi,
>
> I understand that the only way to add virtual hosts is to add them in
> ejabberd's configuration file, and then restart the server.
>
> Are there some plans to allow the creation of virtual hosts using
> ejabberdctl or the web interface ? How difficult would it be to add such
> a feature ?

It seems to me that it would be nontrivial, but not very difficult.
ejabberd_sm and ejabberd_local add some host-specific hooks in their
init routines by looping over ?MYHOSTS; that would need to be run
again.  Most modules would need to be started once again, with the new
name - or stopped, if a virtual host is being removed.

It might look something like this (completely untested):

%% change the configuration file, and then run this function
change_virtual_hosts() ->
    OldHosts = ?MYHOSTS,
    ejabberd_config:start(),
    NewHosts = ?MYHOSTS,
    AddedHosts = NewHosts -- OldHosts,
    RemovedHosts = OldHosts -- NewHosts,
    
    %% I might have forgotten some...
    ejabberd_sm:start(),
    ejabberd_local:start(),
    ejabberd_auth:start(),

    lists:foreach(
      fun(Host) ->
	      case ejabberd_config:get_local_option({modules, Host}) of
		  undefined ->
		      ok;
		  Modules ->
		      lists:foreach(
			fun({Module, _Args}) ->
				gen_mod:stop_module(Host, Module)
			end, Modules)
	      end
      end, RemovedHosts),
    lists:foreach(
      fun(Host) ->
	      case ejabberd_config:get_local_option({modules, Host}) of
		  undefined ->
		      ok;
		  Modules ->
		      lists:foreach(
			fun({Module, Args}) ->
				gen_mod:start_module(Host, Module, Args)
			end, Modules)
	      end
      end, AddedHosts).


-- 
Magnus
JID: legoscia at jabber.cd.chalmers.se



More information about the ejabberd mailing list