Introducing the Daemons gem

The article example below is out of date however the Daemons code instructions are still relevant.

#!/usr/bin/env ruby

# file: rws_daemon.rb

require 'daemons'
require 'rscript'

Daemons.run_proc('rws') do
  code, args = RScript.new.read %w(//job:rscript_web_server http://rorbuilder.info/r/rws.rsf)
  eval code
end

I have the above code running as a daemon on my TonidoPlug using the following command: ruby1.9 rws_daemon.rb start

The next step will be to have this daemon automatically start when the TonidoPlug boots up.

Resources

update: 24-Mar-2011 @ 8:31am There's now an RSF for the above executable using the following commands:

alias rwsd="rcscript //job:rscript_web_server_daemon http://rorbuilder.info/r/rws.rsf"
rwsd start

update: 24-Mar-2011 @ 8:57am Here's the /etc/init.d/rwsd file

#!/bin/bash
#
# Written by Patrick McKenzie, 2010.
# I release this work unto the public domain.
#
# sinatra      Startup script for Sinatra server.
# description: Starts Sinatra as an unprivileged user.
#

#sudo -u www-data ruby /var/www/phone.example.com/control.rb $1
sudo -u james /home/james/.rvm/bin/rvm use ruby-1.9.2-p180 ruby /home/james/ruby/rcscript.rb //job:rscript_web_server_daemon http://rorbuilder.info/r/rws.rsf $1
RETVAL=$?

exit $RETVAL

Tags:
Source:
1432hrs.txt
Published:
24-01-2014 14:32