Linux « Intelligrape Groovy & Grails Blogs

Archive for the ‘ Linux ’ Category

Speeding up Ubuntu

Posted by manoj on December 6th, 2011

Of-late my laptop has been highly responsive …. as responsive as a sloth can be… :P
I mean you wouldn’t be expecting an Intel i5 Processor with 4GB Ram and 500GB hard disk making you go for a coffee break every time you had to build or compile your code.
I am sure many of you must have experienced some form of lag with your Ubuntu (I am using 11.10… But I did experience some form of lag with 10x series also).

So in this blog post I’ll be discussing some ways that you can follow to speed up your Ubuntu

1). Disable StartUp Apps the Smarter Way

Now when I started up StartUp Applications on a my Ubuntu 11.10 installation, all you can see are a mere 5-6 apps. Mine Actually had a whole lot more that were run at start up but are simply not shown like Yakuake, Gwibber, Desktop Sharing Sevrer, Bluetooth Manager etc. Ubuntu 11.04 was somewhat better where you could see most apps but still not all that would be let loose at startup. Using the following commands, I was able to enable all apps running at startup to be shown here.

cd /etc/xdg/autostart
sudo sed --in-place 's/NoDisplay=true/NoDisplay=false/g' *.desktop

Once that was done, restarting Startup Applications now showed all the apps that were running at startup. Just read the description once and decide whether you want to keep it at startup or not.

Startup Applications shown Initially

Startup Applications Now Showing Full List

Startup Applications Now Showing Full List

rcconf is another tool that can be used but I found this method much more comprehensive and user friendly.

2). Swappiness is inversely proportional to Happiness :D

Swappiness is a property for the Linux Kernel that decides on how often to use the swap space. Most of the laptops today are equipped with 3-4 GB of Ram. So the principle of having double the swap space w.r.t to your memory size seems a bit outdated to me. Even though there was plenty of Ram available, my OS insisted on using the swap space, which in turn decreased responsiveness.
So I then moved on to change the swappiness value(Range:0-100, Default: 60)
Since I had a decent amount of RAM that could handle almost anything that was thrown at it, I decreased the swappiness quotient to 20.
To check the current swappiness value just type the following..

 cat /proc/sys/vm/swappiness 

Next to adjust the value swappiness value open

 sudo vim /etc/sysctl.conf 

Search for vm.swappiness and to change it to a desired value.If it is not present just add it to the end of the file. 10 is the figure that is mentioned on many forums, but I decided to play a bit safe and kept it a 20. Simply restart your system for the changes to take effect.

3). Reload Swap contents to Memory

Although I felt that decreasing the swappiness quotient did work for my computer, it is still possible that your computer swaps. This can hurt the multitasking performance of your system.
I found this script that you can use to to get the swap manually back into RAM.

err="not enough RAM to write swap back, nothing done"
mem=`free|grep Mem:|awk '{print $4}'`
swap=`free|grep Swap:|awk '{print $3}'`
test $mem -lt $swap && echo -e $err && exit 1
swapoff -a && swapon -a &&
exit 0

And place it at somwehere like

  /usr/local/sbin/swap2ram.sh 

Once you execute the script, it will transfer all your swap contents back to Memory, and free up your swap space. What it essentially does is turn off  swap space forcing everything back into RAM and turning it back on.

There are many more things that you can do to tweak up the speed of your computer, though I felt these 3 steps helped me a lot.
Hope this Helps :D

Manoj Mohan
manoj(at)intelligrape(dot)com
  • Share/Bookmark
Tags: , ,
Posted in Linux, System

Installing CloneZilla on USB drive using Ubuntu.

Posted by Hitesh Bhatia on October 22nd, 2011

Clonezilla is a software that allows you to do bare metal backup and recovery.

To install Clonezilla we would need following Softwares, all of which are available freely.

  1. 7zip ( p7zip-full_9.04~dfsg.1-1_i386.deb)
  2. Tuxboot (tuxboot-linux-8 )
  3. Clonezilla (clonezilla-live-1.2.6-40-i686.iso)

Here are the steps to install CloneZilla

  1. Install 7zip required to install Tuxboot
    1. sudo dpkg -i p7zip-full_9.04~dfsg.1-1_i386.deb
    2. It would show something like
    3. (Reading database … 168886 files and directories currently installed.)
    4. Preparing to replace p7zip-full 9.04~dfsg.1-1 (using p7zip-full_9.04~dfsg.1-1_i386.deb) …
    5. Unpacking replacement p7zip-full …
    6. Setting up p7zip-full (9.04~dfsg.1-1) …
    7. Processing triggers for man-db …
    8. And Step 1 is done. 7Zip is Installed.

2. Run tuxboot

    1. By default tuxboot is not executable , change it permission to make it.
    2. chmod +x tuxboot-linux-8
    3. Run tuxboot with sudo permission
    4. sudo ./tuxboot-linux-8
    5. Set the values as shown in image

    Step 5 - Installing Clonezilla

    5.1. Select Diskimage – then in adjacent dropdown select iso
    5.2. And then select the clonezilla image ( the one you downloaded)
    5.3. Type – usb drive
    5.4. Press “OK” . And let it complete. It will ask to reboot afterwards , but you can also reboot later

3. And your clonezilla usb is ready now. You may now use it to clone systems.

_________________________________
Hitesh Bhatia
Mail,LinkedIn,Facebook,Twitter
_________________________________
  • Share/Bookmark
Posted in Linux, System

Making your own custom command for a script file which can be executed from any user.

Posted by Anuj Aneja on October 5th, 2011
One way to execute the script file via command can be making of alias and put it in .bashrc , but this will only be available to that user. So for creating a user-defined command which can be executed from any where for any user following steps need to be followed:
1. Make a script file which has the set of commands to be executed and add ‘x’ permission for all.e.g.

Here is a script file(/home/anuj/myscript/myscript.sh) which echo’s current directory on the terminal.

echo $PWD

2. Make a symbolic link  mycommand pointing to myscript.sh in /usr/bin or /sbin/ or /usr/sbin directory  (Differences between them can referred from here).

cd /sbinln -s /home/anuj/myscript/myscript.sh mycommand

Now you can use command “which” to see which file will executed if we type the command named “mycommand”


which mycommand

Output:  /sbin/mycommand

anuj@intelligrape:/tmp$ mycommand

Output:  /tmp/

Its done! :)  Next question would be where we can use it to make our life easier??. Well ! Generally we have deployment script for that we need to switch to user and then we need to run the script file instead of doing that we can make a softlink of the script file and put it in the /sbin or /usr/sbin etc. Like some software packages like apache put softlink to there script file in /sbin.e.g.  a2ensite is a softlink to a2enmode in /usr/sbin which is a executable script file.
There can be some better way to achieve the same so suggestions are most welcomed.

Hope this helps you guys !

Anuj Aneja
Intelligrape Software

  • Share/Bookmark
Posted in Linux

Find v/s Locate … Optimize your search ..

Posted by manoj on September 16th, 2011

A few days back, I was on a server wherein I had to find the location of a file in the file system. Naturally like most newbies, I instantly hit the ‘find’ command.  Something like

sudo find / -name someFileName.ext

Naturally the command took a lot of time to find the file (Local to server relay not being helpful either).
At one point it grew so frustrating that I had to stop it and search for an alternative . Thats when I met Locate.. The lesser known brother of Find, WhereIs and Grep.

As soon as i hit the command

locate someFileName.ext

BING!!!

The result popped up.. in less than a second !!!
This was a real time saving alternative. Comparing 1 sec to over 20 sec and that too over a remote server, man I could have killed for this sort of performance. Thanks to ‘locate’ for having saved me some prison time :D .

Now here’s the real thing …
Locate searches for files from a database that is created automatically. This database contains the list of files in a file system and their associated paths. So essentially locate simply searches through a file and returns a match.
Find on the other hand searches through files in the file system in real time. It’ll definitely be slower because it will search each and every path recursively from it’s start point.

Locate therefore is much faster as compared to find when searching for unique items.

But there are a few disadvantages to this method as well.

Locate might miss out on files created within a 24 hour period. This is because the database through which locate searches is updated automatically through a cron job that usually runs in 24 hour intervals. Find is the winner here … however to manually run the job for updating the database in Ubuntu, you can simply run a command

sudo updatedb

and get the job done.

Find also contains a number of filters like  specifying type -d (Directory) which aren’t present in locate.  This means that locate command for a directory would return files as well as directories. So in essence locate returns a large number of results whereas find can narrow them down.

Essentially it’s the situation that should describe which command to use. But I would still suggest you give locate a try. You would be pleasantly surprised.

Manoj Mohan
manoj(at)intelligrape(dot)com
  • Share/Bookmark
Posted in Linux

Setting System property from command line in grails

Posted by Vishal Sahu on August 24th, 2011

Hi,

In one of my recent grails project, i needed to set System property from command line while running the grails application.
I looked for it and found a simple solution to do so and found it worth sharing.


Suppose we want to set any property, say app.property=”propertyValue”, then the command to set the property in grails application would be:

  grails  -Dapp.property="propertyValue" run-app

Similarly to retrieve the value of System property, we use

String myPropertyValue= System.getProperty("app.property")

It helped me a lot..
Hope it helps


Vishal Sahu
vishal@intelligrape.com
www.intelligrape.com

  • Share/Bookmark
Tags: ,
Posted in Grails, Java tools, Linux, System

Organizing “.bashrc”

Posted by Himanshu Seth on August 17th, 2011

I have been working on Linux for almost 3 years now and have grown to love it a lot.

As with every linux user, the .bashrc file becomes cumbersome and difficult to maintain over a period of time, since there are a lot of project specific aliases, paths, etc

So after working on a couple of projects, I started maintaining separate files for my environment settings. So I just had to create a separate project setting file:

~/.myProjectSettings
alias myAlias1='cd /to/project/dir'
alias projectqa='ssh to@qa'
alias projectDb='mysql -u<username> -p<password> <project_db_name>'

So, everytime I had to add more project specific settings or separate my settings, I had to create a new settings file and then source it in my .bashrc by adding this line

. ~/.myProjectSettings

As you can guess, after doing this a couple of times, even this was becoming very tedious.

So, I tried to follow the golden rule of convention over configuration.

In my .bashrc, I added the following function :

function sourceAllMySettings(){
	FOLDER_TO_BE_SOURCED=~/.mySettings/
	for i in `find $FOLDER_TO_BE_SOURCED -type f`;
	do
		. $i
	done;
}
##don't forget to execute the function
sourceAllMySettings

and placed all my setting files into the folder :

~/.mySettings/

So, now if I have to add more settings to my .bashrc, I just create a new executable file in this folder and it gets automatically sourced.

Goodbye messy .bashrc, welcome organized (segregated) settings :)

Regards
~~Himanshu Seth~~

http://www.IntelliGrape.com

  • Share/Bookmark
Tags: ,
Posted in Linux

Mounting an EBS Volume to an Instance and Soft Linking a Growing Directory to it

Posted by Vivek Krishna on May 5th, 2011

We were having a crisis on our project the other day. The VPS on which we were running our application had some issues with kernel and Tomcat, for that matter, any java process was running unpredictably. Tomcat would explode the WAR file once in a while and even if it did, it would just pause at “Deploying app.war” forever. After spending some time troubleshooting (we didn’t know that it was an issue with the kernel), we decided to move our infrastructure to Amazon EC2. We picked up an EBS based large instance, running Ubuntu and copied the setup from our production server to this new machine. The setup was a breeze, thanks to the scripts we already had in place for migrating our production setup to our QA machines for testing purposes.

However, we realized that Image Magick, which was being used from our application was not working as expected. In fact, it wasn’t working at all. We noticed that we were able to perform it as root, but not as any other user. The error which showed up was that there was lack of disk space. Static documents generated by our application were stored on the file system and it was meant to be an ever expanding directory. The EBS instance we had chosen had a capacity of just 8GB and about 6 GB of that was being occupied by the OS and the rest of our infrastructure. We decided to move this particular directory to a new EBS volume.

This could be accomplished smoothly, thanks to the ease of attaching a new EBS volume to an instance. We added a new volume and then, performed the following steps to move this particular expanding directory.


mke2fs -F -j /dev/sdh #This is to create an ext3 file system for the device attached at /dev/sdh

mkdir /path_to_new_file_system

mount /dev/sdh /path_to_new_file_system #mount the new file system at this directory

cp -r static_documents_location /path_to_new_file_system #Copy the files from the existing directory to the new directory

mv static_documents_location static_documents_location_backup #Backup the existing documents, just in case anything goes wrong

ln -s /path_to_new_file_system/static_documents_location static_documents_location #Create a soft link to refer to the new file location with the same name as the previous one

With these steps, we were good to go on the Amazon machine without even requiring a Server restart. We were expecting a downtime of at least 10 minutes but this happened so flawlessly.

Hope this helps someone.

  • Share/Bookmark
Posted in Database, Linux, System

byobu: screen sessions in Linux

Posted by Salil on April 13th, 2011

This post is just to talk about Screen Sessions in Linux (esp. ubuntu) using command “byobu”.

 

What is Byobu?
Byobu is a Japanese term for decorative, multi-panel screens. As an open source project, Byobu is an elegant enhancement of plain GNU Screen.

 

Where can it be used?
You SSH to some remote machine and Run some commands (application, service, etc). Now you want to logout of ssh session. But want your screen turned-on, so that you just resume it, the next time you access the machine.

 

How to use it?
It’s as simple as 2 steps process.

Step 1: Enter command "byobu"
Step 2: Press F2 (to create a new screen)

here you go!

 

Now you are in a detachable screen session. Enter your commands. And once you done –

Press F6 (to detach the screen)

If you are already logged-into some remote machine (using ssh), now you can logout. And your screen will remain there.
Then, when you come back — you can resume your screen back by following commmand

$ screen -r

It’s good to read about other options (like, screen -x)

 

Your comments are always Welcome. Please post if you have any!

 

Cheers!
Salil Kalia
Salil [at] IntelliGrape [dot] com
Twitter LinkedIn

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

GNOME GUI Integration w.r.t IDEA GUI Launcher

Posted by Kushal Likhi on February 13th, 2011

One of the important part of any Installer is integrating and defining launchers for GUI. This post will demonstrate adding entries in menu bar and panel, using scripts in context of creating a GUI launcher for IDEA IDE.

currently IDEA does not come with any GUI Launcher but this does not mean that we cant have one. How cool it would be if we had an icon on the top panel to launch IDEA in Terminal mode.

IDEA LAUNCHER IN PANEL ->


Similarly an entry is also created in menu: application->programming->Idea
Download: idea_desktop_Integration.tar.gz Check the installation guide below to see how to install

PROBLEM STATEMENT:
A program will be created to do IDEA GNOME GUI Integration, which launches IDEA in TERMINAL such that we can see whats happening in the background, that too with the ease of GUI one click quick launch. It requires following subtasks:

  1. Building Launch Environment for idea.sh: idea.sh is designed to launch in terminal with all PATH variables set for various SDK’s. if we try to launch it in a standalone terminal it will not work as environment is required. In this step we will generate the launch environment
  2. Adding Menu Bar Entry: in this we will add an entry to menu: application->programming->Idea using scripts, automated.
  3. Adding entry to panel: here we will add an entry for launcher in the quickLaunch panel on top of the screen.

Building Launch Environment
whenever terminal is launched it runs the .bashrc file which have the PATH variables to be set.
but we cant execute .bashrc in standalone terminals i.e terminals with no command point as GUI always launches applications in standalone terminals.
so the other option is:- extract all the PATH variables from .bashrc and create your own setup script for the terminal.
this can be achieved by simple commands:-

grep "export" ~/.bashrc |tee ~/.IDEALauncher

this will extract all exported variables and make a file containing all of them in the home folder with the name .IDEALauncher
and we can execute this script to set the path via command:

chmod 777 ~/.IDEALauncher
. ~/.IDEALauncher

Now it has set all the path variables needed for the launch.

the above mentioned task is stored in a file klaunch.sh and is the launcher start point. file is as follows:
Note: UI and echo’s have been removed here to make it more readable, in attached file lot other stuff is there.

# IDEA Launcher Script for gnome desktop integration.
# By Kushal Likhi

#GET settings of enviornment variables and create a shell script for those
grep "export" ~/.bashrc |tee ~/.IDEALauncher

#set enviornment variables
chmod 777 ~/.IDEALauncher
. ~/.IDEALauncher

#launch IDEA
`idea.sh`

Setup Process
adding menu bar entries and panel entries is a part of setup process and is as follows:

“Everything in LINUX is a file”

yes, and using the above saying all we have to do is: create/edit/add some files
FOR Menu Entry we have to create a file: /usr/share/applications/idea.desktop and update cache to be safe
the Script is as follows for the setup file:

#IDEA Desktop integration setup file
# (c) Kushal Likhi
#Ver 1.0

#clear screen for good clean looks
clear

#welcome message
echo "-------------------WELCOME----------------------"
echo ""
echo " SETUP Program for IDEA GNOME Integration"
echo " by: kushal likhi"
echo ""
echo "------------------------------------------------"

#read IDEA installation dir path
echo ""
read -p "Enter IDEA Bin Location, press enter to keep default(/opt/idea/bin/), note: end path with '/':" ideahome

if [ -z "$ideahome"]
then
	ideahome=/opt/idea/bin/
else
	echo "path set!"
fi

echo ""
echo "Path set to: "$ideahome 

#copy files
echo ""
echo "Generating launcher...."
sudo cp -fv klaunch.sh $ideahome
echo ""
echo "copying Icons...."
sudo cp -fv icon.png $ideahome
echo ""

#add menu entries
echo "checking for /usr/share/applications"

if [ -d "/usr/share/applications" ]
then
#found cache file
echo "found"
echo "Adding Entries...."

#NOTE: echo here is used to create files, NOT display on console, '>' creates a file, and '>>' appends to it.
sudo echo "[Desktop Entry]" > /usr/share/applications/idea.desktop
sudo echo "Type=Application" >> /usr/share/applications/idea.desktop
sudo echo "Encoding=UTF-8" >> /usr/share/applications/idea.desktop
#sudo echo "Version 1.0" >> /usr/share/applications/idea.desktop
sudo echo "Name=IDEA IDE" >> /usr/share/applications/idea.desktop
sudo echo "Comment=Launcher for IDEA by Kushal" >> /usr/share/applications/idea.desktop
sudo echo "Categories=Development;" >> /usr/share/applications/idea.desktop
sudo echo "Exec="$ideahome"klaunch.sh" >> /usr/share/applications/idea.desktop
sudo echo "Icon="$ideahome"icon.png" >> /usr/share/applications/idea.desktop
sudo echo "Terminal=true" >> /usr/share/applications/idea.desktop
echo ""
echo "updating /usr/share/applications/desktop.en_US.UTF8.cache"
sudo echo "[idea]" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "Name=IDEA IDE" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "Comment=Launcher for IDEA by Kushal" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "Categories=Development;" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "Exec="$ideahome"klaunch.sh" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "Icon="$ideahome"icon.png" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "Terminal=true" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "Type=Application" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "" >> /usr/share/applications/desktop.en_US.UTF8.cache
echo ""
echo "adding pannel entry......"

#/usr/lib/gnome-panel/gnome-panel-add --launcher=/usr/share/applications/idea.desktop
chmod 777 panel

bash ./panel

echo ""
echo "Menu set..... Enjoy!!"
echo ""
echo "------> YOU WILL FIND ENTRY IN (Applications -> Programming) MENU"
echo ""
echo "NOTE: Run command ./panel to add panel entry explicitly. was unable to add panel in sudo mode"
else
# file not found
echo "ERROR! Does not exist! this setup works for GNOME only"
exit 1
fi

now here we have added menu entry.

Adding Panel Entry:
Ubuntu has made this task easy by providing us with a python script to manipulate panels.
so all we have to do is use that script.. :D
so the code is as follows for the panel file:-

echo "adding panel......"
/usr/lib/gnome-panel/gnome-panel-add --launcher=/usr/share/applications/idea.desktop --panel=top_panel_screen0
echo "panel entry added... "

you can also add to the bottom panel with the switch –panel=bottom_panel_screen0 , now the launch button will appear next to show desktop icon at the botton left corner.
we can also align them to left or right, all is documented in the script usage guide.

Installation Guide
installation is very simple, just follow the following steps:

  1. STEP 1: Download the files: idea_desktop_Integration.tar.gz
  2. STEP 2: Extract the files to a directory.
  3. STEP 3: go in the root of the extracted files and issue command
    sudo ./setup
    

    then when asked enter idea path if it is different from the mentioned, if its same as mentioned just press enter.

  4. STEP 4: issue command:
    ./panel
    

    this has to be issued seperate because the ubuntu script for panel does not work in sudo mode

  5. STEP 5: all set Enjoy!! now whenever you have to launch IDEA just click on the icon and it will launch gracefully

~~Kushal Likhi~~
http://www.intelligrape.com

  • Share/Bookmark
Posted in Linux, System

Git – Grep

Posted by Hitesh Bhatia on January 22nd, 2011

Still in my early days of using Git. Recently just to make sure that I have merged two branches  and have pushed changes to QA server successfully,I often used command “find | xargs grep” .But to deal with this kind of situations Git provides “grep” command. Just as name suggests this commands searches for regex pattern passed to it.

 git grep "regex" 

Example – To find usage of word “collections”  in each file.

 git grep --ignore-case "collections"

output :

ReadMe.txt:groovy Collections
ReadMe.txt:nice collections

Now this just described which of project files have word ‘list’ in it and how many times.One can also use -c option to count occurrences  of word “collections”

git grep --ignore-case -c "collections"

Output:

ReadMe.txt:2
Now a question  why I am not using command (and favoring “git grep”)
find | xargs grep -y "collections"
which will easily do the same for me and would perhaps list some extra  files (which are not exactly part of my app). Now here come the answer with “git grep” I can also search in previous versions of my project.
Example
git grep --ignore-case  "collections" ea145f1
output :
 ea145f1:ReadMe.txt:groovy Collections
It searches for word “collections” in my previous commits . (As second line in file ReadMe.txt was added after commit numbered ea145f1) .Simply awesome.And this is  not it.  To explore more visit. git grep manual page or the git community book which is maintained by Scott Chacon
_________________________________

Hitesh Bhatia

Mail,LinkedIn,Facebook,Twitter

_________________________________

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