Linux « Intelligrape Groovy & Grails Blogs

Posts Tagged ‘ Linux ’

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

Mysql top just like we have top command in Linux

Posted by Anuj Aneja on October 8th, 2011
Once in my grails project i was facing the problem of freeze of server.When this happens tomcat becomes unresponsive.Later on by analyzing the thread dump we found that this problem might be due to the database and tomcat communication. So as to analyse how many connection are active at mysql end we found a query.

Show processlist;

Which gives us the result as:
Output:
+—–+——+———–+———————+———+——+——-+——————+

| Id  | User | Host      | db                      | Command | Time | State | Info             |

+—–+——+———–+———————+———+——+——-+——————+

| 242 | root | localhost |      test_db    | Query   |    0 | NULL  | show processlist |

+—–+——+———–+———————+———+——+——-+——————+

The output shows how many connections are active and their properties.
But for this you need to run the query again and again to analyse the connections information. For a better experience we can use mytop  which is very easy to install and just like the top in linux, simple steps need to be followed to make it work.

Step 1:Install mytop using the following command.

anuj@intelligrape:~$ sudo apt-get install mytop
Step 2:
After installation we need make a configuration file .mysqlconfig any where
e.g
anuj@intelligrape:~$ vim .mysqlconfig
user=

pass=

host=localhost

db=db_name

delay=5

port=330

6socket=

batchmode=0

header=1

color=1

idle=1

For more option you can refer to documentation of mytop .
Step 3:
Now just need run this command to see the mysqltop working.
anuj@intelligrape:~$ mytop ~/.mysqlconfig
output:

Thats it ! Internally it runs the query “show processlist” and is very elegant for analysing mysql connections.

This helps me! Hope this helps you guys!
Anuj Aneja

Intelligrape Software

  • Share/Bookmark
Tags: ,
Posted in Grails

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

Linux trick to get your user back to sudo access while you lost your Admin password and you are with no sudo prevailages.

Posted by Anuj Aneja on February 27th, 2011

I was trying to create new user on my machine but some how i create a new user but  i commited a mistake. That is  while making a new accout i forget to make it acive by giving password. And then i make this new account as Administrator and make my old account as Desktop User. Now the old_account can’t run ’sudo’ command in and i don’t have access to my admin account.Everytime while running a sudo command it give me the error as shown below:

old_user~$sudo -s

your account is not in sudoers list So this event will be reported.

And further in Ubuntu you have root account but it not by default active in there you  can switch to the root by typing:

old_user$su -
or
old_user$sudo -s

But will ask for root password which is not activated yet.

In this situtation i found a solution which can be done by editing sudoers list or group list file stored in /etc/sudoers ,/etc/group but to edit you require root access or sudo access. Which i lost it. Now to come out safe from this fishy situation take the following step:

1. Boot the system with any  Ubuntu live cd login as ubuntu now.
2.The password for Ubuntu user is blank and it is also added to sudoers list so now you can run sudo command:

ubuntu~$sudo -s
root~$

You are logged in as root.
3. Now type the following command in order:

root~$cd  /media/(some long name of you actual installation  folder)/etc/
root-.......etc/~$chmod 777 group
root-.......etc/~$vi group

Now i put the old_username in in front of sudo option like :

sudo:x:27:old_username

And save this file.

Now the old_user can run sudo command :)
I restarted my system and run the following commands

old_user~$sudo -s
enter password of old user:
root~$adduser old_user admin

Now old_user become the part of the admin group can perform any sudo,and admin opearation.Hurray !:)
The comment and any suggestion of doing this in a better way are always welcomed.
It helps me hope this helps you cheers! :)
Thanks
Anuj Aneja
Inelligrape Software

  • Share/Bookmark
Posted in Grails

Mysql Dump multipurpose script.

Posted by Hitesh Bhatia on January 12th, 2011

Taking MYSQL dump is usual requirement in my project . And Since some of the tables in project are huge so often I have to take dumps of selected tables and often have to ignore some tables.

since we had to do it frequently in our project so I created a script  which does following for me.

  1. Takes database dump
  2. Takes dump of specified tables.
  3. Takes dump of all the tables other than specified.

Inside the script I have added variables like username and password which are required by Mysql. (So if you are using this ,you will need to change them.)

USER="username"
PASSWORD="password"
DATABASE="$1"
DUMPS="Dumps"
DUMPDIR="$DATABASE$DUMPS"
FILENAME="latest.sql"
cd;mkdir "$DUMPDIR"

if [ $# -eq 0 ]; then
	echo "Usage : <databasename> <tablename*>  # if table name(s) is specified only that/those table will be dumped"
	echo "Altername Usage : <databasename> -k <table(s)dToBeIgnored>"
	exit
fi

if [ $# -eq 1 ];then
echo "Dumping $DATABASE to  $DUMPDIR/$FILENAME"
mysqldump --user="$USER" --password="$PASSWORD" "$DATABASE" > ~/"$DUMPDIR"/"$FILENAME"
fi

COMMAND="mysqldump --user=$USER --password=$PASSWORD $DATABASE"
if [ $# -gt 1 -a $2 != "-i" ];
	then
     for i in $*
	 do
		 if [ $i != "$DATABASE" -a $i != "-i" ];then
			 $COMMAND $i > ~/"$DUMPDIR"/"$i.sql";
		 fi
	 done
fi

if [ $# -gt 2 -a $2 == "-i" ];
	then
	COMMAND2=" "
	for i in $*
	do
		if [ $i != "$DATABASE" -a $i != "-i" ];then
		COMMAND2="$COMMAND2 --ignore-table=$DATABASE.$i"
		fi
	done
	$COMMAND $COMMAND2 >  ~/"$DUMPDIR"/"$DATABASE"-"Ignored.sql"
fi

Now what this can be used in three ways -
(Note – I have named this script sqlDump and all of following examples use this name )

  1. ./sqlDump.sh databasename
    This will take a complete dump of all my tables in specified database and store it in file named latest.sql
  2. ./sqlDump.sh databasename table1 table2 … tablenN
    This will take dump of all tables specified.And will store them in file named – table1.sql , table2.sql … tableN.sql
  3. ./sqlDump.sh databasename -i table1 table2 .. tableN
    This will take dump off all the tables in database ignoring specified tables. And will store it in file named <databaseName>-Ignored.sql.

If file is executed without any arguments it will just describe its Usage
Note – All of these tables will be stored in directory named <databasename>Dumps in home directory.

(more…)

  • Share/Bookmark
Posted in Grails, Linux