[Klone-users] hooks

Oleg Kobyakovskiy ok at dev.speedflow.com
Thu Sep 11 09:38:58 EDT 2008


Hi Stefano,

Got it.

Thanks a lot.
Oleg.

On Thu, Sep 11, 2008 at 4:08 PM, Stefano Barbato <barbato at koanlogic.com>wrote:

> Hi Oleg,
>
> KLone creates and kills processes based on its own policies (for example if
> a client request it very slow klone will spawn a new process to handle other
> incoming connections).
>
> So when KLone, by itself, kills its subprocesses it will call child_term;
> if *you* kill KLone with a signal it will not call child_term (but will call
> server_term hook).
>
> s
>
>
>
>
> On 11/set/08, at 14:47, Oleg Kobyakovskiy wrote:
>
>  Hello Stefano,
>>
>> thanks for help.
>> 1) I used -F -d. No child init events
>> 2) I used -F. got child init events
>>
>> And now I have next question.
>> I can see init event but do not see term event.
>> I think the kloned have to be finished different way (not by "killall
>> kloned"), but I didn't found what is correct yet.
>> Did you see "child_term" on finish?
>>
>> Thanks,
>> Oleg.
>>
>>
>>
>> On Thu, Sep 11, 2008 at 3:12 PM, Stefano Barbato <barbato at koanlogic.com>
>> wrote:
>> 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
>>
>>
>> _______________________________________________
>> 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
>>
>
>
> _______________________________________________
> Klone-users mailing list
> Klone-users at koanlogic.com
> http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://koanlogic.com/pipermail/klone-users/attachments/20080911/f7f2f11a/attachment.html


More information about the Klone-users mailing list