Friday 14 February 2014

Jenkins - Setup to schedule your repetitive scripts

What is Jenkins & when to use It?

When you have bunch of repeated jobs or scripts that you want to run, scheduled or sometimes manually triggered. Go for jenkins.


Its as easy as 

  •    Step 1: download
  •    Step 2: Install
  •    Step 3: Install Basic Plugins (optional)
  •    Step 4: Setup security
  •    Step 5: Create new job(s)
  •    Run


Jenkins is also used these days in the case of continuous integration, working with the Source Control, Review Boards, and other quality monitoring tools.


Step 1 : Download  : http://jenkins-ci.org/

Based on your environment, you can download the installer as shown below and install it.



Step 2 : Install   - Follow instructions.

  • Follow the installer instructions.
  • On Linux, firewall to be disabled if it blocks 8080 port
    service iptables off
  • After installation accessible at  http://<hostname>:8080  . Example http://localhost:8080
You will see the below screen after successful installation & start-up


Step 3 : Install  Plugins (Optional)

There are some default plugins. If you need more, pick and choose from the plugin list as shown below.



For Manual installation.
  • Download plugins from https://updates.jenkins-ci.org/download/plugins/
  • copy the *.hpi/*.jpi file into the $JENKINS_HOME/plugins directory. 
  • Restart Jenkins (many containers let you do this without restarting the container)
I picked up few extra plugins Greenballs, XShell, setenv

Step 4 : Enable Security

1. Manage Jenkins -> Configure Global Security -> Enable Security.  




2. Configure as shown in the below picture.

  1. Enable Security
  2. Save  in jenkins database with Signup Enabled. This will enable you to add users later.
  3. Add privileges for admin user (which you will add through signup process)
  4. anonymous will have no privileges. Admin user - Select all checkboxes



  1. 5. Save, which will take you to the Login page as shown in the next image.

3. Signup for admin user from the Login Page. 



You are done with the basic security. You can go ahead and add other privileges using the admin user that is created.

Step 5 : Create new job




The dashboard now shows the job that was created.  and can now be run to see the progress

Some special settings when running on Linux Environment.

Jenkins in linux is created as a service and can be started using service jenkins start

The service will not be able access scripts or files within /root user  Say java -jar /root/test.jar will give you permission denied, even after setting the chmod appropriately. 

To solve this problem, the sudoers file has to be edited as mentioned below and execute the command prefixed with sudo. 

sudo java -jar /root/test.jar

Changes in the sudoers file
  • requiretty to be disabled for the jenkins service.  Add the Defaults:jenkins !requiretty  afterDefaults requiretty
    • visudo .(edit sudoers files)
    • Defaults requiretty
    • Defaults:jenkins !requiretty
  • add this line jenkins        ALL=(ALL)       NOPASSWD: ALL at the end

Friday 7 February 2014

[Solution] Elasticsearch 0.90 insallation with .rpm and logging Errors

Problem : 

I downloaded the latest ES rpm and installed on centos. When tried running the script in foreground, i see that the logging is not enabled.

tried both /etc/init.d/elasticsearch -f and   /usr/share/elasticsearch/bin/ -f both. 

log4j:WARN No appenders could be found for logger (node).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.


and nothing gets logged.

Tried the following in vain : 
  • export ES_CLASSPATH=/etc/elasticsearch/logging.yml 
  • changed patch.conf, path.data in elasticsearch.yml file

But, Nothing seems to fix the logging problem

Solution:

edit /usr/share/elasticsearch/bin/elasticsearch  
give absolute paths for the home, and all files.

This file should be changed, so "any" startup of elasticsearch will work in foreground without errors


ES_JAVA_OPTS="-Des.config=/etc/elasticsearch/elasticsearch.yml -Des.path.conf=/etc/elasticsearch/ -Des.path.home=/usr/share/elasticsearch -Des.path.logs=/var/log/elasticsearch -Des.path.data=/var/lib/elasticsearch -Des.path.work=/tmp/elasticsearch -Des.path.plugins=/usr/share/elasticsearch/plugins"