[Klone-users] hooks

Stefano Barbato barbato at koanlogic.com
Thu Sep 11 08:12:22 EDT 2008


Hi,

are you using -d to start the klone daemon? did you set iterative mode  
in the config file?

This is an example I just tried-out:

http://koanlogic.com/download/klone/klone-hooks-example.tar.gz

unpack, run 'make' and './kloned'; your log file should look like this:

Sep 11 14:07:54 mbp ./kloned[49996]: [inf][49996:::] hooks_setup
Sep 11 14:07:54 mbp ./kloned[49996]: [wrn][49996:klog.c: 
461:klog_args_check] threshold unspecified: assuming lowest possible  
(DEBUG)
Sep 11 14:07:54 mbp Unknown[49996]: [wrn][49996:broker.c: 
105:broker_create] CGI support disabled, use --enable_cgi to enable it
Sep 11 14:07:54 mbp Unknown[49996]: [wrn][49996:broker.c: 
112:broker_create] File system support disabled, use --enable_fs to  
enable it
Sep 11 14:07:54 mbp Unknown[49997]: [inf][49997:::] child_init
Sep 11 14:07:55 mbp Unknown[50007]: [inf][50007:::] child_init

bye,
s


On 11/set/08, at 12:24, Oleg Kobyakovskiy wrote:

> Hello Tomas,
>
> thank you very much for help, but still not working.
> I put hooks function into .kl1 file.
> Got your code for connection to DB (using PostgreSQL).
> I'm using Klone 2.1.0.
> My top-level Makefile is:
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> -include Makefile.conf
> KLONE_VERSION ?= 2.1.0
> KLONE_CONF_ARGS ?=      \
>     --prefix=$(DESTDIR) \
>     --enable_hooks \
>     --libs=$(DESTDIR)
> WEBAPP_CFLAGS ?= -I$(KLONE_APP_TOP) -I$(KLONE_SRC)
> WEBAPP_LDADD ?=
> WEBAPP_LDFLAGS ?=  -lpq
> -include build/mk/klone-app.mk
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> As you can see I've added enable_hooks key to Makefile (I did it for  
> configure step before and have error).
> Also I've changed your code for PQsetdbLogin as:
> dbg_err_ifm ((pg_conn = PQsetdbLogin(...))) == NULL,"connection  
> error: setdbLogin");
> And didn't see the message in logs,
> Then I've added 2 rows in .kl1 to see if this function run:
>
>    info ("Before login");
>    dbg_err_ifm (1,"Before login");
>
> But see nothing like this in logs.
> Only what I see in logs is:
> Sep 11 13:17:25 ok : [wrn][13597:broker.c:105:broker_create] CGI  
> support disabled, use --enable_cgi to enable it
> Sep 11 13:17:25 ok : [wrn][13597:broker.c:112:broker_create] File  
> system support disabled, use --enable_fs to enable it
>
> So I think hooks are not wokring for me. Somewhere I'm wrong, but I  
> don not know where.
>
> My .kl1 file is:
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> <%!
> #include <klone/klone.h>
> #include <postgresql/libpq-fe.h>
> #include <u/libu.h>
>
> PGconn     *pg_conn;
> PGresult   *res;
>
> int pg_connect(void) {
>    // e.g. connect to postgres DB
>
>    info ("Before login");
>    dbg_err_ifm (1,"Before login");
>    dbg_err_ifm ((pg_conn = PQsetdbLogin(...)) == NULL,"connection  
> error: setdbLogin");
>
>    dbg_err_ifm (PQstatus(pg_conn) != CONNECTION_OK,
>        "connection error: %s", PQerrorMessage(pg_conn));
>
>    info("pg (%s:%s) connected on socket %d", PQhost(pg_conn),  
> PQport(pg_conn),
>        PQsocket(pg_conn));
>
>    return 0;
> err:
>    return ~0;
> }
>
> int child_init(void)
> {
>         /* a new child has been forked, tear-up the always on DB  
> connection */
>         pg_connect();
>         return 0;
> }
>
> int child_term(void) {
>         PQfinish(pg_conn);
>         return 0;
> }
>
> void hooks_setup(void)
> {
>         /* set hooks */
>         hook_child_init( child_init );
>         hook_child_term( child_term );
> }
> %>
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> And it's placed in webapp/www/
>
> Any ideas?
>
> Thanks a lot,
> Oleg.
>
>
> On Thu, Sep 11, 2008 at 1:12 AM, thomas fossati <tho at koanlogic.com>  
> wrote:
> Hi Oleg,
>
>
> On Sep 10, 2008, at 10:26 PM, Oleg Kobyakovskiy wrote:
> reading  manual about hooks and see next:
> "Developers can let Klone call their own functions on interesting  
> events (see below). To enable this functionality Klone must be  
> configured with –enable_hooks. When compiled this way Klone will  
> call hooks_setup() to gived the user the opportunity to register his  
> hooks."
> So I tried to configure klone with --enable_hooks flag. But got this  
> error:
>
> [err] Failed command: 'enable_hooks'!
>
> which klone version are you using ?
>
> Could you please provide your top-level Makefile ?
>
>
> I'd like to make the connection to DB in child_init process.
> Looks like I don't connect there. How can I see is it connected or  
> not?
>
> 1) write the code that handles DB connection setup:
>
> int your_db_init_func(void)
> {
>    // e.g. connect to postgres DB
>
>    dbg_err_if (PQsetdbLogin(...) == NULL);
>
>    dbg_err_ifm (PQstatus(...) != CONNECTION_OK,
>        "connection error: %s", PQerrorMessage(...));
>
>    info("pg (%s:%s) connected on socket %d", PQhost(...), PQport(...),
>        PQsocket(...));
>
>    return 0;
> err:
>    return ~0;
> }
>
> 2) provide a lib with an hooks_setup() function:
>
> void hooks_setup(void)
> {
>    (void) hook_child_init(your_db_init_func);
>    // perhaps other hooks (e.g. db connection teardown, ...)
>    return;
> }
>
> and let it link to the kloned executable by adding the path of the  
> lib via WEBAPP_LDADD.
>
> See http://www.koanlogic.com/download/klone/klapp-auth-simple-1.2.0.tar.gz 
>  - expecially auth-hooks/auth_hooks.c and Makefile - as a starting  
> point.
>
>
> Also in some examples I found something like dbg_err_if.
> What is it and where can I foud info about error debuging?
>
> dbg_xxx_if comes from libu's carpal module: please see http://wiki.koanlogic.com/doku.php?id=libu_carpal 
>  for an overview.
>
> Basically when you configure your klapp with --enable_debug, a log  
> message with priority DEBUG is routed through syslog (*) in case a  
> dbg_xxx_if assertion fails.  Note that "carpals" with log level >  
> debug are always logged (even if --enable_debug is not specified).
>
> (*) In your kloned.conf add something like:
>
> log
> {
>    type syslog
>    syslog.facility LOG_LOCAL7
> }
>
> and make sure your /etc/syslog.conf has a line like:
>
> local7.*    /var/log/kloned.conf
>
> Hope it helps, t.
>
>
> _______________________________________________
> Klone-users mailing list
> Klone-users at koanlogic.com
> http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users
>
> _______________________________________________
> Klone-users mailing list
> Klone-users at koanlogic.com
> http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users





More information about the klone-users mailing list