Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional hooks for module_install, module_uninstall #1300

Closed
iAchilles opened this issue Sep 14, 2016 · 4 comments
Closed

Additional hooks for module_install, module_uninstall #1300

iAchilles opened this issue Sep 14, 2016 · 4 comments
Assignees

Comments

@iAchilles
Copy link
Contributor

Hi guys!
Are there any ways (hooks) to run custom logic before/after module install (before/after module uninstall) ?

@cromain
Copy link
Contributor

cromain commented Sep 15, 2016

There is nothing for this now. Adding hook would be simple, but only a custom ejabberd module would catch this and run your custom logic.
I mean, this would be usefull only if you write your own module which triggers action on the hooks.

@iAchilles
Copy link
Contributor Author

@cromain
Yes, I often write custom modules for eJabberd, and it would be great if module_install calls hook handler in the module automatically :-)

For example:
src/ext_mod.erl

install(Module) when is_atom(Module) ->
    install(jlib:atom_to_binary(Module));
install(Package) when is_binary(Package) ->
    Spec = [S || {Mod, S} <- available(), jlib:atom_to_binary(Mod)==Package],
    case {Spec, installed(Package), is_contrib_allowed()} of
        {_, _, false} ->
            {error, not_allowed};
        {[], _, _} ->
            {error, not_available};
        {_, true, _} ->
            {error, conflict};
        {[Attrs], _, _} ->
            Module = jlib:binary_to_atom(Package),
            case compile_and_install(Module, Attrs) of
                ok ->
                    code:add_patha(module_ebin_dir(Module)),
                    ejabberd_config:reload_file(),

                    case erlang:function_exported(Module, post_install, 0) of
                          true ->
                               Module:post_install(); 
                          _ ->
                               ok
                     end;

                Error ->
                    delete_path(module_lib_dir(Module)),
                    Error
            end
    end.

@cromain cromain added this to the ejabberd 16.x milestone Sep 21, 2016
@cromain cromain self-assigned this Nov 28, 2016
@cromain cromain modified the milestones: ejabberd 16.12, ejabberd 16.x Nov 28, 2016
@cromain
Copy link
Contributor

cromain commented Nov 28, 2016

This is indeed a good approach. It's now committed. Thanks.

@cromain cromain closed this as completed Nov 28, 2016
@lock
Copy link

lock bot commented Jun 11, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants