System « Intelligrape Groovy & Grails Blogs

Archive for the ‘ System ’ Category

Git – No Branch

Posted by on November 30th, 2012

Recently one of my colleagues went nuts over Git, he was trying to do a git commit through his IDE, and he encountered this “detached HEAD” warning. But he ultimately did that, and when he switched to master branch, there was no other branch and his commits were not on master branch either. This is where he thougt of redoing all his work.

But I told him about ‘reflog’ command, which basically keeps track of ‘HEAD’. Looking at the output (listed below) ‘git reflog’ command made it clear that he did a checkout of old commit, Kept committing on ‘no branch’ state, and when he checked out master back.

		d41214e HEAD@{0}: checkout: moving from 7691216fc5b4491e35ceeec18e6c91c314ae4b95 to master			
		7691216 HEAD@{1}: commit: Changes to product history
		7f04320 HEAD@{2}: commit: Implemented product history
		1aec670 HEAD@{3}: checkout: moving from master to 1aec670

There was no other branch. But he remembered his commit messages which were also shown in the output of ‘git reflog’ command their respective hash codes. Now we had two ways to remedy this situation

1) We could cherry-pick both of his commits to branch master.

		git cherry-pick 7f04320
		git cherry-pick 7691216

This approach is only useful when the number of commits are less, as one has to repeat this for each commit.

2) Create a branch from last commit and merge it to master.

		git branch product 7691216
		git checkout master
		git merge product	

But this also has a drawback, when replicating this scenario, I found out that “Git is not able to do a very complex merge” in this case. I went back to month old code with checkout, and tried the same thing. But git refused to a merge.

We used first option and our work was back in master branch, but precaution is always better than cure. Now to make sure this kind of situation never comes up, always do a checkout with the branch name.

	git checkout product 1aec670

This would have altogether saved us from ‘detached State’ scenario. And also while replicating this scenario from command line, I found out that Git also gives a warning stating that “Warning: you are leaving 2 commits behind, not connected to”. So listening to Git would also have saved us the trouble.

_________________________________
Hitesh Bhatia
Mail LinkedIn,Facebook,Twitter
_________________________________
Posted in git, Linux, System

Configuration of ElasticSearch on windows machine

Posted by on September 19th, 2012

Hi,
I try to find the installation process for elasticSearch, but didn’t get a right way to install, after along search on google i got below link:

http://pastorcmentarny.blogspot.in/2011/09/how-to-install-elasticsearch-on-windows.html looked helpful but still very tricky and a lot of effort

Recently in my project, I got stuck while installing elasticsearch plugin on windows machine.
ElasticSearch is built using Java setting the JAVA_HOME environment variable.

1. Download the elasticsearch installer latest version from https://github.com/rgl/elasticsearch-setup/downloads/elasticsearch-0.19.2-setup-64-bit.exe

To run elastic, execute file : C:\Program Files\elasticsearch\bin\elasticsearch.bat
But you can easily convert it into a service that runs on startup
2. Set the PATH environment variable

PATH  = C:\Program Files\elasticsearch\bin\elasticsearch.bat
Posted in System

Sending email through command line with Mutt

Posted by on September 12th, 2012

In one of the shell scripts I was reading I saw a usage of mutt text-based command line email client. Mutt can be used to send out the emails from the production machines or any other servers where you do not have access to the browsers or UI based email clients. Sometimes it is essential to send out a particular log file to certain people for bug fixing while you are checking on the prod machine.

Here is how you can send out the emails from the Linux (at-least for most of the Debian based distributions such as Ubuntu)

  sudo apt-get install mutt

Now you can type in the following command:

 mutt -s <emailSubject> <recipientEmail> -c <ccRecipientEmail> -b <bccRecipientEmail> -a </path/to/the/attachmentFile> < </path/to/the/fileContainingTheMessage>

We can see an example here:

 mutt -s "Demo Subject Line" xyz@xyz.com -c abc@xyz.com -b blind-recipient@xyz.com -a /tmp/meetingDetails.xls < /tmp/emailBody.txt

As you can see, the -s flag is used to specify the subject line of the email and the optional flags -c and -b are used to specify the “cc” recipient and “bcc” recipient respectively. Also, -a flag is used to specify the location of the attachment file. There is one caveat regarding the -a flag i.e. -a option must be placed at the end of command line options. You can read the mutt documentation for more information on this.

This utility is a nice to know tool if you are a developer working in Linux and can use it in shell scripts when ever there is an apt use-case. You can read more about mutt and other cool things it can do by clicking here or by typing the ‘man mutt‘ command in your terminal.

Hope this helps !!

- Abhishek Tejpaul
abhishek@intelligrape.com

Posted in Linux, System

How to Set-up SSL certificates on your Linux server

Posted by on June 1st, 2012

In one of my project, I have to set-up SSL certificates for my website to make it secure, so that it could also be access via https protocol. SSL is a way to secure internet communication from your browser to a secure website. The websites using SSL will have https:// to their name.

Following are the steps to set-up SSL certificate on your server:
1. Issue Command to Generate Key: openssl genrsa -des3 -out www.MY_DOMAIN_NAME.com.key 2048.
2. Issue Command to Generate CSR(Certificate Signing Request):
openssl req -new -key www.MY_DOMAIN_NAME.com.key -out www.MY_DOMAIN_NAME.com.csr.

This command will prompt for the following X.509 attributes of the certificate:
– Country Name: Use the two-letter code without punctuation for country, for example: US or CA.
– State or Province: Spell out the state completely; do not abbreviate the state or province name, for example: California
– Locality or City: The Locality field is the city or town name, for example: Berkeley. Do not abbreviate. For example: Saint Louis, not St. Louis
– Company: If the company or department has an &, @, or any other symbol using the shift key in its name,the symbol must be spelled out or omitted, in order to enroll. Example: XY & Z Corporation would be XYZ Corporation or XY and Z Corporation.
– Common Name: The Common Name is the Host + Domain Name. It looks like “www.company.com” or “company.com”. etc.
You can skip other attributes by pressing return (or enter)

3. You can verify your CSR (Optional) Here
4. Now, At verilog site or any other site apply for test certificates and fill up the details over there, paste your www.MY_DOMAIN_NAME.com.csr file content on the request form and submit it.
5. After few minutes, You will receive an email which contains the certificate attached in its body, copy that certificate and save it as www.MY_DOMAIN_NAME.com.crt on your server. (For email,check your spam also ;) )
6. Enable MOD-SSL by Issuing Commands: a2enmod ssl
7. Now you need to update the apache config file. Open you sites apache-config file located at /etc/apache2/sites-available/YOUR_SITE_NAME. This is an XML File . Modify “VirtualHost *.80” to “VirtualHost *.443” (443 Port is used for SSL) and paste the following code inside the “VirtualHost *:443” tag.

SSLEngine on
SSLCertificateFile COMPLETE_PATH_TO_CRT_FILE (like /home/user/ssl/www.MY_DOMAIN_NAME.com.crt)
SSLCertificateKeyFile COMPLETE_PATH_TO_KEY_FILE (like /home/user/ssl/www.MY_DOMAIN_NAME.com.key)

– Note: For using both http and https protocol, copy and paste “VirtualHost *.80” tag, modify copied “VirtualHost *.80” to “VirtualHost *.443” (443 Port is used for SSL) and paste the above code inside your “VirtualHost *.443” tag.

7. You can verify your apache config, using the command: apache2ctl configtest
8. Restart apache by issuing command: /etc/init.d/apache2 restart OR apache2ctl restart

Hope it helps.

Regards,
Gautam Malhotra
gautam@intelligrape.com

Posted in Linux, System

Set-up SSL Communication between two Linux servers Using Keytool Command

Posted by on May 31st, 2012

In one of my project, My front end application runs on one server and back end application runs on another. Both application have to communicate with each other through SSL(Secure Sockets Layer). SSL is a way to secure internet communication from your browser to a secure website. The websites using SSL will have https:// to their name.

In comes the Java keytool command, which is a key and certificate management utility. Keytool is a java security tool, which is used to create and manage public keys,private keys,and security certificate. It manages a keystore (database) of cryptographic keys, X.509 certificate chains, and trusted certificates.

Using the Java keytool command you can add the certicate into your keystore as trusted certificate.

Following are the steps to perform https communication between two application on different servers:
1. Copy server1-site.crt file to Server 2.
2. Now, Import this root or intermediate CA certificate to an existing Java keystore, using the command:
    Default keystore password is changeit

keytool -import -trustcacerts -keystore cacerts -storepass YOUR_KEYSTORE_PASSWORD -noprompt -alias webAppCertificate -file www.web-app.mydomain.com.crt

3. Restart apache by issuing command: /etc/init.d/apache2 restart OR apache2ctl restart
4. Repeat, Steps 1 to 3 on server1 with server2-site.crt file.

Using the keytool command you can add , delete ,list certificate from your keystore.

Refrence: http://www.sslshopper.com/article-most-common-java-keytool-keystore-commands.html

Hope it Helps!

Regards,
Gautam Malhotra
gautam@intelligrape.com

Posted in Linux, System

Fetching File From FTP in Background With Curl.

Posted by on May 9th, 2012

Last night I had to restore file with size greater than 220GB from our backup FTP server to our main server after OS re installation.

Now I could have simply done “get” after logging into ftp out server, but that would have required my machine to stay awake all night unattended. Seems simple but everything I tried didn’t seem to work .

In comes curl, literally saved my night. With simple command written below I was able to transfer file from ftp server to local machine.

 curl ftp://name:password@server/file.tar > file.tar

And then it was piece of cake running it in background with nohup

nohup curl ftp://name:password@server/file.tar > file.tar &

Thanks to curl, me and my system were able to get good nights sleep :)

_________________________________
Hitesh Bhatia
Mail LinkedIn,Facebook,Twitter
_________________________________
Tags: , , ,
Posted in System

Multiple Bootable OS in Single USB

Posted by on April 19th, 2012

Recently I have been knee deep into Linux installations. Installing through  USB is great process, there is no hassle of CD and its faster too. But problem is first we need bootable USB. Up till now I used “Start Disk Creator”, which is bundled in Ubuntu and is great for creating bootable USB, major problem with it is that it creates single boot USB, that is If I have bootable USB for Ubuntu 11.04, it will be erased when I create a bootable stick for Ubuntu 11.10.

This was a problem for me, and I found a solution to this problem in Multisystem, which creates a single bootable USB for multiple OS.
Here are steps to install And Use Multisystem
1) Download From PenDriveLinux.com, Extract the package .. change the permission of extracted file “install-depot-multisystem.sh” to make it executable.

2) Execute this file and it’ll download some files, and complete its installation. After Its Done, lets move to actually creating Pen Drive with multiple bootable OS.

3) Run Multisystem and it’ll ask you to confirm any USB drive if inserted. Once confirmed it  should look as following images, but there would be no OS pre configured. (it shows some as I configured them, it also tells me that I have  4live CDs already configured.)
MultisystemMultisystem Home Screen
4) Click on icon at bottom in middle (Which has “Select .iso or .img “written on top of it). And Select  image file of OS for which bootable USB need to be created. It’ll again ask for password and within  less than a minute bootable will be ready.

5)Same process (step 4) can be repeated to add multiple OS to bootable USB stick.

6) It also lets you test how bootable stick will work.Just Click on “Q” button and see the magic. Below are the images of me testing ArchBang from my bootable USB.
Multisystem Boot
Archbang 1
Archbang 2

Posted in Linux, System

Forgot Root Password in Linux, How to Reset Root Password through GRUB?

Posted by on March 28th, 2012

Hi,
 
It is a major problem when we forgot our root password in linux. But don’t know how to recover it. First thought that came to mind reinstall machine. But I found a way that might help you without reinstall and save your hours. It is a interesting trick in linux to get back our root password in few minutes. I used it on ubuntu 11.10 it work fine for me. Some people might know about this method, but I thought i share with you all for those who don’t know.
 
Caution : But please don’t play with this for fun, only use it when in need.
 
Here are the steps to get back your password :
1. Reboot your system.
2. When Grub Loads, Either move arrow to stop clock/timer.
3. Select Ubuntu Kernel, and then Press ‘e’ key to open it in Edit Mode.
 

 
4. In edit mode, screen will look like this in Ubuntu…
 

 
If you see the 2nd line from bottom, that says info about kernel add ’1′ in end of command as given below,
linux /boot/vmlinuz-2.6.31.9 root=UUID=904bf39-9234 ro quiet splash 1
 
5. Then Press Ctrl + b to boot kernel in single user mode.
6. By using passwd command reset your root password,
root# passwd
New UNIX Password:
Retype UNIX Password:
passwd updated successfully
 
7. Now reboot the machine, machine will reboot with your new password.
 
I hope it helps. ;)
 
Thanks,
Tarun Pareek
tarun@intelligrape.com
http://in.linkedin.com/in/tarunpareek
More Blogs by Me

Posted in Linux, System

Sharing HTTP Session between subdomains

Posted by on March 21st, 2012

Recently, I had a usecase to share same http session between different subdomains. The idea was that if a user is logged in on “somedomain.com“, he need not to login again to go to subdomain.somedomain.com. The same http session should be usable. I started off on the wrong foot by looking into the SpringSecurity plugin, which I had been using. But, later on, I found that this is to be done by configuring the Tomcat. The solution is to configure tomcat to recongnize session cookies from the subdomains. So all it takes is to modify element tomcat/conf/Context.xml to:

 <Context sessionCookiePath="/" sessionCookieDomain=".yourdomain.com">

and you are good to go. The solution works for Tomcat version 6.0.27 and above.

Cheers,
Imran Mir
imran[at]intelligrape[dot]com

Posted in Grails, System

Increasing the connection timeout between browser and the tomcat server

Posted by on December 21st, 2011

Hi,

There is a case stuck recently in my project where i need to increase the connection timeout between browser and the server, because of the reason before the response get completed server leave the connection which result in no response. My colleague Himanshu told me to change the setting in server.xml, which help in my purpose.

To increase the connection timeout on tomcat server follow the following steps :

1. Open the file server.xml residing in tomcat6/conf/.
2. You just need to set variable connectionTimeout in it to Value in Milliseconds.(i.e 1000 milliseconds = 1 second)

For example :

File : server.xml

<Connector port="8080" protocol="HTTP/1.1"  connectionTimeout="20000" URIEncoding="UTF-8"            redirectPort="8443" />

I thought it will be useful to share, hope it helps.
 

Thanks,
Tarun Pareek
tarun@intelligrape.com
http://in.linkedin.com/in/tarunpareek

Posted in System