System « Intelligrape Groovy & Grails Blogs

Archive for the ‘ System ’ Category

Git Stash : A very useful command

Tuesday, August 31st, 2010
Posted by Vivek Krishna

We have been using GitHub for version control in one of our projects and I am absolutely loving it! There are quite many advantages over a concurrent version control system like subversion.

One of the commands I found useful was the stash command. It is of use when we are working on a piece of functionality, which is not in a state to be committed, but find that there is a bug/issue in a previously committed piece of code and want to fix it before proceeding with any further development.

In that case, what we can do is issue the command

git stash save "work in progress"

Once that is done, it is a save point. Now you can revert the code for that particular branch by using the checkout command.
After fixing the issue and committing it (and pushing it) we can get back the copy on which we were working, with the command,

git stash pop

A very elegant command in what would’ve been an otherwise tedious job,

Hope this helps.

Vivek

http://in.linkedin.com/in/svivekkrishna

  • Share/Bookmark
Posted in System

Linux – Managing applications running on system start-up

Wednesday, July 14th, 2010
Posted by Himanshu Seth

Rcconf is a tool that we recently discovered. This tool allows you to manage your start-up applications easily.

We found this tool when me and my colleague Aman were trying to identify the processes that we never use but they do eat up a lot of our system resources. We found this link very useful: http://www.debianadmin.com/manage-linux-init-or-startup-scripts.html.

The other way to manage system start-up applications is as the page suggests, by using update-rc.d, but rcconf provides an interface which is easy to understand and use.

To install rcconf, run the following command on your command line:

sudo apt-get install rcconf

To run rcconf, you’ll need sudo privileges:

sudo rcconf

The application looks like :

* means that application is a part of startup
Use spacebar to uncheck the application

Save the settings and restart your linux box. I removed unused applications like postgres, tomcat, monit, bluetooth etc.

And my system does feel a bit faster :)

Regards
~~Himanshu Seth~~

http://www.IntelliGrape.com

  • Share/Bookmark
Posted in Linux, System

How to Set-up shared folder/repository between two or more users on Linux

Monday, June 14th, 2010
Posted by Himanshu Seth

We had a case where we wanted two different applications (run by different users) to be able to read and write from the same file system.
This is how we solved this problem:

  1. Create a group which these users will belong to : groupadd <GroupName>
  2. Edit user1 and user2 to be a member of this group: usermod -a -G <GroupName> user1 & usermod -a -G <GroupName> user2
  3. Create a shared directory. In our case, it had to be the document root for an Apache site. Thus we chose the location <Shared_Folder>
  4. Now we need to change the group of this folder : chgrp -R <Shared_Folder>
  5. We’ll also need to grant the group write access on this folder : chmod g+w <Shared_Folder>
  6. Now we’ll need to set the GroupID flag on this folder. For a directory, the set-groupID flag means that all files created inside that directory will inherit the group of the directory. Without this flag, a file takes on the primary group of the user creating the file. This property is important to people trying to maintain a directory as group accessible. The subdirectories also inherit the set-groupID property. (http://www.dartmouth.edu/~rc/help/faq/permissions.html)
  7. Now in your .bashrc / .bash_profile, set the umask as 002. Setting this umask ensures that all the newly created files by this user will have the permission “rw-rw-r”. Thus giving the group write permission.

Now when either of the users create any file in the <Shared_Folder>, all the users of this group will have the read/write permissions on that file. Not only this, these permissions will be on the subfolders and the files with-in that folder as well.

But, if any of these users create a file outside the <Shared_Folder>, the primary group of that file/folder will be the same as the primary group of that user. Thus files/folder only in the <Shared_Folder> are shared between these users.

This is just one of the many great abilities that Linux provides.

Hope this saves you some time.

Your feedback and suggestions are welcome.

Regards
~~Himanshu Seth~~

http://www.IntelliGrape.com

  • Share/Bookmark
Posted in Linux, System

Grails – Installation on windows machine

Wednesday, June 2nd, 2010
Posted by Vishal Sahu

Hi,

This blog is about installing Grails on windows machine.

Before installing grails, make sure that Java SDK 1.4 or higher is installed on your machine.
Set JAVA_HOME environmental variable to point to the path where you have installed Java

1. Download the grails latest version from http://www.grails.org/Download

2. Extract it on the appropriate location…say C:\grails

3. Create an environmental variable GRAILS_HOME which points to the path of installation of grails…i.e C:\grails

4. In the PATH environment variable.. point it to the /bin directory of grails i.e %GRAILS_HOME%\bin

In a nutshell, the environmental variables should be like..

JAVA_HOME = C:\Program Files\Java\jdk-1.5
GRAILS_HOME  = C:\grails
PATH  =  %GRAILS_HOME%\bin;%JAVA_HOME%\bin;

This works fine for me.


Regards
Vishal
vishal@intelligrape.com

  • Share/Bookmark
Posted in Grails, System

Embedding JBPM 4.3 in a Grails 1.2.2 Application

Friday, May 14th, 2010
Posted by Himanshu Seth

Hi,

In one of our projects, we had a requirement for using some existing Business Process Management tool. JBPM is one such tool that we are evaluating.

Our first step was to run a “Hello World” process from inside the grails application. On searching over the internet, I didn’t find any helpful article/blog on integrating JBPM inside a grails application. However, there were some very good resources on integrating JBPM with a spring application. I found Joram Barrez’s Hello World Example very helpful and was able to integrate using the following steps:

  1. Download jbpm from here.
  2. Unzip the contents and copy the jbpm.jar file to the lib directory of your application.  The exploded directory has the following files/ folders for version 4.3 :
  3. Also copy the mail.jar from the jbpm installation directory (${jbpmHome}/lib) to the lib directory of your application.
  4. Create a process descriptor file in the conf directory (helloWorld.jpdl.xml) with the following code
         <process name="helloWorld" xmlns="http://jbpm.org/4.0/jpdl">
         <start>
         <transition to="printHelloWorld"/>
         </start>
     
         <java class="com.jbpm.example.Printer" method="printHelloWorld" name="printHelloWorld">
              <transition to="CheckDate"/>
              <transition to="theEnd"/>
         </java>
     
         <end name="theEnd" />
         <state name="CheckDate">
         <transition to="printHelloWorld"/>
         </state>
        </process>
  5. Create a class in src/groovy
    package com.jbpm.example
     
    class Printer {
     
     public void printHelloWorld() {
       System.out.println("&lt;----------------&gt;");
       System.out.println("&amp;nbsp;&amp;nbsp; HELLO WORLD!");
       System.out.println("&lt;----------------&gt;");
     }
    }
  6. Create a minimal jBPM config (jbpm.cfg.xml) in the conf directory
         <jbpm-configuration>
         <import resource="jbpm.default.cfg.xml"/>
         <import resource="jbpm.tx.hibernate.cfg.xml"/>
         <import resource="jbpm.jpdl.cfg.xml"/>
        </jbpm-configuration>
  7. Create a basic Hibernate config called conf/jbpm.hibernate.cfg.xml(I’m using MySql, Still looking for a way on how to use the grails DataSource)
        <?xml version="1.0" encoding="utf-8"?>
        <!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
        <hibernate-configuration>
         <session-factory>
         <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
         <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
         <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/testJbpm?autoReconnect=true</property>
         <property name="hibernate.connection.username">username</property>
         <property name="hibernate.connection.password">password</property>
     
         <property name="hibernate.format_sql">true</property>
         <property name="hibernate.hbm2ddl.auto">update</property>
     
         <mapping resource="jbpm.repository.hbm.xml" />
         <mapping resource="jbpm.execution.hbm.xml" />
         <mapping resource="jbpm.history.hbm.xml" />
         <mapping resource="jbpm.task.hbm.xml" />
         <mapping resource="jbpm.identity.hbm.xml" />
     
         </session-factory>
        </hibernate-configuration>
  8. Create the following Spring beans is resources.groovy
    springHelper(org.jbpm.pvm.internal.processengine.SpringHelper) {
            jbpmCfg = "jbpm.cfg.xml"
    }
    processEngine(springHelper:"createProcessEngine")
  9. Now lets deploy this process. To deploy a process we will need to inject the processEngine bean
     def processEngine;

    The code to deploy this process is

    RepositoryService repositoryService = processEngine.getRepositoryService();
             repositoryService.createDeployment()
                     .addResourceFromClasspath("helloWorld.jpdl.xml")
                     .deploy();
  10. Lets start an instance of this service :
    ExecutionService executionService = processEngine.getExecutionService();
    executionService.startProcessInstanceByKey("helloWorld");

    This will execute the printHelloWorld method of the Printer class as configured in the process description file.

Hope you find this useful. We are still working on executing more complex processes and will keep posting our learnings.

Your feedback and suggestions are welcome.

Regards
~~Himanshu Seth~~

http://www.IntelliGrape.com

  • Share/Bookmark
Tags: ,
Posted in Grails, System

How to allow non-root user to start/stop Apache process on a *nix server

Thursday, May 13th, 2010
Posted by Deepak Mittal

Recently, I had to write a script to deploy a Grails application on a cluster of 7 servers without prompting for any kind of passwords. The load balancer was configured so as NOT to direct any request to the node, if the Apache process is not running on the server.

So, my script to do the deployment on all the servers one by one is very simple — (a) stop Apache (b) deploy new version of the app on Tomcat using deploy.sh script lying on the server (c)  start Apache

SERVER_IPS="10.20.30.40 10.20.30.41 10.20.30.42"
for i in `echo $SERVER_IPS`
do
     echo "Deploying on Web Host $i"
     ssh applicationUser@$i "cd; apache2ctl stop; ./deploy.sh; sleep 30; apache2ctl start"
done

The only hiccup is that the applicationUser does not have rights to start/stop Apache.  After looking around for a while, I came to know about setuid which allow users to run an executable with the permissions of the executable’s owner or group.

So, all I had to do in order to allow  applicationUser to bounce apache process is :

sudo u+s /usr/sbin/apache2
sudo u+s /usr/sbin/apache2ctl

I also had to set the trusted relationship between the production servers and my machine in order to allow password-less SSH login.

After I did the above steps, I could deploy my application to all nodes in the cluster with a single command.

-Deepak

  • Share/Bookmark
Posted in Linux, System

Apache-Tomcat integration on Ubuntu server

Wednesday, February 13th, 2008
Posted by admin

Follow the steps mentioned below to integrate Apache with Tomcat on an Ubuntu system. The steps assume that Apache and Tomcat are already installed and working fine independently.

  • Install Apache module for tomcat

sudo apt-get install libapache2-mod-jk

  • Create a file by the name “worker.properties” in /etc/apache2 directory. Sample worker.properties file below

workers.tomcat_home=/opt/servers/tomcat5.5
workers.java_home=/opt/java/jdk1.5
ps=/
worker.list=worker1
worker.default.port=8009
worker.default.host=localhost
worker.default.type=ajp13
worker.default.lbfactor=1

  • Add the following line to your site configuration file (/etc/apache2/sites-available/dellServer)

jkMount /* worker1

  • Add the following lines to the end of your /etc/apache2/apache2.conf file

LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile /etc/apache2/workers.properties
# Where to put jk logs
JkLogFile /tmp/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"

  • Share/Bookmark
Tags: ,
Posted in Linux, System