Red5 Application Deployment with Capistrano
Monday, June 25th, 2007Introduction
To deploy the applications for Red5, I found that Rubys Capistrano really fits very nice. This is an abstract on how we did it.
Basic Requirements
Subversion repository with your Red5 Application checked in (the compiled .class files) with the following structure (or adjust the script below):
- webapps/config
- webapps/MyRed5Application
- webapps/red5-default.xml
On the server
- Installed and configured Red5 server
- Secure socket shell access to the server
- Subversion client (svn)
On the client from which to deploy
- Ruby >1.8.4
- Gems
- Capistrano (gem install capistrano)
deploy.rb
The following Capistrano recipe will provide you with the functionality of automatic deployment and rollback (it uses Capistranos out-of-the-box features where possible). Put this file (”deploy.rb”) in a directory called “config”. Be sure to adjust all parameters starting with a “#”.
set :repository, “#svn-path-to-your-webapps” # i.e. https://server.com/repos/red5apps/webapps
set :svn_username, “#svn_user” # svn user to use for checking out the application
set :svn_password, Proc.new { Capistrano::CLI.password_prompt(’SVN Password: ‘) }
# app roles
role :app, “#example.com” # domain with s.s.h. access to deploy to
set :user, “#user” # user used for login
# directories
red5_dir = “#/etc/red5″ # path on the server to your red5 directory
set :deploy_to, “#/etc/red5/deploy_to_directory” # directory where to check out your svn code
# tasks
task :restart do
run “cd #{red5_dir} ; #{red5_dir}/red5-shutdown.sh >> #{red5_dir}/red5.log”
run “cd #{red5_dir} ; nohup #{red5_dir}/red5.sh >> #{red5_dir}/red5.log &\nsleep 5″
end
# overridden task
desc <<-DESC
Update all servers with the latest release of the source code. All this does
is do a checkout (as defined by the selected scm module).
DESC
task :update_code, :except => { :no_release => true } do
on_rollback { delete release_path, :recursive => true }
source.checkout(self)
set_permissions
# uncache the list of releases, so that the next time it is called it will
# include the newly released path.
@releases = nil
end
Now what
First step is to create the initial directory layout for your application on the server. Run the following command in the terminal/shell in the “webapps” directory:
When started, Capistrano will ask for your password to log into the server and create the appropriate directories you specified in the deploy.rb recipe. You can read more about this in the Capistrano manual, but basically it creates subdirectories like “releases”, “shared” where the application is going to be placed. Each deploy will create a new release and the directory “current” will be a symlink to the current release.
Next step on the server is to replace the Red5 “webapps” directory and create a symbolic link:
rm -rf webapps
ln -s #/etc/red5/deploy_to_directory/current webapps
This makes sure that Red5 will always take the latest deployed release.
The final step is to deploy the application:
This will checkout the latest release to the server, change the “current” symlink to this release (Red5 was configured to use the “current” directory) and will restart the Red5 server to use the latest version. If you’re running Tomcat it should be easy to change the task :restart…
And finally, in case you want to roll back to your previous version, just execute
on your client and Capistrano will take care of it.