ejabberd and Erlang installation with lager_transform undefined - erlang

I am new to Erlang, I have been trying to install Erlang and ejabberd on EC2 ubuntu machine, everything went well till I started compiling some external modules in ejabberd. It started throwing error undefined parse transform 'lager_transform'.
I tried everything which is as below:
Did rebar get-deps, make clean, make deps, make install. After this I am able to see that lager_transform.beam is made and present in /lib/ folder.
Checked rebar.config file, it had lager deps on top, which is widely suggested, no help even after that.
Added -compile[{parse_tranform},{lager_transform}] on top of module, even then their is no luck.
I am really blocked on this, and not able to complete the installation. I have done this before on fedora with ejabberd 15.11 and otp 18.2, at that time it was using p1_logger instead of lager. But now when I am installing fresh with otp 18.2 and ejabberd 16.0 or 15.11, I am getting lager_transform undefined error.

Please make sure you compile ejabberd as described in documentation: http://docs.ejabberd.im/admin/guide/installation/#installing-ejabberd-from-source-code
For example, you can compile it with:
./configure --enable-lager --enable-mysql
make
You need to run configure and make to set properly the build chain.

Related

How do I set up a new ejabberd server?

I'm trying to figure out how to properly setup an ejabberd project that allows for easy compilation of custom beam files- so far, we've been using an existing project that is cumbersome to manage, and uses erlide as the IDE.
I would like to set up the project in a way that I can use a more helpful IDE like vscode, and somehow streamline the compiling and copying of the beam files and updating the module on the server.
Writing code in Elixir is fine as well- I just want the project to be set up in a way that is dev friendly.
Apologies if the question is too broad, but I'm not exactly sure how else to best phrase it. If you feel like I'm missing something in my current flow, please let me know, as I've basically inherited this project. If there are any clarifications required, let me know as well.
Thanks.
easy compilation of custom beam files
somehow streamline the compiling and copying of the beam files and updating the module on the server.
If the task is about compiling and loading additional modules, a running ejabberd node can compile, load and start additional modules in runtime, see
https://docs.ejabberd.im/developer/extending-ejabberd/modules/#ejabberd-contrib
Usually the modules come from
https://github.com/processone/ejabberd-contrib
but you can tell ejabberd to download other modules from other git repositories, or you can copy modules source code and tell ejabberd to install them. And those modules can be written in Erlang or Elixir. Full example: https://docs.ejabberd.im/developer/extending-ejabberd/elixir/#elixir-module-in-ejabberd-contrib
Basically:
you write the module in your development machine, test it...
when happy with the source code, copy mod_whatever.erl to the production machine, $HOME/.ejabberd-modules/sources/mod_whatever as explained in the example mentioned earlier
run ejabberdctl module_install mod_whatever
In step 2, instead of copying the source code yourself, you can have a git repository just for your module, tell ejabberd the module's git URL, similarly to https://github.com/processone/ejabberd-contrib/tree/master/extra
BTW, for step 3, starting in ejabberd 22.10, there's a page in ejabberd webadmin to install and uninstall those modules (copying the files requires manual administration of course).
I would like to set up the project in a way that I can use a more helpful IDE like vscode
What a coincidence, these days I'm playing with VSCode variants (VSCode, VSCodium, Coder's code-server and Github Codespaces) and how to develop ejabberd using them. This is useful for step 1 that I mentioned earlier (write module and test it). If you are interested in ejabberd + VSCode, tell me.

'"erl.exe"' is not recognized as an internal or external command, operable program or batch file

'"erl.exe"' is not recognized as an internal or external command,
operable program or batch file.
Elixir and Erlang were running fine until today when I did a version update. I don't really have access to a good version manager for Elixir since I use a windows computer so I just ran the Elixir install wizard to uninstall and reinstall to update the version. I have uninstalled and reinstalled a couple of times as well as checked the elixir forum for solutions (there was 1 solution, it didn't work) for solutions. I need to get Elixir up and working pretty quickly as I am about to start on my first contract.
Instead of using
erl <'command details'>
Try to run using "./" prefix so it become
./erl <'command details'>
in the cli.
I am also using windows and have added elixir, erlang and erts paths in env. But still, it is giving me the same error. I am not getting the error. I did not update the version. My system was slow hence I deleted some files, but they were explicit. They didn't have anything to do with the elixir folder.

Load/Recompile Rebar Modules after downgrading Erlang/OTP

I wish to use an erlang client library to communicate with an mqtt broker for one of my projects. So I've started an application using rebar3's built-in templates and added emqttc as a dependency. Since erlang/otp 21 does not have support for gen_logger(emqttc depends on gen_logger) and the tuple_calls compiler options do not suffice, I had to downgrade to erlang#20 according to this post.
Now the issue with downgrading erlang is that, none of rebar3's commands(clean/compile/shell/report etc) work as expected and my previous projects built with rebar3 do not compile, I get to see this error message:
=ERROR REPORT==== 21-Aug-2018::12:54:29 === Loading of /usr/local/bin/rebar3/rebar/ebin/rebar3.beam failed: badfile escript:
exception error: undefined function rebar3:main/1 in function
escript:run/2 (escript.erl, line 759) in call from escript:start/1
(escript.erl, line 277) in call from init:start_em/1 in call from
init:do_boot/3
=ERROR REPORT==== 21-Aug-2018::12:54:29 === beam/beam_load.c(1863): Error loading module rebar3: This BEAM file was compiled for a later
version of the run-time system than 20. To fix this, please
recompile this module with an 20 compiler. (Use of opcode 160; this
emulator supports only up to 159.)
I've uninstalled and reinstalled rebar3, looked up on the web for this but nothing's clear and specific to rebar. Any help on this would be appreciated.
This may not be the exact answer for your question. But it may give you and idea.
What about using Docker. Its an easy way to keep your environment clean and neat.
If you use docker, you just have to include your new erlang version in Dockerfile as an environment variable.
ENV OTP_VERSION="20.3.6"
Check your _build/prod/rel/YOURAPPNAME/ directory. Most probably it has a release which doesn't match your erlang version. You can safely delete this directory and rebuild using rebar3 compile

Any ZMQ bindings for Erlang on Windows?

Is it possible to use Erlang with ZMQ on Windows? I have tried to use erlzmq2, but rebar fails to compile it with cryptic linker errors. Of course i can invest some time and investigate makefiles, but maybe other way exists?
Update
Whose who are interested in compilation errors can download latest erlang for windows and try to build erlzmq2 (Visual Studio 2012 compiler, msys sh and make). Error looks like:
cl : Command line error D8021 : invalid numeric argument '/Wl,-DLL,-IMPLIB:.libs
\zmq.dll.lib'
Makefile:541: recipe for target 'libzmq.la' failed
make[3]: *** [libzmq.la] Error 2
Please note that other erlang libs are compiling with this setup without any problems.
Your problem lies in compiling ZeroMQ for Windows. You haven't actually gotten to any Erlang yet. Here are some of the clues that tell you this:
Makefile:541: recipe for target 'libzmq.la' failed
This line says there's a problem on line 541 of the Makefile. But in erlzmq2, you can see that neither the main Makefile nor the c_src Makefile (which is what would build libzmq.la) has anything close to that many lines.
make3: * [libzmq.la] Error 2
The [3] means that you're 3 invocations deep into Make. Specifically, you started at the top-level Makefile, which called Rebar, which ran make -C c_src, which downloads ZeroMQ version 3.2.2 and tries to do a ./configure && make
To fix this Unix-style, go into the deps directory of erlzmq2 and figure out how to correctly compile ZeroMQ. Hopefully, you will just need to pass some arguments to configure. Then you can edit c_src/Makefile and set ZMQ_FLAGS to whatever you had to do for configure, clean, and make.
To fix it more Windows-style, follow the Windows build instructions for ZeroMQ. Put the compiled libzmq under deps and just edit the c_src Makefile to a no-op.
Finally, if you don't actually need to run this code on Windows, but are just using Windows as your development environment, I think you'll have the easiest time by running the build inside a Linux VM (not a hard thing at all with tools like Vagrant). Sorry, but Unix is the real system for this stuff; Windows support is an afterthought.

Call to i:im() in application debugger failed in ejabberd

I'm trying to debug ejabberd. I have compiled the files with debug_info. I start ejabberd, then use ejabberd debug to get into the shell. Once in there, running im() produces "Call to i:im() in application debugger failed". I can't figure out what's causing this. Any ideas on how to debug?
Edit
I've tried running this in just the erl shell independent of ejabberd and it still fails. So it looks like it's related to my erlang setup as opposed to a problem with my ejabberd setup.
Foolish me: apt-get install erlang-debugger solved the problem.

Resources