Tuesday, February 22, 2011

BuildForge Introduction


Before you start
In this tutorial, learn how to install and configure IBM Rational® Build Forge® to build the open source project Jakarta Tomcat. Create a continuous integration environment for Tomcat, with builds occurring whenever changes are committed to the Tomcat Subversion repository. With this 2-part series, go from zero to 96 bpd (builds per day) in two days. This tutorial covers the tasks for the first day.
If you are a developer involved in build automation, or a system operator providing infrastructure support for build and deploy functions, this series is for you.
Part 2 (the second day) of this series describes how Build Forge provides for the reuse of existing project scripting. It also covers how Build Forge can extend a simple compile and package build process by adding customization and deployment capability.
After completing this tutorial you will know:
  • Basic Build Forge concepts
  • How to install and set up Rational Forge
  • How to create Build Forge objects to represent build servers for the tutorial
  • How to configure a Hello World project to run
It is assumed that you have some understanding of building applications based on Java™ technology. Build Forge is language agnostic, but the Tomcat project is written in the Java programming language. Experience with Apache Ant and Subversion is helpful, but not required.
To complete the steps in this tutorial, you should have access to the following tools, which you can get by using the contact information on the Rational Build Forge product overview
  • Introduction
  • This tutorial uses Tomcat as an example project to show how a Rational Build Forge implementation reuses existing scripts. Think of Tomcat as an analogy for any project you'd like to include in a build management system where you can't, or don't want to, change build scripts. In the tutorial example, Tomcat could represent any internal or external project related to your projects.
  • Interrelated projects need to be deployed into an integration environment so they can be tested together. Triggering builds in the integration environment continuously when project codebases change (continuous integration), then running automated tests, is best practice for ensuring that system integration points continue working.
    When implementing build management, you want to avoid impacting developers' current build workflows, or limiting their future ability to innovate. Using an open source project is perfect. A build management system should be judged on: enabling an organization to achieve continuous integration, customized notifications, secure access, scheduling, and reporting without requiring development changes. The open source project will show how Rational Build Forge can automate the key tasks.

    Before and after
    Before and after 

Install and set up Rational Build Forge
This section explains how to set up the required server components, as shown below.
Section 2 goal
For this tutorial, all server processes, including the database, will be running on a single host.
The Build Forge Management Console will check for a valid license on startup. You need to install the Rational License Server and import an evaluation license before installing the Build Forge Management Console.
  1. Unzip the installation files.
  2. Run Setup. Select Install Rational License Server.
  3. Accept the default options for the rest of the license server installation. When setup is complete, click Finish.
  1. Start the License Key Administrator by selecting All Programs > IBM Rational > IBM Rational License Key Administrator.
  2. Select Import a Rational License File, and click Next.
  3. Browse to the location of the Evaluation License Key file.
  4. Open the file, and click Import.
  5. Verify that the licenses are valid, and click Import.
  6. Agree to restart the license server.
The Build Forge Management Console will store configuration data and build log files in a database. For this tutorial, install MySQL version 5.0.45.
  1. Unzip the installation file, then run it.
  2. When prompted, select the Complete setup.
  3. Select Install.
  4. Click Next until you see the window below. Select Configure the MySQL Server now, then click Finish.
  5. Click Next, select the Standard Configuration, and click Next.
  6. Select:
    • Install As Windows Service
    • MySQL for the Service Name
    • Launch the MySQL Server Automatically
    • Include Bin Directory in Windows PATH
    and click Next
  7. Enter a root password, click Next, then click Execute.
  8. Click Finish.
You need to create a database instance inside MySQL to store Build Forge data. You also need to create a MySQL user for Build Forge to connect with.
  1. Open a command prompt and, as shown below, enter mysql -uroot -p<password entered during mysql install>
  2. At the mysql prompt, enter create database build;
  3. At the mysql prompt, enter grant all on build.* to build identified by 'build';
  4. At the mysql prompt, enter quit
Now that there is a license server ready to serve valid Build Forge licenses, and a database available and configured, proceed with the installation of the Build Forge Management Console.
  1. Unzip the installation file, and run it.
  2. Click Next on the setup wizard Welcome panel.
  3. Select your destination folder.
  4. Enter localhost for the License Host, and accept the default Http Server Port unless the system you are using is currently using that port (for example, another Web Server).
  5. Enter MC1 for Location Name. Select Connect to existing database, and:
    • DB Name: build
    • DB Type: MySQL
    • DB Host: localhost
    • Username: build
    • Password: build
    Management Console 
  6. Click Install.
    After installation, the Build Forge Management Console will start up in the background as a service. When it starts and encounters the empty MySQL database, it will begin creating a table structure. This process may take a minute. Wait for the system to become idle before proceeding.
  7. After stopping the Build Forge service (bfengine), you'll copy libmySQL.dll to the BuildForge Apache directory. At a command prompt, enter net stop bfengine
  8. Enter copy "c:\Program Files\MySQL\MySQL Server 5.0\bin\libmySQL.dll" "c:\Program Files\BuildForge\Apache\bin"
  9. Restart the Build Forge service by entering net start bfengine
  10. Close the command prompt window.
  11. Double-click the Management Console icon on the desktop.
  12. Enter the User name root and Password root, and click Login.
  13. You should then see the Management Console home page for the root user.
    Management Console
Build Forge Agents can be installed on any system that will take part in a build, deploy, and test process managed by Build Forge. For this tutorial, install the agent on the same system as the Management Console. The agent system can, and usually will, be remote.
  1. Unzip the installation file and run win-bfagent-7.0.1.211.exe.
  2. Accept all defaults throughout the agent installation panels.
  3. Click Finish when prompted.
This concludes the installation required for the Rational License Server, MySQL, the Rational Build Forge Management Console, and the Rational Build Forge Agent. The next section explains how to configure Build Forge to create a build process.

First steps to Hello World
In this section you create Build Forge objects to represent build servers for the tutorial, and configure a Hello World project to run. For a complete explanation of the options in these steps, see the online help with Rational Build Forge.
Hello World
You installed the Build Forge agent in Install and set up Rational Build Forge. The first step is to configure the Management Console to communicate with the agent process. This configuration will use functions from the Servers navigation panel in the Management console.
Hello World
The object holds the credentials the Management Console will use to log into the system running the Agent. The account used must have sufficient privileges to perform the tasks in the build process.
  1. Click Server Auth under Servers.
  2. Enter localhost auth for the Name, and the login parameters for the Administrator (or an account with sufficient privileges).
  3. Click Save Server Authentication.

    Hello World
Build Forge provides a powerful means of selecting a build server dynamically at build time. It is beyond the scope of this tutorial to describe this function, so you will hard wire the builds to a particular server. First you need to make a Selector that selects a server based on its name.
  1. Click Selectors under Servers.
  2. Enter build selector for the Name.
  3. Click Save.

    Hello World
Build Forge allows multiple criteria to be used, such as free disk space, number of CPUs, and so on. This tutorial uses:
  1. Default Name BF_NAME.
  2. Operator == .
  3. Enter build_server for the Value.
  4. Yes for Required.
  5. Click Save.

    Hello World
The server object holds the connection information (host) and the link to the Server Authentication we created in Create server authentication. On the build server, the working directories for builds are set by the Path entry on this panel. Build Forge also lets you associate a server with an Environment variable specific to it.
  1. Click Servers.
  2. Enter build_server for the Name, c:\build for Path, and select localhost auth for Authentication. Leave the default values for the remaining fields.
  3. Click Save.

    Hello World
Build Forge will not be able to write to the directory specified in the path above unless it has been created. At a command prompt, enter md c:\buildHello World
To test the connection to the agent:
  1. Select build_server.
  2. Click Test Connection.

    Hello World
The Test Results tab will be displayed. After the Management Console has connected with and tested the agent, the display will be updated with the test results and the indicator on the icon for the server will show a green status.
Hello World
Now that the Management Console can control builds with an agent, you can write a Hello World project that will use the agent to echo a value. A Build Forge project contains several steps representing the commands that make up the build process.
  1. To create the build project, it must be configured with a name and a selector. Consult the online help for a description of the remaining project configuration fields.
    • Click Projects.
    • Enter Hello World for the Name, and verify that Selector has defaulted to build selector.
    • Click Save Project.

      Hello World
  2. Open the project by clicking on Hello World in the project list.
  3. In the project, the steps are configured to perform the build process. In the Details tab, create a single step that echoes back a value:
    • Enter Echo Value for the Name
    • Enter echo Hello World in the Command area.
    • Leave the rest of the fields with default values for now.
    • b. Click Save Step.

      Hello World
  4. Execute the project by clicking Start Project.
  5. Leave the default values shown below, and click Execute.
  6. The running build page will be displayed, showing progress through the project steps as they execute. The result from each step is also displayed.
  7. Click the Step Name Echo value to see the log output from the step execution.
  8. Scroll to the bottom of the log output. The expected Hello World message is shown.

    Hello World

Summary
You've accomplished a lot. The Build Forge Management console is running, and is connected to a "remote" server. You learned some basic Build Forge concepts, and are now familiar with the Build Forge deployment architecture and basic configuration. The architecture is able to control a simple build process on a remote server.
Get some rest and be ready for your second day, when you'll use everything created so far to begin building a real-world project: Jakarta Tomcat. Part 2 describes how Build Forge provides for the reuse of existing project scripting. It also covers how Build Forge can extend a simple compile and package build process by adding customization and deployment capability.

Monday, February 21, 2011

CGI installation on ubuntu server

I'm keen to execute perl CGI scripts on my ubuntu system, So i need to configure cgi in my apache2. I followed below steps.


sudo vi /etc/apache2/apache2.conf
Add the following line somewhere:
ServerName localhost
and restart Apache.
sudo /etc/init.d/apache2 restart

Step 1: Create a new Apache site

To create a new site, first create a directory where you want to keep files associated with this site. I like to keep sites in /usr/local/public_html directory. The configuration files for all sites available to Apache are stored in the /etc/apache2/sites-available/ directory. Create a configuration file for your new site (here called samba) by copying the configuration file for the default site.
sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/samba
Open the new configuration file.
sudo vi /etc/apache2/sites-available/samba
You will notice that there is a lot of stuff between <VirtualHost> tags. You have to edit some of this. Change the DocumentRoot path to point to the newly created site directory.
DocumentRoot /usr/local/public_html
In a similar fashion, change one of the Directory directives (it looks something like this)
<Directory /var/www/>
to be consistent with your site path.
<Directory /usr/local/public_html/>
After making these changes, disable the default site using the Apache disable site script.
sudo a2dissite default
Next, use the Apache enable site script to activate the new site.
sudo a2ensite samba
Finally, restart Apache.
sudo /etc/init.d/apache2 restart
Create a simple index.html file and save it in /usr/local/public_html/ to test your new site. Something simple like
<html>
<strong>Ubuntu Hardy Heron is Here</strong>
Browse (preferable on another machine) to your new site to test the configuration.

Step 2: Install phpmyadmin and create root mySQL user

In order to make mySQL database administration easy, many hosts provide phpMyAdmin. You can easily install this tool on your Ubuntu LAMP server too using the built in package management software. At the command prompt type
sudo aptitude update
sudo aptitude install phpmyadmin
You will have to insert the Ubuntu install CD to complete this installation. During the installation the script will ask which version of Apache to automatically configure. If you installed apache as per this previous postthen select apache2 (with space bar) and continue. After the install completes, the phpMyAdmin script should be in the /usr/share/directory and (after restarting Apache; see above) it should resolve in your browser when you type localhost/phpmyadmin (or xxx.xxx.xxx.xxx/phpmyadmin). If it doesn’t, you must add the following alias and include to the bottom of the apache configuration file apache2.conf in /etc/apache2/.
Include /etc/phpmyadmin/apache.conf
Alias /phpmyadmin /usr/share/phpmyadmin
You can log in by using root as your username and the root password configured during the mySQL installation (if you decided not to enter a mySQL password or were not prompted for a password then the password field is blank by default). Once logged on to phpMyAdmin, you can set a new root password by navigating to the privileges page, clicking the icon that looks like a pencil next to each root account (there may be more than one), and entering a password in the appropriate field of the page that loads.

Step 3: Configure a cgi-bin directory

Configuring Apache to allow CGI program execution is pretty easy. Create a directory to be used for CGI programs (here I create /usr/local/public_html/cgi-bin) and add the following to the site configuration file (again between the <VirtualHost> tags).
ScriptAlias /cgi-bin/ /usr/local/public_html/cgi-bin/
<Directory /usr/local/public_html/cgi-bin/>
          Options ExecCGI
          AddHandler cgi-script cgi pl
</Directory>
The first line creates an alias that points to the directory in which CGI scripts are stored. The final line tells Apache that only files that end with the *.cgi and *.pl extensions should be considered CGI programs and executed.




To Enable the apache with the CGI :

Enable CGI and perl support for apache2 server
You need to install the following package
sudo aptitude install libapache2-mod-perl2
Configure a cgi-bin directory
You need to create a cgi-bin directory using the following command
sudo mkdir /home/www/cgi-bin
Configuring Apache to allow CGI program execution is pretty easy. Create a directory to be used for CGI programs and add the following to the site configuration file (again between the <VirtualHost> tags).
ScriptAlias /cgi-bin/ /home/www/cgi-bin/
<Directory /home/www/cgi-bin/>
Options ExecCGI
AddHandler cgi-script cgi pl
</Directory>
The first line creates an alias that points to the directory in which CGI scripts are stored. The final line tells Apache that only files that end with the *.cgi and *.pl extensions should be considered CGI programs and executed.
Test your Perl Program
cd /home/www/cgi-bin
sudo nano perltest.pl
Copy and paste the following section save and exit the file.
###Start###
#!/usr/bin/perl -w
print "Content-type: text/html\r\n\r\n";
print "Hello there!<br />\nJust testing .<br />\n";
for ($i=0; $i<10; $i++)
{
print $i."<br />";
}
###End###
make sure you change permissions on it
sudo chmod a+x perltest.pl
Now open your web browser open http://yourserverip/cgi-bin/perltest.pl.It should be working.

Thursday, February 17, 2011

mail alert for root login

Paste the below in either .bashrc or .bash_profile and restart your terminal


echo 'ALERT - Root Shell Access on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d"(" -f2 | cut -d")" -f1` to `/sbin/ifconfig | grep "inet addr" | head -1 | awk '{print $2}' | cut -d":" -f2`" user@examples.com

Monday, February 14, 2011

Connecting to linux server form ubuntu using .ppk file

Make sure you have installed:

sudo apt-get install openssh-server openssh-client

Install putty using:
sudo apt-get install putty

Generate rsa keys and place them in your .ssh folder.

  • Create the public key file:
    puttygen /path/to/puttykey.ppk -L > ~/.ssh/id_rsa.pub
  • Create the private key file:
    puttygen /path/to/puttykey.ppk -O private-openssh -o ~/.ssh/id_rsa
Now you are able to ssh and scp to that server.

If you have .pem file and want to convert it into .ppk file use the below:
puttygen ec2-democrasoft.pem -O private -o ec2-democrasoft.ppk


AFAIK, the files under .ssh show have below permissions.



-rwx------ 1 root root 1675 2011-03-31 12:31 id_rsa
-rw-r--r-- 1 root root  402 2011-03-31 12:31 id_rsa.pub

Thursday, February 10, 2011

Subversion installation on windows

Below is the step by step procedure to install subversion using apache on windows.


Introduction

I decided to write this article in order to save time to those people who must install and set up Subversion on Windows machines, having no idea of how to do that and no time to search for any piece of information on the internet.
It took two days for me and enormous efforts to understand what is going on with Subversion and how to make it work. I asked my friend who is working on a parallel project in the Computer Science department of my university how much time he spent setting up SVN with Apache on their Linux server. He told it took him one month!!! :) Well, no comments.
Let's get down to business, we don't have much time.

Prerequisites

First of all, we need to download SVN and Apache.

Subversion

Install Subversion to any directory, then add the bin sub-directory to the environment path. For example: if we installed svn into C:\programs\programming\svn-win32-1.4.0, then go to Start -> Settings -> Control Panel -> System.
Click on the Advanced tab and choose Environment Variables.
subversion_apache_system_properties.jpg
subversion_apache_environment_variables.jpg
subversion_apache_path.jpg
The next step is to create a directory which will be a root for all the repositories of our source control.
  • Open the command prompt.
  • Let's say that we want our root directory be named as c:\svnroot. Then, create this directory either in command prompt or using Explorer.
  • Create repositories in the svn root directories using the following commands:
    • svnadmin create c:\svnroot\test1
    • svnadmin create c:\svnroot\test2
    subversion_apache_repo_create.jpg

Apache server

Now, we can install the Apache server.
When the installation is finished, go to the bin directory within the Subversion installation, find two files with extension *.so, and put them into the(Apache)/modules directory. The files are mod_authz_svn.so and mod_dav_svn.so.
Go to the conf sub-directory within the Apache installation directory and open the httpd.conf file in any text editor.
Add the following lines:
 Collapse
LoadModule dav_module modules/mod_dav.so
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
After that, add the following block:
 Collapse
<Location /svn/>
    DAV svn
    SVNParentPath c:/svnroot/ #specify the root for repositories
    #http://www.archivesat.com/CVS_developers_help/thread45479.htm 
        post which discuss why you need to specify /svn/ and not /svn
    
    #list repositories
    SVNListParentPath on 
    # our access control policy
    AuthzSVNAccessFile bin/apachesvnauth #authentication file 
                   #path where policy is written for each user   

    AuthType Basic #type of authentication
    AuthName "Subversion repository" #the name of the authentication 
                                      #and the name of repository realm
    AuthUserFile bin/apachesvnpasswd #the name of the 
                                      #file with user passwords values
    Require valid-user #permit to log-in only for authorized users
</Location>
  • <Location /svn/> - if you type in your browser something like this: http://localhost:8080/svn/, then Apache will know how to find your root repository usingSVNParentPath.
  • SVNParentPath c:/svnroot/ - specify the root for the repositories.
  • SVNListParentPath on - permit to see the list of repositories using http://localhost:8080/svn/.
  • AuthzSVNAccessFile bin/apachesvnauth - authentication file path where the policy is provided for each user. The file is stored in the bin sub-directory of Apache.
  • AuthType Basic - the type of authentication.
  • AuthName "Subversion repository" - the name of the authentication and the name of the repository realm.
  • AuthUserFile bin/apachesvnpasswd - the name of the file with user password values, stored in the bin subdirectory of the Apache installation.
  • Require valid-user - permit to log-in only for authorized users.

Building the password file

We use the AuthUserFile bin/apachesvnpasswd entry, which tells Apache to find the file with passwords in the bin sub-directory within the Apache installation directory. We need to build this file. Go to that directory using the command prompt and type the following command:
 Collapse
htpasswd.exe -c apachesvnpasswd user1
You will be prompted to enter the password for user user1, and the file apachesvnpasswd will be created in the bin sub-directory. In order to add another user, just type the same command without -c and provide the name of another user.
 Collapse
htpasswd.exe -c apachesvnpasswd user2
Note: only the users we created will be able to log into our repositories because we used the Require valid-user parameter.

Building the authentication file

The following block is an example of the authentication file:
 Collapse
[/] * = r [test1:/] user1 = rw user2 = [test2:/] user1 = r user2 = rw

Explanations

  • [/] * = r - gives access to everyone to read all the repositories
  • [test1:/] - gives read and write permissions to user1 for repository test1, and user2 can not read or write
  • [test2:/] - user1 can read from repository test2, and user2 has full access rights

Run Apache

Theoretically, we are at the stage when we can run Apache and test our Subversion. So start Apache, open the web browser and write something like this:http://localhost:8080/svn/.
If you don't get any errors, you will be prompted to type the username and password.
subversion_apache_username.jpg
Provide the username you created and the password, and press OK. You will see the following page:
subversion_apache_repo_list.jpg

References