Saturday, March 15, 2014

Egtm (GTM support for Erlang) using UTF-8 chset

If you've already seen this line, you know how this one can be frustrating :)
EGTM Common Error: egtm: 150373066,call^%egtmapi,%GTM-E-INVOBJ, Cannot ZLINK object file due to unexpected format,%GTM-I-TEXT, Object compiled with CHSET=UTF-8 which is different from $ZCHSET

Fighting with GTM to have the UTF8 routines of EGTM, I've finally won the round !
Here's my strategy: in rebar.config add the UTF-8 line ( and set the correct path for your gtm_dist:
{port_envs, [
  %% GT.M flags
  {".*", "gtm_dist", "/opt/application/lib/fis-gtm/V6.0-003_x86_64/utf8"},
  {".*", "gtm_chset", "UTF-8"},
  {".*", "LDFLAGS", "$LDFLAGS -I$gtm_dist -L$gtm_dist -Wl,-rpath -Wl,$gtm_dist -lgtmshr -lc"}
]}.
Then remove the 'egtm_worker.so' from the src directory, and finally recompile:
./rebar comp

Monday, September 3, 2012

Easy ejabberd clustering procedure

I was fed up with lack of easy ways to connect multiple ejabberd together. The documentation contains what you need but because of not so friendly command lines, I was never satisfied by the procedure.

So I've added a simple command "attach" to "ejabberdctl" that speed up the procedure, basically it uses already defined vars from the script:


    $EXEC_CMD "$ERL \
      $NAME $ERLANG_NODE \
      -mnesia dir \"\\\"$SPOOLDIR\\\"\" \
        -mnesia extra_db_nodes \"[$MASTER]\" \
      -s mnesia"

}
Apply this patch, and enjoy the "attach" command:
=== modified file 'src/ejabberdctl.template'
--- src/ejabberdctl.template    2012-08-02 14:39:16 +0000
+++ src/ejabberdctl.template    2012-08-31 09:06:56 +0000
@@ -364,13 +364,63 @@
         status=0
     }
     return $status
+}
+
+attach ()
+{
+
+RUNAS=${INSTALLUSER-root}
+
+cat <<END
+- Attaching Procedure - (running as '$RUNAS')
+
+You're about to initialise this local mnesia with another running instance.
+Data will be written to '$SPOOLDIR'
+
+First, determine which node do you want to use as master, and answer the question.
+
+Now, once you're in the erlang shell, type:
+mnesia:info().
+
+Look at the line that starts with: "running db nodes", and observe that your node
+is listed.
+
+Then type the following:
+mnesia:change_table_copy_type(schema, node(), disc_copies).
+
+You'll normally get: "{atomic,ok}"
+
+You can now close the shell using:
+q().
+
+You can start ejabberd now, and observe this new node in the webadmin...
+END
+
+echo -n "Specify which master do you want to use (ex: ejabberd@node02): "
+read MASTER
+
+        if [[ -n $MASTER ]]
+        then
+
+    $EXEC_CMD "$ERL \
+      $NAME $ERLANG_NODE \
+      -mnesia dir \"\\\"$SPOOLDIR\\\"\" \
+        -mnesia extra_db_nodes \"[$MASTER]\" \
+      -s mnesia"
+
+        else
+                echo
+
+        fi
 }

+
 case $ARGS in
     ' start') start;;
     ' debug') debug;;
     ' live') live;;
     ' started') wait_for_status 0 30 2;; # wait 30x2s before timeout
     ' stopped') wait_for_status 3 15 2; stop_epmd;; # wait 15x2s before timeout
+    ' attach') attach;;
     *) ctl $ARGS;;
 esac



Ejabberd cluster connection problem using mnesia ?

If you try to connect two ejabberd servers and still can't get the job done because mnesia seems to be blind, check out the content of the file "ejabberdctl.cfg". By default ejabberd vm don't accept network connections ...
#.
#' INET_DIST_INTERFACE: IP address where this Erlang node listens other nodes
#
# This communication is used by ejabberdctl command line tool,
# and in a cluster of several ejabberd nodes.
# Notice that the IP address must be specified in the Erlang syntax.
#
# Default: {127,0,0,1}

INET_DIST_INTERFACE={0,0,0,0}
Fix your file like the code above and retry...

Configuring ejabberd for BOSH using a specific url

Put this inside the "listen" part:
  {5280, ejabberd_http, [
                         {request_handlers,
                                [
                                        {["boshurl"], mod_http_bind}
                                ]
                        },
                         http_bind,
                         web_admin
                        ]}

Reload ejabberd, and connect to "yourdomain:5280/boshurl" and enjoy :)

Wednesday, October 12, 2011

"Pseudo Randomly" retrieve data...

When you want to crawl some websites and you want to hide yourself a little, here's a simple trick to change randomly your user-agent string.
There's a very convenient function in erlang called 'uniform' from the module 'random', you can use it by calling 'random:uniform(MaxValue)' where MaxValue is the high limit.

So if you want to generate a random value from 1 to 5 you can simple use, 'random:uniform(5)'...

Now that you know how to generate random values, here's some code that do just what's the title say:

Sticky