Thursday, July 28, 2011

Using CCRB to manage multiple environments with same code base

Usually the code should be tested in a development environment before pushing the code to production. Automating test process is an important process in deployment. CCRB is a great tool to do this.


The code base is written in such a way that it can be deployed to development or production based on environment variables passed using the capistrano deployment script.

The development deployment initiates a CCRB build and testing process in the development cruisecontrol project which has the same code base. During this process the CCRB should be capable of invoking a development environment variable.

In comman setups we have the environmental variable 'development' and 'production' to differentiate the between production and development.

We add the following entries to cruise_config.rb to pass the 'development' environmental variables to the ccrb build.
============
ENV['env'] = 'development'
============

You can create a file named build_requested in project rootdir to initiate a build process.

Tuesday, July 26, 2011

Capistrano Using User Input

Capistrano does not accept ruby methods. Suppose I need to get user input I can't use gets.strip and it would spew Method not found error.

You can use the following method to get the user input in capistrano deploy scripts.
==============
puts "This is a critical code do you want to proceed (y/n)"
value = STDIN.gets[0..0] rescue nil
exit unless value == 'y' or value == 'Y'
===============

Capistrano is full and fast automation solution. Don't include too much of user interaction in that unless necessary.

Tuesday, July 12, 2011

Bash Execute a Remote Command as Sudo

Just difficult for me to remember this thing. This is a way to execute remote command which can executed only using sudo privileges.
===============
ssh -t testuser@testserver "/usr/bin/sudo sh -c w"
===============

Thursday, July 7, 2011

Migrate Thunderbird email from Mac to Ubuntu

This is a simple step to migrate thunderbird mails from Mac OSX to Ubuntu.


Create the following directories in Ubuntu Desktop

cd /home/rayber
mkdir .thunderbird

Mount the mac HD

mount -t hfsplus /dev/sda2 /media/mac
Copy the data from mac homedir

cp -rpf /media/mac/Users/home/rayber/Library/Thunderbird/* .thunderbird/


You are now good to go. Start thunderbird and you should be able to start from the place where you stopped in Mac.

Tuesday, July 5, 2011

SSH with Empty Password and no ssh keys

This is a guide to zero security in linux. It is applicable only in places where security is not a threat and there is no threat from external networks.

The following options would allow a system running ssh to have a user with empty password so that you can use this user to login without any password or ssh keys.


I am adding a test user for this purpose.

useradd noneknowme
passwd -d noneknowme

Configure ssh server to allow empty passwords.

Edit the following line in /etc/ssh/sshd_config
================
PermitEmptyPasswords yes
================

Restart sshd using /etc/init.d/sshd restart

Now you should be able to access the host with ssh with username noneknowme without any issues.
===============
ssh -l noneknowme test
[noneknowme@test ~]$
================

Don't try this . I am using this as a reference. Thanks to linuxquestions.org

Friday, July 1, 2011

script to check swap usage by process ( approximate )

The following command returns the total swap usage.

swapon -s

The following script would obtain the total MB of swap used obtained from proc filesystem and sum it up.

for pid in `ps -ef|grep -i java| grep -v grep|awk '{print $2}'`; do echo -n "Pid: $pid "; cat /proc/$pid/smaps |grep -i swap| awk '{SUM += $2} END {print "SUM: " SUM " kB (" SUM/1024 " MB)"}'; done

Thanks to linuxquestions.org