<div dir="ltr">Hello Stefano,<br><br>thanks for help.<br>1) I used -F -d. No child init events<br>2) I used -F. got child init events<br><br>And now I have next question.<br>I can see init event but do not see term event.<br>
I think the kloned have to be finished different way (not by "killall kloned"), but I didn't found what is correct yet.<br>Did you see "child_term" on finish?<br><br>Thanks,<br>Oleg.<br><br><br><br>
<div class="gmail_quote">On Thu, Sep 11, 2008 at 3:12 PM, Stefano Barbato <span dir="ltr"><<a href="mailto:barbato@koanlogic.com">barbato@koanlogic.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
are you using -d to start the klone daemon? did you set iterative mode in the config file?<br>
<br>
This is an example I just tried-out:<br>
<br>
<a href="http://koanlogic.com/download/klone/klone-hooks-example.tar.gz" target="_blank">http://koanlogic.com/download/klone/klone-hooks-example.tar.gz</a><br>
<br>
unpack, run 'make' and './kloned'; your log file should look like this:<br>
<br>
Sep 11 14:07:54 mbp ./kloned[49996]: [inf][49996:::] hooks_setup<br>
Sep 11 14:07:54 mbp ./kloned[49996]: [wrn][49996:klog.c:461:klog_args_check] threshold unspecified: assuming lowest possible (DEBUG)<br>
Sep 11 14:07:54 mbp Unknown[49996]: [wrn][49996:broker.c:105:broker_create] CGI support disabled, use --enable_cgi to enable it<br>
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<br>
Sep 11 14:07:54 mbp Unknown[49997]: [inf][49997:::] child_init<br>
Sep 11 14:07:55 mbp Unknown[50007]: [inf][50007:::] child_init<br>
<br>
bye,<br><font color="#888888">
s</font><div><div></div><div class="Wj3C7c"><br>
<br>
<br>
On 11/set/08, at 12:24, Oleg Kobyakovskiy wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello Tomas,<br>
<br>
thank you very much for help, but still not working.<br>
I put hooks function into .kl1 file.<br>
Got your code for connection to DB (using PostgreSQL).<br>
I'm using Klone <a href="http://2.1.0." target="_blank">2.1.0.</a><br>
My top-level Makefile is:<br>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-<br>
-include Makefile.conf<br>
KLONE_VERSION ?= 2.1.0<br>
KLONE_CONF_ARGS ?= \<br>
--prefix=$(DESTDIR) \<br>
--enable_hooks \<br>
--libs=$(DESTDIR)<br>
WEBAPP_CFLAGS ?= -I$(KLONE_APP_TOP) -I$(KLONE_SRC)<br>
WEBAPP_LDADD ?=<br>
WEBAPP_LDFLAGS ?= -lpq<br>
-include build/mk/<a href="http://klone-app.mk" target="_blank">klone-app.mk</a><br>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-<br>
As you can see I've added enable_hooks key to Makefile (I did it for configure step before and have error).<br>
Also I've changed your code for PQsetdbLogin as:<br>
dbg_err_ifm ((pg_conn = PQsetdbLogin(...))) == NULL,"connection error: setdbLogin");<br>
And didn't see the message in logs,<br>
Then I've added 2 rows in .kl1 to see if this function run:<br>
<br>
info ("Before login");<br>
dbg_err_ifm (1,"Before login");<br>
<br>
But see nothing like this in logs.<br>
Only what I see in logs is:<br>
Sep 11 13:17:25 ok : [wrn][13597:broker.c:105:broker_create] CGI support disabled, use --enable_cgi to enable it<br>
Sep 11 13:17:25 ok : [wrn][13597:broker.c:112:broker_create] File system support disabled, use --enable_fs to enable it<br>
<br>
So I think hooks are not wokring for me. Somewhere I'm wrong, but I don not know where.<br>
<br>
My .kl1 file is:<br>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-<br>
<%!<br>
#include <klone/klone.h><br>
#include <postgresql/libpq-fe.h><br>
#include <u/libu.h><br>
<br>
PGconn *pg_conn;<br>
PGresult *res;<br>
<br>
int pg_connect(void) {<br>
// e.g. connect to postgres DB<br>
<br>
info ("Before login");<br>
dbg_err_ifm (1,"Before login");<br>
dbg_err_ifm ((pg_conn = PQsetdbLogin(...)) == NULL,"connection error: setdbLogin");<br>
<br>
dbg_err_ifm (PQstatus(pg_conn) != CONNECTION_OK,<br>
"connection error: %s", PQerrorMessage(pg_conn));<br>
<br>
info("pg (%s:%s) connected on socket %d", PQhost(pg_conn), PQport(pg_conn),<br>
PQsocket(pg_conn));<br>
<br>
return 0;<br>
err:<br>
return ~0;<br>
}<br>
<br>
int child_init(void)<br>
{<br>
/* a new child has been forked, tear-up the always on DB connection */<br>
pg_connect();<br>
return 0;<br>
}<br>
<br>
int child_term(void) {<br>
PQfinish(pg_conn);<br>
return 0;<br>
}<br>
<br>
void hooks_setup(void)<br>
{<br>
/* set hooks */<br>
hook_child_init( child_init );<br>
hook_child_term( child_term );<br>
}<br>
%><br>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-<br>
And it's placed in webapp/www/<br>
<br>
Any ideas?<br>
<br>
Thanks a lot,<br>
Oleg.<br>
<br>
<br>
On Thu, Sep 11, 2008 at 1:12 AM, thomas fossati <<a href="mailto:tho@koanlogic.com" target="_blank">tho@koanlogic.com</a>> wrote:<br>
Hi Oleg,<br>
<br>
<br>
On Sep 10, 2008, at 10:26 PM, Oleg Kobyakovskiy wrote:<br>
reading manual about hooks and see next:<br>
"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."<br>
So I tried to configure klone with --enable_hooks flag. But got this error:<br>
<br>
[err] Failed command: 'enable_hooks'!<br>
<br>
which klone version are you using ?<br>
<br>
Could you please provide your top-level Makefile ?<br>
<br>
<br>
I'd like to make the connection to DB in child_init process.<br>
Looks like I don't connect there. How can I see is it connected or not?<br>
<br>
1) write the code that handles DB connection setup:<br>
<br>
int your_db_init_func(void)<br>
{<br>
// e.g. connect to postgres DB<br>
<br>
dbg_err_if (PQsetdbLogin(...) == NULL);<br>
<br>
dbg_err_ifm (PQstatus(...) != CONNECTION_OK,<br>
"connection error: %s", PQerrorMessage(...));<br>
<br>
info("pg (%s:%s) connected on socket %d", PQhost(...), PQport(...),<br>
PQsocket(...));<br>
<br>
return 0;<br>
err:<br>
return ~0;<br>
}<br>
<br>
2) provide a lib with an hooks_setup() function:<br>
<br>
void hooks_setup(void)<br>
{<br>
(void) hook_child_init(your_db_init_func);<br>
// perhaps other hooks (e.g. db connection teardown, ...)<br>
return;<br>
}<br>
<br>
and let it link to the kloned executable by adding the path of the lib via WEBAPP_LDADD.<br>
<br>
See <a href="http://www.koanlogic.com/download/klone/klapp-auth-simple-1.2.0.tar.gz" target="_blank">http://www.koanlogic.com/download/klone/klapp-auth-simple-1.2.0.tar.gz</a> - expecially auth-hooks/auth_hooks.c and Makefile - as a starting point.<br>
<br>
<br>
Also in some examples I found something like dbg_err_if.<br>
What is it and where can I foud info about error debuging?<br>
<br>
dbg_xxx_if comes from libu's carpal module: please see <a href="http://wiki.koanlogic.com/doku.php?id=libu_carpal" target="_blank">http://wiki.koanlogic.com/doku.php?id=libu_carpal</a> for an overview.<br>
<br>
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).<br>
<br>
(*) In your kloned.conf add something like:<br>
<br>
log<br>
{<br>
type syslog<br>
syslog.facility LOG_LOCAL7<br>
}<br>
<br>
and make sure your /etc/syslog.conf has a line like:<br>
<br>
local7.* /var/log/kloned.conf<br>
<br>
Hope it helps, t.<br>
<br>
<br>
_______________________________________________<br>
Klone-users mailing list<br>
<a href="mailto:Klone-users@koanlogic.com" target="_blank">Klone-users@koanlogic.com</a><br>
<a href="http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users" target="_blank">http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users</a><br>
<br>
_______________________________________________<br>
Klone-users mailing list<br>
<a href="mailto:Klone-users@koanlogic.com" target="_blank">Klone-users@koanlogic.com</a><br>
<a href="http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users" target="_blank">http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users</a><br>
</blockquote>
<br>
<br>
_______________________________________________<br>
Klone-users mailing list<br>
<a href="mailto:Klone-users@koanlogic.com" target="_blank">Klone-users@koanlogic.com</a><br>
<a href="http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users" target="_blank">http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users</a><br>
</div></div></blockquote></div><br></div>