Capistrao web enable and disable

Posted on January 6th, 2010

Using a simple cap disable_web command allows my Rails apps to be completely disabled while I perform maintenance on the site without having to worry about users accessing it. Being able to suspend the site with a single command is cool…

First create a generic page that you want your users to see when your site is disabled and name it maintenance.html. Then throw it into your /config directory.

Cap Tasks

Next, write a disable_web task for Capistrano.

desc "This will disable the application and show a warning screen"
task :disable_web do
  run "cp #{current_path}/config/maintenance.html #{current_path}/maintenance.html"
end

This simple one liner will copy the maintenance.html file into the root of your application. Now lets write a task to re-enable the application.

desc "This will enable the application and remove the warning screen"
task :enable_web do
  run "rm #{current_path}/maintenance.html"
end

This will simply delete the maintenance file.

Ok, so, basically, when you run cap disable_web, Capistrano will move your maintenance file into the root of your app, and enable_web will delete it. So far this does nothing to disable your PHP application.

mod_rewrite Magic

The trick to this is using mod_rewrite to look for your maintenance file. If it’s at the root of your application, then all requests will be directed to it. Otherwise the application works as normal.

RewriteEngine On

# Check for maintenance file and redirect all requests
RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*(\.html|\.php)$ /maintenance.html [L]

This will look for any requests of .html and .php files. All requests that fit that condition will pointed to the maintenance.html page if it exists at the root of the application.

Thunderbird 3 released

Posted on December 29th, 2009

If you like Firefox’s tabbed browsing, you’re going to love tabbed email. Thunderbird 3’s tabbed email lets you load emails in separate tabs so you can quickly jump between them. Search results open in a new tab too. New tools like our timeline and filtering tools will help you pinpoint the email you’re looking for, whether it’s the one from yesterday, last month, or several years ago.”

You can read the release notes from http://www.mozillamessaging.com/en-US/thunderbird/3.0/releasenotes/

General linux commands

Posted on December 27th, 2009

1. How to know in which shell you are working on ?

echo $0

2. The default  shell in your passwd file :

echo $SHELL

3. The environmrnt variable path is given using the command :

echo $PATH

4. To list all the files in a directory :

ls

5. To list the files based on modified date:

ls -lrt

6. Free memory available :

free -m

7. Hard Disk space left/available:

df -h

8. To know the server load statistis use the command:

top

9. Command used to tar a file ;

tar -cvzf <filename.tar> <filename>

10. To find the count of files in a directory

cd directory

ls * | wc -l

Shell Script to print the multiplication table from 1 to 7

Posted on December 27th, 2009

for i in $(seq 1 7); do
echo “Multiplication Table of $i :”
for x in $(seq 1 10); do
result=`expr $i \* $x`;
echo “$i * $x = $result”;
done;
echo “==========================”
done;

Securing Apache 2 using SSL : How to

Posted on December 26th, 2009

We access websites using the protocol http. To make our site secure we need to access the site with the protocol https (port number 443). For this we need to add SSL certificates to our apache configuration. The document below describes how this is done:

1. Install Apache.

2. Enable the SSL module. Add the line “SSLEngine on” to apache congiguration file or in the 443 virtual hosts entry.

3. Keys:

The first step is to use OpenSSL to produce the keys that are used to secure your site. These keys are used when encrypting and decrypting the traffic to your secure site. To do so, run

openssl genrsa -out mydomain.key 1024

Typing the above on the command line will create a 1024 bit private key and
puts it in the file mydomain.key, which will later be placed in the proper
directory. This private key is not encrypted and protected by a pass phrase.
To encrypt the key, add -des3 to the above command line. Be aware in doing
so that you will always need to be available to type in the pass phrase
whenever the server restarts. If you choose not to encrypt the key, be
sure to keep it secure. In particular, it should be placed in a directory
that is only readable by the web server.

4. Certificates
 Self Signed Certificates
 Generate your own certificate by going back to the command line and
 entering the following:

  openssl req -new -key mydomain.key -x509 -out mydomain.crt

   This command creates a self-signed SSL certificate in the file
   mydomain.crt, which will later be placed in the proper directory.

5. Installing the Site Certificate

It is now time to place the private key and the certificate in locations where they will be found by Apache.My installation wants the private key (mydomain.key) to be placed in /etc/apache2/ssl.key/ and the certificate (mydomain.crt) to be in /etc/apache2/ssl.crt/. Assure that the ssl.key directory is only readable by root and that if you keep any other copies of your private key, that they cannot be read by others.

Configuring Apache

To configure Apache, you will need to edit the httpd.conf file that for my installation is found in /etc/apache2. To support secure traffic over SSL, Apache needs to have mod_ssl installed and enabled. To enable SSL in apache give the command a2enmod ssl And restart apache. The rest of the work in involved in getting /etc/apache2/sites-enabled/000-default right. Apache's virtual host capability is used to provide the secure site. Edit the /etc/apache2/ports.conf
NameVirtualHost *:80
NameVirtualHost *:443
Listen 443

Edit the /etc/apache2/sites-enabled/000-default file :

<VirtualHost *:80>
ServerAdmin webmaster@mydomain.com
DocumentRoot /srv/www/htdocs/mydomain
ServerName www.mydomain.com
ServerAlias mydomain.com
</VirtualHost>

<VirtualHost *:443>
ServerAdmin webmaster@mydomain.com
DocumentRoot /srv/www/htdocs/mydomain-secure
ServerName mail.mydomain.com
SSLEngine on
SSLCertificateFile /etc/apache2/ssl.crt/mydomain.crt
SSLCertificateKeyFile /etc/apache2/ssl.key/mydomain.key
</VirtualHost>

Debugging Apache

You may refer the log /var/log/apache2 directory to look for

the access and error logs for Apache.

Installing and Setting up Apache in Ubuntu server

Posted on December 26th, 2009

This scenario applies to the Ubuntu version of linux.

1. Install Ubuntu

2. apt-get install apache2

Before this make sure you are connected to the internet. You may also check the DNS entry at the file /etc/resolv.conf

3. /etc/init.d/apache2 start

4. The conficuration file for the port 80 is at

/etc/apache2/sites-enabled/000-default

How to print the nth line of a file

Posted on December 25th, 2009

head -(n+1) <filename> |  tail -1

Ruby on Rails deployment

Posted on December 25th, 2009

The good environment for the Ruby on Rails deployment is the combination of Apache phusion with Ruby Enterprise Edition.

Happy Christmas

Posted on December 25th, 2009

Wishing you a merry christmas to all.

:::::
Garden Hose Pot
Cheap Retro Replica NFL NBA MLB Throwback Football Basketball Jerseys | hp printer ink cartridges refills| Jewelry Making Supplies | Thumb Joint Pain | Dog Health Problems |Tinkerbell Personal Checks |Garden Planters