I don’t usually waste my time on java, but today I was in the right mood and tried to write a very simple network daemon, just to learn how hard it was. After some quick google I found that java can’t daemonize itself (it has no access to relevant native system calls) and therefore the Apache guys developed a nice component called org.apache.commons.daemon. I though Apache guys are smart, after all they developed the Apache web server, Subversion and more interesting stuff, so they have to know very well how a network daemon works. So I happily started with the test app, SimpleDaemon, bundled in the commons tar file, just to prove it works.
Unfortunately at the 1st attempt I got:
pioppo@roentgen ~/sandbox/daemon $ jsvc -verbose SimpleDaemon.class SimpleDaemon
24/12/2006 00:32:53 32525 jsvc error: Cannot execute JSVC executor process
Gosh, what is this?
Ok ok, some more googling and I found jsvc is using execve(2) on itself but doesn’t canonicalize the filename so execve fails. To workaround the problem you have to invoke jsvc as an absolute path:
pioppo@roentgen ~/sandbox/daemon $ /usr/bin/jsvc -verbose SimpleDaemon.class SimpleDaemon
pioppo@roentgen ~/sandbox/daemon $
On second attempt I get no errors, but it’s not running. Well, not very verbose either. I know my stuff, so I try debugging with strace and I find jsvc is failing opening the pidfile in /var/run/jsvc.pid but it’s not nice enough to tell me. Ok, let’s try again forcing log file creation and a pid file in the current dir:
pioppo@roentgen ~/sandbox/daemon $ /usr/bin/jsvc -pidfile ./sd.pid -errfile ./err.log SimpleDaemon.class SimpleDaemon
pioppo@roentgen ~/sandbox/daemon $
This time the err.log file has been created and I can read this nice report:
24/12/2006 00:42:58 31709 jsvc.exec error: syscall failed in set_caps
24/12/2006 00:42:58 31709 jsvc.exec error: set_caps(CAPS) failed
24/12/2006 00:42:58 31708 jsvc.exec error: Service exit with a return value of 4
Gosh, this is driving me crazy. Wasn’t this supposed to be a piece of cake? Ok, some more googling and I find this happens in case I have no capability kernel module loaded. OK OK, let’s modprobe capability and try again:
24/12/2006 00:51:28 32407 jsvc.exec error: Cannot find daemon loader org/apache/commons/daemon/support/DaemonLoader
24/12/2006 00:51:28 32406 jsvc.exec error: Service exit with a return value of 1
$&$&&^ what the hell is this, a candid camera? After more googling I find this happens because I forgot to add the path to the jar file for commons. Eventually I find a way to run this test daemon that is supposed to do nothing, just an Hello World app. I look it up in top and I see it spawned 10 threads and is taking 368M of virtual mem. Ok, now I know why I don’t usually waste my time on java
Hey!!
I just wanted to wish you a very merry Christmas and happy new year!! Have a great time on the beach!! I agree with you about Christmas and snow, but I guess thanks for global warming, there is no snow in Canada for Santa! Your picture of the golden rain is amazing! how I love Christmas lights!!
Enjoy your holidays!
Jessica (from Canada in case you forgot! hahah)
Merry merry merry Christmas Jess! So thanks to global warming next year you’re gonna spend your xmas on the beach of Ontario lake?