Search code examples
amazon-web-servicesmqttejabberdtls1.2

Ejabberd MQTT on AWS fails to launch: undefined exit with reason {'EXIT',{undef,[{mod_mqtt,socket_type,[],[]}


I follow the tutorial https://docs.ejabberd.im/admin/guide/mqtt/#enabling-mqtt-service-in-ejabberd.

Here is my config, the same as tutorial. And I also open port 1883, 8883 on AWS security group.

hosts:
  - "localhost"

listen:
  -
    port: 1883
    module: mod_mqtt
    backlog: 1000      
  -
    port: 5280
    module: ejabberd_http
    request_handlers:
       ...
       "/mqtt": mod_mqtt
  -
    port: 8883
    module: mod_mqtt
    backlog: 1000
    tls: true

# adapt the path to your own certfile    
certfiles:
  - "/var/snap/ejabberd/tls/mqtt.pem"

modules:
...
  mod_mqtt: {}

However ejabberd fails to launch, throwing the errors below:

2020-03-29 21:30:59.416 [error] <0.299.0> Supervisor ejabberd_listener had child 
{1883,{0,0,0,0},tcp} started with ejabberd_listener:start({1883,{0,0,0,0},tcp}, 
mod_mqtt, [{backlog,1000}]) at undefined exit with reason {'EXIT',{undef,
[{mod_mqtt,socket_type,[],[]},{ejabberd_listener,start,3,[{file,
"src/ejabberd_listener.erl"},{line,86}]},{supervisor,do_start_child,2,[{file,
"supervisor.erl"},{line,358}]},{supervisor,start_children,3,[{file,
"supervisor.erl"},{line,341}]},{supervisor,init_children,2,[{file,
"supervisor.erl"},{line,307}]},{gen_server,init_it,6,[{file,"gen_server.erl"},
{line,328}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,240}]}]}} 
in context start_error

and

2020-03-29 21:29:31.371 [error] <0.38.0>@ejabberd_config:validate_opts:1022 
unknown option 'certfiles' will be likely ignored

Solution

  • {undef, [{mod_mqtt,socket_type,[],[]},

    This means that erlang couldn't find the file mod_mqtt.beam... or maybe the file was found, but it didn't include the definition of the function socket_type/0. That module with that function was added in ejabberd 19.02: https://github.com/processone/ejabberd/commit/a3df791373c30ccc79a6082f4c910a378d726cdc

    So, maybe you installed an older version, or it is wrongly installed and lacks that module.

    unknown option 'certfiles' will be likely ignored

    The option certfiles was adde in ejabberd 17.11, so I don't understand how a recent ejabberd can complain that it is unknown:

    https://github.com/processone/ejabberd/commit/35b7203e01aefbdfe4ea7804ebe20a8667466628