Topic: Daemon won't start after being initialized

Ok, breaking down my earlier problem of creating a Windows service into just creating the daemon part first can anyone explain to me why this program won't even start??

I stuck a load of put commands in there for debugging and the output generated is as follows:

"run daemon"
starting
In Service Main
"state: 1"
"stopped"

Which says that when queried the state after init has run is STOPPED, why?

begin
class XmlReader < Daemon
  def service_init
    # Give the service time to get everything initialized and running,
    # before we enter the service_main function.
    #xml = REXML::Document.new(File.open("dataIn.xml"))
    puts "starting"
    sleep 5
  end

  def service_main
    puts 'In Service Main'
    fileCount = 0 # Initialize the file counter for the rename
    watchForFile = "c:\\findme.txt"
    p 'state: ' + state.to_s
   
    if state == CONTINUE_PENDING
      p 'contin pend'
    elsif state == PAUSE_PENDING
      p 'pause pend'
    elsif state == PAUSED
      p 'paused'
    elsif state == RUNNING
      p 'running'
    elsif state == START_PENDING
      p 'start pend'
    elsif state == STOP_PENDING
      p 'stop pend'
    elsif state == IDLE
      p 'idle'
    elsif state == STOPPED
      p 'stopped'
    end
   
    while running?
      if state == RUNNING
        sleep 5
        if File.exists? watchForFile
          fileCount += 1
          File.rename watchForFile, watchForFile + "." + fileCount.to_s
        end
      else
        p 'sleeping'
        sleep 0.5
      end
    end
  end

  def service_stop
    msg = "Received stop signal at: " + Time.now.to_s
  end
     
  def service_pause
   msg = "Received pause signal at: " + Time.now.to_s
  end
     
  def service_resume
    msg = "Received resume signal at: " + Time.now.to_s
  end
end

p 'run daemon'
d = XmlReader.new
d.mainloop

rescue Exception => err
  p 'ERROR ' + err
  raise
end


This is driving me crazy! lol

TIA