Topic: Vlad the Deployer with FastCGI and Lighttpd

Has anyone used vlad with fastcgi? It seems to have been built for mongrel, but I know that rails has spawner/reaper code to handle starting/stopping both. Does anyone know how to hook into that using vlad (unless it does by default, I don't really know). I don't really like the complexity of Capistrano, and vlad seems amazingly simple!

Re: Vlad the Deployer with FastCGI and Lighttpd

Okay, figured it out. Vlad the Deployer is SOO much easier than Capistrano!
We are running a virtual private server (VPS) site on railsplayground.com, with a lighttpd server and fastcgi instances. Great service! Highly recommend them.
The following are the steps I took to get automated deployment working:

1) sudo gem install vlad (do this on local AND server machines, for some reason "remote_task :migrate" in vlad/core.rb needs vlad installed on server, but really it shouldn't...)

2) Add or modify (if they exist) the following files:

[code=RAILS_ROOT/Rakefile]
# Add these two lines to your rakefile
require 'vlad'
Vlad.load[/code]

The following is for deployment on two servers, one for testing, one for production. You only need one namespace if you want. namespace just specifies "rake namespace:task" when you call rake from the command line (see below).

[code=RAILS_ROOT/config/deploy.rb]
require 'vlad'
require File.dirname(__FILE__) + "/vlad_helper.rb"
include VladHelper

set :deploy_to,  "/path/on/production/server/to/appname"
set :repository, "http://svn/repo/appname"

namespace :testing do
    task :settings do
        set :domain, "your-test-server.com"
    end
   
    setup_tasks 
end
 
namespace :prod do
    task :settings do
        set :domain, "your-production-server.com"
    end
   
    setup_tasks 
end[/code]

You can define a new namespace for each server you want. We have a test VPS and a production VPS, so you just change the :domain variables. The tasks are all the same, and are abstracted out to a module:

[code=RAILS_ROOT/lib/vlad_helper.rb]
module VladHelper
    def setup_tasks
        desc "Sets up the directory at /your/path/to/appname"
        remote_task :setup => :settings do
            dirs = [deploy_to, releases_path, scm_path, shared_path]
            dirs += %w(system log pids).map { |d| File.join(shared_path, d) }
            run "umask 02 && mkdir -p #{dirs.join(' ')}"
        end
 
         desc "Updates, chowns, and restarts"
        remote_task :deploy => [:update, :restart]
       
        desc "Updates web site with latest SVN release"
        remote_task :update => :settings do
            Rake::Task["vlad:update"].invoke
            # For use in ferret indexing, make index a sym link to shared/index
            run "ln -s #{shared_path}/index #{release_path}/index"
            # Give server all access to public folder
            run "chmod 755 #{release_path}/public -R"
            # Give user=apache group=apache access to the entire app
            # Even though we use lighttpd, it is still under apache:apache privileges
            # Don't ask, don't know why... RailsPlayground.com thing i guess.
            run "chown apache:apache #{release_path} -R"
        end     
 
        desc "Starts Lighttpd"
        remote_task :start => :settings do
            run 'service lighttpd start'
        end
 
        desc "Restarts Lighttpd"
        remote_task :restart => :settings do
            run 'service lighttpd restart'
        end
         
        desc "Stop Lighttpd"
        remote_task :stop => :settings do
            run 'service lighttpd stop'
        end     
    end
end[/code]

Once that is set:

rake testing:setup
rake testing:deploy
rake testing:start

or

rake testing:setup testing:deploy testing:start


You can do this for the other server as well
rake prod:setup prod:deploy prod:start

Once its all up, and you want to update the server to the latest SVN:
rake testing:deploy

I use cygwin on windows, not really sure if Vlad works outside of a *nix environment (like using cmd.exe in windows). But get cygwin for rails dev, it really helps! Also get Poderosa shell for cygwin, gives you tabs and everything. Each command Vlad runs with require a password, so I set up cygwin to use ssh keys (you may need an ssh package installed):

[code=Command Line]local$> ssh-keygen.exe[/code]
This creates id_rsa and id_rsa.pub files in your /home/.ssh/ folder.
[code=Command Line]local$> scp /home/.ssh/id_rsa.pub http://your-server.com:/root

local$> ssh root@yourserver.com
Password: *Enter your PS here*

Logged into server. Welcome!
server$> cat /root/id_rsa.pub >> /root/.ssh/authorized_keys[/code]
Or something like that. You can always ask your server admin where to put ssh keys/how to do it. But it should be pretty much the same for most VPS's.

Good luck, and happy impailing!


I mean deploying...

- Harmon

Last edited by Harmon (2007-09-12 18:09:23)

Re: Vlad the Deployer with FastCGI and Lighttpd

I'm doing some similar work on vlad to get it to start and stop my ActiveMessaging pollers.

I'm trying to understand where vlad tasks are 'inherited' and automatically run, and where they need to be explicitly called. I'm also not sure about what path things will execute in.

The end goals are:
1. Separate deployment from our demo server (stable branch) and our nightly testing server (latest from trunk)
2. When starting and stopping, also start and stop the ActiveMessaging pollers using the script "script/poller start"

Will rake trunk:update automagically call rake vlad:update or do I need to explicitly define trunk:update and have it invoke vlad:update? Is there some way to inherit from vlad?

Do I need to define a full path or chdir for the "run script/poller start" to work??

require 'vlad'

# IP address for mongrel to list on (this is localhost, since apache is routing requests to mongrel).
set :mongrel_address, "127.0.0.1"

# Rails environment
set :mongrel_environment, "production"

# user and group ids to run mongrel as
set :mongrel_user, "someuser"
set :mongrel_group, "somegroup"

# Number of mongrel instances in the cluster
set :mongrel_servers, 3

# Command to start apache. We don't want vlad to start and stop apache, so this is
# a dummy command.
set :web_command, "true"

namespace :r2 do
  # Domain of host to deploy to. Need to change this if deploying to a different host.
  # Possibly could set host name via an environment variable.
  # Format is <ssh account>@<hostname>
  set :domain, "extension@server1"

  # Folder to deploy application to.
  set :deploy_to,  "/opt/myproj"

  # SVN repo path.
  # We'll need to create a stable branch and change this to check out that branch.
  set :repository, "http://mysvn/svn/repos/myproj/branches/r2"
     
    desc "Starts or restarts the pollers"
    remote_task :start => :settings do
      Rake::Task["vlad:start"].invoke
      run 'script/poller stop'
      run 'script/poller start'
    end
end

namespace :trunk do
  # Domain of host to deploy to. Need to change this if deploying to a different host.
  # Possibly could set host name via an environment variable.
  # Format is <ssh account>@<hostname>
  set :domain, "myproj@server2"

  # Folder to deploy application to.
  set :deploy_to,  "/opt/myproj"

  # SVN repo path.
  # We'll need to create a stable branch and change this to check out that branch.
  set :repository, "http://mysvn/svn/repos/myproj/trunk"
     
    desc "Starts or restarts the pollers"
    remote_task :start => :settings do
      Rake::Task["vlad:start"].invoke
      run 'script/poller stop'
      run 'script/poller start'
    end
end


Thanks for the help!

Last edited by jbartels (2007-12-18 12:25:27)

Re: Vlad the Deployer with FastCGI and Lighttpd

http://withoutscope.com/2007/9/17/vlad- … ecret-love

This solved the different deployment target issues.

Still trying to sort out how to start a13g.

Re: Vlad the Deployer with FastCGI and Lighttpd

Ok sovled my own problems.

I added this:

namespace :vlad do
  remote_task :start do
    run "#{deploy_to}/current/script/poller stop"
    run "#{deploy_to}/current/script/poller start"
  end
end

to deploy.rb and the pollers start after doing the normal vlad thing.