Writing Ruby Daemons

We got some bash scripts running via a cronjob to set permissions of certain directories. To improve this process I wrote a very simple ruby daemon process to handle this.

First I installed the daemons gem (#gem install daemons), next I created the following:

#control.rb
require ‘rubygems’
require ‘daemons’

Daemons.run(’permissions.rb’)

———————————————————————-
#permissions.rb
loop do
system(’<some unix commands’>
system(’<some unix commands’>
sleep 15
end

As you can see, I use the standard unix tools by invoking the system(”) command. I am still trying to find out if it would be benefitial to use File.chmod and File.chown from the fileutils package.

3 Responses to “Writing Ruby Daemons”

  1. Diva #2 Says:

    Hi Sander,

    Did you know that NetBeans IDE 6.0 will have Ruby support. Gails and I moved over to Ruby recently. Its pretty cool.

  2. sander Says:

    Hi Chris,

    Thanks for your comment. I’ve seen some posts about ruby and NetBeans. However till now I have been using Ruby mainly as a replacement for standard bash scripts.

    For example, I wrote a view scripts that automatically installs our CMS software onto a clients website (Copying files, loading mysql db’s, setting permissions and file ownership etc.). However I have not been using Ruby Rails or Jruby yet and all my scripts are written in unix vi and run on the cli :)

  3. Fred Mitchell Says:

    Thanks for this — Daemons has worked out well in an application I am writing.

Leave a Reply