Calling Ruby on Rails rake tasks through Appworx
I have a rake task “db:update_last_status”, which I need to have run on remote servers, nightly, to update cached status fields – which are used for fast search capabilities in an RoR application. The RoR application runs on Red Hat Enterprise Linux, an an Oracle database. It would be simple to script that with Cron, but that doesn’t lend itself to monitoring or work within the enterprise standards. Capistrano works great, but also isn’t within the Enterprise standards.
So… the rake task needs to be run through an Enterprise Automation System, called Appworx.
Appworx is used for running scheduled jobs on various servers, and multiple operating systems.
So far…. the Appworx config on this RHEL server entails
- Install Agent
- Configure agent
- Setup Appworx Job
- Setup authentication for application user, through Appworx
- Setup Library and Home for application user / Agent, through Appworx
- Setup Program Group for application user, for scripts to run as user
- Setup Appworx Process Flow (Chain)
- Add REGISTER_OUTPUT to Process flow
- Setup appworx folders
- Copy script to appropriate appworx folder on host,
- Modify script for running Appworx and using variables passed in buy generic cytotec.
- Modify script to detect error and return 0 or 1
# PARAMETERS: # 1. environ environ=${1} # Setup SCRIPT Vars and paths, here # set environment same as application user for RoR . /home/fis/.bashrc # script cd $fis_home RAILS_ENV=$environ rake db:update_last_status > $combined_log ln -f -s $combined_log $last_log echo $RAILS_ENV # Do error detection here. Return 1 on error # Clear old log files older that 7 days
- Configure RHEL system for sending out mail – needed for REGISTSER_OUTPUT
- Additional notes, added later
- There is a dedicated VM running this RoR application. Apache and Fusion/Passenger run as the application user. In order for the rake task to work correctly, when called through Appworx, we have Appworx run the script as that user. So, it was necessary to setup a new Appworx Program type, which runs scripts as as designated user. It was also necessary to add every script to the list of script that Appworx will run as a su-ed script.