Ruby On Rails - Dennis Henry

Transcription

Ruby on RailsMatt Dees

All trademarks used herein are the sole property of theirrespective owners.

IntroductionHow Ruby on Rails WorkscPanel's interaction with Ruby on RailsAdministrating Ruby on RailsTroubleshooting Ruby on Rails

What is Ruby on Rails?A Web Application Framework aimed towards the rapiddevelopment and deployment of Dynamic Web 2.0Applications

Interpreted Programming LanguageWeb Applications are done through either Rails or asa straight CGI applicationEvery part of the Ruby on Rails system is dependenton ruby working correctly

GemsGems are Ruby modulesEither compiled or interpreted Ruby codeGems can be full applications or libraries for RubyprogramsManaged by the “gem” command

RailsRails is a framework for creating Ruby applications andprovides several different pieces of functionalityRails exists for multiple programming languagesIs a gemConsists of several gems used for handling differentfunctionsDifferent versions of this exist, each applicationrequires a specific version

Rails ContinuedAction Record – Rapid development library forbuilding daemon independent database queriesAction Pack – An implementation of Model ViewController for Ruby.Action Mailer – An Email HandlerWebserver – Usually webrick, however we usemongrel

MongrelMongrel is the Web Server used for serving Ruby onRails applicationsOne instance per Ruby applicationOther daemons exist, but mongrel has the bestsecurity and performance recordIs a gemRuns applications on port 12001 and up on cPanelUses a significant amount of memory

cPanel and Ruby on RailscPanel provides an interface for managing Ruby onRails applications inside of each user's cPanelCan be enabled/disabled via the feature manager inWHMNumber of Ruby applications a user is allowed canbe modified via “Modify an Account” in WHM with the“Max Mongrels” optionThis number should be limited as ruby uses it's ownwebserver for each application that uses memory

The WHM/cPanel Interface

What cPanel Does with RoRWhen cPanel creates this application, it runs“rails /path/to/application”The information for the application is stored in /.cpanel/ruby-on-rails.dbA mongrel process is executed when “run” is hiteach user has their own set of ruby binaries, librariesand gems in /ruby/

Rails and the ShellRuby on Rails is designed for each application to beadministered from the shellNearly all applications assume shell access to thehosting serverThe Rakefile is used to deploy rails application, thiswill automatically setup databases and many otherportions of an application, this is accessed using the“rake” command

How Apache Interacts with RoRApache interacts with Ruby on Rails by settings upRewritesUses mod rewrite in /public html/.htaccessstored in /.cpanel/ruby-on-railsrewrites.dbYou can only redirect the main domain, subdomainor addon domain to a ruby on rails application.

Rewrite Interface

Rewrite Creation Interface

cPanel and GemsThere are three methods of installing gems on a cPanelsystem, either via WHM, cPanel or the CLIThe CLI is the recommended methodWhen installed through cPanel, they are installed to /ruby/gemsWhen installed through WHM or the CLI they areinstalled globally to /usr/lib/ruby

cPanel Gem Interface

gem CLIThe gem CLI allows you to install, troubleshoot andperform maintenance on Ruby modulesSimilar to cpan and pearGems are installed to /usr/lib/ruby/gems/1.8/gemsFor users, they need to run either /scripts/gemwrapper or /ruby/bin/gem

gem CLI (cont.)!gem listThis will list all of the gems currently installed onyour servergem list --remotewill list all gems available from http://gems.rubyforge.org/

gem CLI (cont.)!gem install gemname Installs a gemCan be specified with -v for a specific version of agem (such as rails)useful for testing errors with our gem installationmethod

gem CLI (cont.)!gem check –specification gemname This will allow you to see what files a module willinstall, what dependencies it has and generalinformation on the gemgem check –alien gemname Security check, will check for any abnormal filesinside of the module's basegem check –verify filename Checks the MD5sum of a file from a module versusthe repository

gems without the gem commandRuby modules can be downloaded from http://gem.rubyforge.org. This allows gems to be installedeven if the gem CLI is not workingYou will need to untar the package, chdir into thedirectory, then run “ruby setup.rb”

Logs For Application StartupIssues/usr/local/cpanel/logs/error logThis will show any issues with executing the mongrelprocess itself APPBASE /log/mongrel.logThis will show any issues with mongrel failing to loadgems, 90% of failed starts will be contained here

Logs For Application Errors APPBASE /log/(production development).logThese logs will show any errors that the applicationhas while executing.If your user is complaining about an applicationacting funny, it will probably be heremost issues inside of these logs indicate applicationside errors that cannot be fixed at the server level.

Application Startup IssuesThe best way to check application startup issues is toexecute the application manually with the followingcommand:chdir APPBASE && sudo -u USERNAME /usr/bin/ruby /usr/bin/mongrel railsstart -p port -d -e production -Plog/mongrel.pidThis will execute the mongrel instance on it's own,outside of cPanel making process tracing simple

Gem Installation IssuesOur gem installer is executed via /scripts/gemwrapper,which initializes some environment variables into gemthat make it work with our homedir setup. We alsouse a cache file located at: /.cpanel/datastore/scripts gemwrapper --noexpect list -remoteto store a list of these gems, if this file exists but doesnot contain a list of gems, remove it and refresh thepage

Gem Installation Issues (cont)!There are a few other things that should be checked forgem installation errorsDoes the user have compiler access?Can the user write to their own /ruby/ directory?User Quota?

Question&Answer

Apache interacts with Ruby on Rails by settings up Rewrites Uses mod_rewrite in /public_html/.htaccess stored in /.cpanel/ruby-on-rails-rewrites.db You can only redirect the main domain, subdomain or addon domain to a ruby on rails application. Rewrite Interface. Rewrite Creation Interface.