Capistrano deployment on litespeed

Posted on Sun Jul 08 @ 13:37:47

The other day a friend of mine recommended me litespeed web server for rails application instead of the apache, mongrel cluster combination I’ve used. So I listened to him an installed litespeed following these instructions written by PickledOnion.

After the installation I needed to customize my previous capistrano deployment script. I use capistrano 2 for deployment. Here is the code of the script:


    set :application, "munitic.com.hr" 
    set :repository,  "svn://munitic.com.hr/#{application}/trunk" 
    set :deploy_to, "/home/ivica/public_html/#{application}" 
    set :svn_username, 'ivica'

    role :app, "www.munitic.com.hr" 
    role :web, "www.munitic.com.hr" 
    role :db,  "www.munitic.com.hr", :primary => true

    namespace :deploy do
      desc "Restart litespeed web server" 
      task :restart, :roles => :app do
        sudo "/opt/lsws/bin/lswsctrl restart" 
      end

      desc "Start litespeed web server" 
      task :start, :roles => :app do
        sudo "/opt/lsws/bin/lswsctrl start" 
      end

      desc "Stop litespeed server" 
      task :stop, :roles => :app do
        sudo "/opt/lsws/bin/lswsctrl stop" 
      end

      task :after_update, :roles => :app do
        run "ln -s #{shared_path}/photos #{current_path}/public/photos" 
        run "ln -s #{shared_path}/munitic.com.hr.xml 
                   #{current_path}/config/munitic.com.hr.xml" 
        run "ln -s #{shared_path}/.httpasswd 
                   #{current_path}/config/.httpasswd" 
        sudo "chmod -R 2770 /home/ivica/public_html" 
        sudo "chgrp -R www-data /home/ivica/public_html" 
        run "chmod 600 #{current_path}/.msmtprc" 
      end
    end

The main part of the script are the restart, stop, and start tasks. They as their name says restart, stop and start litespeed. I have one additional task called after_update which I use to do some of my custom stuff like linking my gallery photos to /public/photos folder of my application, or linking the configuration file of the litespeed virtual host (munitic.com.hr.xml) and linking the .httpasswd file which is used to enable authorization for awstats. The chmod and chgrp commands are used to ensure that litespeed will have enough permissions to serve my application. The last chmod is to ensure that msmtp program (used to send exception mail via gmails smtp server) which demands that its configuration file (.msmtprc) has 600 permissions has them.

One last thing. To make deploy:web:enable and deploy:web:disable tasks work login into your litespeed administration web site, on the “Configurations” menu choose “Virtual hosts” and click on the virtual host you want to edit. Now click on the Rewrite tab and then click on the “edit” link for Rewrite Control and set Enable Rewrite to yes. Click “save”. After that click “edit” for Rewrite Rules and add these lines:


    RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
    RewriteCond %{SCRIPT_FILENAME} !maintenance.html
    RewriteRule ^.*$ /system/maintenance.html [L]

Click “save”. Now apply the changes and restart the server.

Enjoy!

Posted in Rails, 3 Comments Comments

Comments

CROATIA Ivica on 23 Jul at 22:00:04

Yes I forgot to mention that, thank you.

CROATIA Denis Brulić on 10 Jul at 15:30:00

Hello, this comment is for the readers. Check "view page source" and you'll notice that code highlight is done by : <pre><code class="ruby"> tags.

UNITED STATES Will W on 23 Jul at 17:50:08

I also followed PickledOnion's instructions, but I had to change one thing to get it to work. In the Virtual Listener's Context tab, I clicked on Edit and changed the Location to "$VH_ROOT/public/current".

COMMENTS ARE DISABLED