What is the best way to accomplish system tasks from Ruby on Rails?

I am creating a small web application for system administration (I think Web-Min, but in RoR), and I need to have access to system parameters from my Ruby code. For example, I want to allow the user to change the host name, time zone, or network configuration of the server.

My current thoughts are to have a separate setuid script (Perl, Ruby, ??) so that I can call it from my RoR code, and it will take action. It is rather bulky and not very elegant. I am new to Ruby and would like to know if there is a better way to accomplish this type of thing.

Thanks!

+5
source share
4 answers

BackgrounDRb. - rails, .

+3

RailsCasts , .

, , "Rake in Background" , ? , Ruby on Rails.

root, ( ) , IP- . "Starling and Workling" "Custom Daemon" .

sudo. () , :

sudo (, hostname, ifconfig) , . . - sudo vim, , sudo vim, !bash .

( ) - rake ( ), (, ). , /usr/bin/myapp_systemtasks root:root, sudo script. , , , script ( , ).

, , - , . , , , ( )

+3

- result = %x[uptime] . , , script, sudo sudoers.

0

Starling, . , .

, , , , .

require 'starling'
starling = Starling.new('127.0.0.1:22122')
starling.set('my_queue', 12345)

Then your worker can simply delete any tasks:

require 'starling'
loop do
  starling.get('my_queue') # this will block until something gets added to the queue
  # do stuff
end
0
source

All Articles