tags:

views:

305

answers:

1

I need to run a standalone ruby script as Unix (linux) daemon.

After running that daemon I need to run another Ruby method with it.

I installed the ruby-daemon gem on my machine by using the gem install daemon.

I did the test daemon program.

My test.rb file is :

module Test
    def test_method
        @s =" ITS WORKING !"
        file=File.new("/home/username/test.txt", "w")

        file.puts @s

        file.close
    end
end

My test_control.rb file is :

# this is myserver_control.rb

  require 'rubygems'        # if you use RubyGems
  require 'daemons'

  Daemons.run('test.rb')

After this I run the following command: ruby test_control.rb start

Now how can I check whether the daemon program has started properly?

How can I invoke a method with it?

+1  A: 

Looks like the formatting on your post is way off, so hopefully someone can fix that, but I think the problem here is you're defining a module but not actually firing off the method you define.

The Daemons utility only executes the script provided. You should test that your "test.rb" file can be run on the command line directly before trying to diagnose what might be wrong with Daemons itself.

It may be as reworking test.rb:

module Test
  def self.test_method
    @s =" ITS WORKING !"
    file = File.new("/home/username/test.txt", "w")

    file.puts @s

    file.close
  end
end

Test.test_method

There are other ways to use Daemons where you pass it a module to run, but you're not using it that way.

tadman