I’m writing a Rails 3 application that needs to be able to trigger modifications to unix system config files. I’d like to insulate the file modifications from the consumer side by running them in a background process. I’ve considered writing out a temp file in rails and then copying the file with a bash script but that doesn’t really insulate the system. I’ve also considered pulling from the database manually with a cron based script and updating the configs.
But what I would really like is a component that can hook into the rails environment, read out what is needed from the database, and update the config files. This process needs to be run as root because the config files mostly live in /etc/whatever.
Any suggestions?
Thanks!
My brother the network admin says you should write a Ruby/Perl/whatever script to do the actual modifications that validates the input and actually makes the modification. You could call this script from rails with. You will still want to sanitize
@parameters.System.exec("/usr/bin/sudo", ["/path/to/script"] + @parameters)As far as getting the data from the database you could either make a new SQL connection, and get the info from database.yml in rails. note data in the database should be validated since you are running as root.