From: Rogue Amateur Date: 2006-07-14T04:50:14+09:00 Subject: Re: Nuby Q: Daemonize (other materials have been read!) unknown wrote: > On Fri, 14 Jul 2006, Rogue Amateur wrote: > >> >> So, this works. So does another, innocuous script I wrote. I even >> checked out the daemonize library the other person suggested, and it >> works too. My pain in the butt actually need it to work as a daemon, >> however, does not work. >> >> What could cause code which works in interactive mode to fail in daemon >> mode? >> >> I'm checking the code now, and I do have "if debug" statements which >> output to STDOUT. Could that be the problem? > > only unless you need them to go somewhere - the code i sent has them > going to > /dev/null. > >> I'm adding some blurbs to try to get the stupid thing to tell me, but it >> seems to die so silently (eg: nothing in syslog, which is where most >> messages are expected to go), that I can't get enough information. >> >> I know it manages to send the "shut down the listener" message, which is >> a "rescue" action. > > well - then it must be throwing an error right? post you code and i'm > sure > someone will spot the error. > >> Hints, suggestions and other comments? > > wrap your script with this > > begin > > # > # your entire script > # > > rescue Exception => e > require 'tmpdir' > > tmp = Dir.tmpdir > this = File.basename $0 > pid = Process.pid > > deathlog = File.join tmp, "#{ this }.#{ pid }" > > m, c, b = e.message, e.class, e.backtrace.join("\n") > > msg = "%s (%s)\n%s" % [m, c, b] > > open(deathlog, "w"){|f| f.puts msg} > end > > after it runs do an > > ls -ltar /tmp > > there should should find a record of the failure. > > > regards. > > > -a I'd love to post the code, but I can't - it's proprietary. If I can rewrite it so that I cna post it, I will do so tonight. Basically, I'll have to rewrite it, and verify that the rewrite has the same problem. truely odd things are happening: daemon.rb my_code.rb > with your Exception recue clause returned nothing. Executes Listener stop. ruby daemon.rb my_code.rb > with the exception clause returns nothing. However, it doesn't execute the Listener stop either. (using daemonize inside the code) my_code.rb > with exception clause returns 2 files (1503 and 1502, both of which say: exit (SystemExit) /usr/lib/site_ruby/1.8/daemonize.rb:26:in `exit' /usr/lib/site_ruby/1.8/daemonize.rb:26:in `daemonize' ./my_code.rb:621 **** repeat the run, and new files are not created. I'm not seeing any errors logged to syslog, or my verbose log. ONCE, I seemed to get it to work. I ran it as a plain run in a redirect to /dev/null, and then killed the window. It killed that process, but didn't kill the listener. Then, I ran it with "ruby daemon.rb my_code.rb" (no daemonize inside the code)., and it worked, and ran through to completion. I have not been able to do that again! will work on rewriting tonight, and posting. apologies for the stupidity. RA -- Posted via http://www.ruby-forum.com/.