Technical
Deploy Script

Its not always easy for Java ( I mean other ) people to figure out different options for mongrel. I had to write a script that will automatically restart application in rails_app directory using “easy” syntax.


#key = project name as well as folder name
#value = port number on which to run the app
@existing_projects = {
            "CREST" => 8000, 
            "mis" => 8001,
            "Security" => 8002,
            "Requisites" => 8003,
            "GED" => 8004,
            "collateral" => 8005,
            "leb" => "8006" 
          }
@environments = ["production","development","test"]

module Rdeploy

  def self.help_banner
    puts "Usage: ruby rdeploy.rb ProjectName command environment [options] #for example ruby rdeploy.rb mis start production" 
    puts "\n" 
    puts "Options:" 
    puts "\n" 
    puts "       --with-cvs-update           to run cvs update before restarting" 
  end

  def self.set_env
    if !ARGV[2].nil? 
      case ARGV[2]
        when "development" 
          env "/db/dev/eq/cprt/Ruby" 
        when "production" 
         env "/db/pub/eq/cprt/current/Ruby" 
        else
          puts "\n" 
          puts "There is no such environment  as #{ARGV[2]}." 
          puts " Valid options:\n" 
          puts "    production " 
          puts "    development" 
          puts "\n" 
        exit
      end  
    else
      puts "Please Specify environment" 
      puts "Available options are" 
      ["production","development"].each{|e| puts " #{e}"}
      exit
    end
  end

  def self.env(ruby_home)
      ENV['PATH'] = "" 
      ENV['ROOT']= ruby_home
      ENV['ROOT_APP']="#{ENV['ROOT']}/rails_apps" 
      ENV['SYBASE']="/home/tpdev/Sybase" 
      ENV['SYBASE_LIB']="/home/tpdev/Sybase/OCS/lib" 
      ENV['ORACLE_HOME']="/home/tpdev/Oracle" 
      ENV['TNS_ADMIN']="/home/tpdev/Oracle/network/admin" 
      ENV['PATH']="#{ENV['ROOT']}/ruby_apt/bin:#{ENV['SYBASE']}/OCS/lib:#{ENV['SYBASE']}/locales:/usr/bin" 
      ENV['LD_LIBRARY_PATH']="#{ENV['ROOT']}/ruby_apt/lib:#{ENV['SYBASE']}/OCS/lib:i#{ENV['SYBASE']}/locales:#{ENV['ORACLE_HOME']}/lib" 
  end

end

if ARGV.empty? || ARGV[0]  "-h" || ARGV[0]  ”—help” 
  Rdeploy.help_banner
  exit
end

if @existing_projects.has_key? ARGV[0] Dir.chdir(”#{ARGV0}”) case ARGV[1] when “start” Rdeploy.set_env puts `mongrel_rails start -d -p #{@existing_projects[ARGV0]} -e #{ARGV2}` when “stop” `mongrel_rails stop` when “restart” `mongrel_rails restart` else puts “invalid command #{ARGV1}” puts “Available commands are:” puts ”\n” puts ” – restart” puts ” – start” puts ” – stop” puts ”\n” end Dir.chdir(”../”)
else puts “Project with the name of #{ARGV0} does not exist.” puts ” Following is the list of available projects:” @existing_projects.each_key{|key,value| puts ” #{key} \n”} exit
end