Monday, December 7, 2015

script to run puppet-lint, puppet validate, erb check and ending white space in yaml files under a git branch


#!/bin/bash
# sctipt need to be run from git repository
# cd ~/mygit && sh this_script.sh
# check you puppet code before adding it - git add .

(
# get all unstrack and staged files except one being deleted
all_files="$(git status -s|grep -v "^D "|awk '{print $NF}')"

# list all puppet files with .pp extention
all_pp_files="$(echo $all_files|tr ' ' '\n'|grep pp$)"

# TEST-1: runn puppet-lint on .pp file
if [ -z "$all_pp_files" ];then
  echo There is no pp file
else
echo -e "\nRUNNING PUPPET LINT .............................................................................................................."
for i in $all_pp_files
  do
    echo;echo "FILE : $i"
    /opt/puppet/bin/puppet-lint --with-context --with-filename --no-80chars-check $i
 done


# TEST-2: runn puppet validate on .pp files
echo -e "\nRUNNING PUPPET VALIall DATE ..........................................................................................................."
for i in $all_pp_files
  do
    echo;echo "FILE : $i"
    puppet parser --storeconfigs validate $i
 done
 fi


# TEST-3: check ruby erb template
 all_erb_files="$(echo $all_files|tr ' ' '\n'|grep erb$)"
 if [ -z "$all_erb_files" ]; then
   echo There is no erb file
 else
   echo -e "\nRUNNING ERB TEMPLATE CHECKS ......................................................................................................."
   for i in $all_erb_files
   do
      echo;echo "FILE : $i"
     /opt/puppet/bin/erb -P -x -T '-' $i | ruby -c
   done
 fi


# TEST-4: check yaml files for end of line white space
 all_yaml_files="$(echo $all_files|tr ' ' '\n'|grep yaml$)"
 if [ -z "$all_yaml_files" ]; then
   echo There is no yaml file
 else
 echo "RUNNING YAML CHECKS ......................................................................................................."
 for i in $all_yaml_files
 do
    echo;echo "FILE : $i"
    grep -n "[[:space:]]$" $i
 done
 fi

) 2>&1  | tee /tmp/validate.txt

echo Above output saved in /tmp/validate.txt
#end of script

Tuesday, November 17, 2015

git - demonstrating merge conflict management : Merge conflict - Automatic merge failed

Let us take example of Romeo and Juliet love story. They decided to write their story.


PART-1: Initial draft of Romeo and Juliet story in master branch


--All big Love stories start with a tiny story !

$ git branch
* master


--This is initial short story

$ cat >story.txt
Romeo and Juliet are writting their love story
Love is ever lasting and Life is not
Our soul had been together and will remain always
As we are not Two, we are one ...
^D
$
$ git status
# On branch master
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
#       story.txt
nothing added to commit but untracked files present (use "git add" to track)
$ git add .
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#       new file:   story.txt
#

$ git commit -m "Romeo and Juliet - our story - first draft"
[master 978e583] Romeo and Juliet - our story - first draft
 1 files changed, 4 insertions(+), 0 deletions(-)
 create mode 100644 story.txt
$ git log
* 978e583 (HEAD, master) Romeo and Juliet - our story - first draft
* 52d4c41 inital repo - commit zero
$ cat -n story.txt
     1  Romeo and Juliet are writting their love story
     2  Love is ever lasting and Life is not
     3  Our soul had been together and will remain always
     4  As we are not Two, we are one ...
$



PART-2: Romeo and Juliet - updated their stories separately


Fact is, no two people think say way, even they Love each other like Romeo and Juliet ! So, both have updated story, in their own way.

--from master branch, Romeo has created a branch

$ git checkout -b romeo_branch
Switched to a new branch 'romeo_branch'


--from master branch, Juliet create another branch

$ git checkout master
Switched to branch 'master'
$ git checkout -b juliet_branch
Switched to a new branch 'juliet_branch'
$
$ git branch
* juliet_branch
  master
  romeo_branch


--Juliet did following changes and did commit
  --On line 2, replaced 'not' with 'temporary'
  --Added a line 5 at the end of story 'World see us seprate but we do not feel so ..'

$ vi story.txt
$ git add .
$ git commit -m "Juliet - modified line 2 and added line 5"
[juliet_branch 4ffd429] Juliet - modified line 2 and added line 5
 1 files changed, 2 insertions(+), 1 deletions(-)
$ cat -n story.txt
     1  Romeo and Juliet are writting their love story
     2  Love is ever lasting and Life is temporary
     3  Our soul had been together and will remain always
     4  As we are not Two, we are one ...
     5  World see us seprate but we do not feel so ..
$


--Romeo did following change and did commit

  --On line 2, appended 'permanent' after last word 'not'
  --Added a line 5 at the end of story 'Does life have any meaning without love ?!'

$ git checkout romeo_branch
$ vi story.txt
$ git add .
$ git commit -m "Romeo - modified line 2 and added line 5"
[romeo_branch c990508] Romeo - modified line 2 and added line 5
 1 files changed, 2 insertions(+), 1 deletions(-)
$
$ cat -n story.txt
     1  Romeo and Juliet are writting their love story
     2  Love is ever lasting and Life is not permanent
     3  Our soul had been together and will remain always
     4  As we are not Two, we are one ...
     5  Does life have any meaning without love ?!



PART-3 : Conflict in story - Yep, even lovers need to know how to manage conflict !


--Understand existing commits:

$ git log
* c990508 (HEAD, romeo_branch) Romeo - modified line 2 and added line 5
| * 4ffd429 (juliet_branch) Juliet - modified line 2 and added line 5
|/
* 978e583 (master) Romeo and Juliet - our stries - first draft
* 52d4c41 inital repo - commit zero


978e583 is common ancestor - parent. From this parent, 2 child commits 4ffd429 and c990508.


--Romeo, time to time, merge stories and update master branch. Romeo, merge Juliet story on top of his own story. And, merge failed !!

$ git co romeo_branch
Switched to branch 'romeo_branch'
$ git merge juliet_branch
Auto-merging story.txt
CONFLICT (content): Merge conflict in story.txt
Automatic merge failed; fix conflicts and then commit the result.
$ git s
# On branch romeo_branch
# Unmerged paths:
#   (use "git add/rm ..." as appropriate to mark resolution)
#
#       both modified:      story.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
$
$ cat story.txt
Romeo and Juliet are writting their love story
<<<<<<< HEAD
Love is ever lasting and Life is not permanent
Our soul had been together and will remain always
As we are not Two, we are one ...
Does life have any meaning without love ?!
=======
Love is ever lasting and Life is temporary
Our soul had been together and will remain always
As we are not Two, we are one ...
World see us seprate but we do not feel so ..
>>>>>>> juliet_branch
$


--what does it mean :
   -There is no conflict in line 1 - all good
   -HEAD is pointer to branch where you are. In this care HEAD is pointing to romeo_branch
   -git says that
       --line betweeen <<<<<<< and ======= are from the file in present branch ( HEAD that is romeo_branch)
       --line between ======= and >>>>>>> are from ther branch you are mearging ( that is - juliet_branch)


--Rome dicidess to fix conflicts following way :
  -delete line <<<<<<< , ======= and >>>>>>>
  -Combine feelings of both and update line 2 as
        "Love is ever lasting and Life is not permanent, it is temporary"
   -Keep last line of both - so it will make line 5 and line 6


-- Final story after manually editing file is :

$ cat -n story.txt
     1  Romeo and Juliet are writting their love story
     2  Love is ever lasting and Life is not permanent, it is temporary
     3  Our soul had been together and will remain always
     4  As we are not Two, we are one ...
     5  Does life have any meaning without love ?!
     6  World see us seprate but we do not feel so ..
$


--Finally, commit it - new commit is 9dc72f2 - new commit have ha been created by merging Juliet's commit 4ffd429 on top of Romeo's old commit c990508

$ git status
# On branch romeo_branch
# Unmerged paths:
#   (use "git add/rm ..." as appropriate to mark resolution)
#
#       both modified:      story.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
$
$ git add .
$ git commit -m "Romeo and Juliet combined story"
[romeo_branch 9dc72f2] Romeo and Juliet combined story
$


--how does commit log looks like ?

$ git log
*   9dc72f2 (HEAD, romeo_branch) Romeo and Juliet combined story
|\
| * 4ffd429 (juliet_branch) Juliet - modified line 2 and added line 5
* | c990508 Romeo - modified line 2 and added line 5
|/
* 978e583 (master) Romeo and Juliet - our stries - first draft
* 52d4c41 inital repo - commit zero



PART-4 - Finally merge Romeo branch onto master


$ git checkout master
Switched to branch 'master'
$
$ git merge romeo_branch
Updating 978e583..9dc72f2
Fast-forward
 story.txt |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
$

--It is hassle free, Fast-forward merge
    -Fast-forward - No conflict while mearging - hence move (master) from second last line ( common ancesotor) to top line.

$ git log
*   9dc72f2 (HEAD, romeo_branch, master) Romeo and Juliet combined story
|\
| * 4ffd429 (juliet_branch) Juliet - modified line 2 and added line 5
* | c990508 Romeo - modified line 2 and added line 5
|/
* 978e583 Romeo and Juliet - our stries - first draft
* 52d4c41 inital repo - commit zero
$


--Get rid of romeo_branch and juliet_branch.

$ git branch -D romeo_branch juliet_branch
Deleted branch romeo_branch (was 9dc72f2).
Deleted branch juliet_branch (was 4ffd429).
$ git branch
* master 9dc72f2 Romeo and Juliet combined story



--Love stories have no end - so Romeo and Juliet will create a new branch from master branch and repeat this whole cycle - again and again!



Reference :  https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging

Tuesday, November 10, 2015

keytool - deleting and installing SSL certificate in java certificate store

keytool  is Key and Certificate Management Tool. It is provided by development  package e.g. java-1.6.0-sun-devel-1.6.0.85-1jpp.2.el6.x86_64

Java KeyStore file is /etc/alternatives/java_sdk/jre/lib/security/cacerts (/etc/alternatives/java_sdk is link to default java base directory e.g. /usr/lib/jvm/java-1.6.0-sun.x86_64/ ). keytool utility is used to interact with this binary keystore database file.


How to find currently installed certificate, delete a certificate and import new one



--find existing certificate alias

# keytool -keystore /etc/alternatives/java_sdk/jre/lib/security/cacerts  -list \
 -storepass changeit


--delete an exising alias

$ keytool -keystore /etc/alternatives/java_sdk/jre/lib/security/cacerts  -delete \
 -alias  -storepass changeit


--import a certificate

$ keytool -import -noprompt -trustcacerts \
 -alias  \
 -file /var/tmp/your.company.com.crt \
 -keystore /etc/alternatives/java_sdk/jre/lib/security/cacerts \
 -storepass changeit


--display details of certificate

$ keytool -list -v -keystore /etc/alternatives/java_sdk/jre/lib/security/cacerts  \
 -alias   
 -storepass changeit


(changeit - your keystore password)


Reference:

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

Monday, November 2, 2015

Extend logical drive of HP Smart Array P410i using hpacucli by adding a new SAS disk

I have an RAID5 Logical Disk. So, add a new disk of same size of existing disk. ( Note: If disk size is larger than others as in 2I:1:5 - 600 GB - only 300 GB will be used, rest is not usable)


--Add a 300GB hot plug SAS disk into one of emply bay. After few seconds, Smar Array controller -detects a new 'unassigned' disk - 2I:1:6

# hpacucli ctrl all show config

Smart Array P410i in Slot 0          (sn: 5001438013123456)

   array A (SAS, Unused Space: 0 MB)

      logicaldrive 1 (1.1 TB, RAID 5, OK)

      physicaldrive 1I:1:1 (port 1I:box 1:bay 1, SAS, 300 GB, OK)
      physicaldrive 1I:1:2 (port 1I:box 1:bay 2, SAS, 300 GB, OK)
      physicaldrive 1I:1:3 (port 1I:box 1:bay 3, SAS, 300 GB, OK)
      physicaldrive 1I:1:4 (port 1I:box 1:bay 4, SAS, 300 GB, OK)
      physicaldrive 2I:1:5 (port 2I:box 1:bay 5, SAS, 600.1 GB, OK)

   unassigned

      physicaldrive 2I:1:6 (port 2I:box 1:bay 6, SAS, 300 GB, OK)



--Add all unassigned disk in Logical Drive 1 ( logicaldrive 1 size is 1.1 TB) by specifying logical drive id

# hpacucli ctrl slot=0 ld 1 add drives=allunassigned



--Extend Smart Array Logical Drive. ( I have tested on RHEL 5.8)

# hpacucli ctrl slot=0 ld 1 modify size=max

Warning: Extension may not be supported on certain operating systems.
         Performing extension on these operating systems can cause data to
         become inaccessible. See ACU documentation for details. Continue?
         (y/n) y



--Is logical drive extended ? Yes, it is extended from 1.1 TB to 1.4 TB.

# hpacucli ctrl all show config

Smart Array P410i in Slot 0          (sn: 5001438013EDECA0)

   array A (SAS, Unused Space: 0 MB)

      logicaldrive 1 (1.4 TB, RAID 5, OK)

      physicaldrive 1I:1:1 (port 1I:box 1:bay 1, SAS, 300 GB, OK)
      physicaldrive 1I:1:2 (port 1I:box 1:bay 2, SAS, 300 GB, OK)
      physicaldrive 1I:1:3 (port 1I:box 1:bay 3, SAS, 300 GB, OK)
      physicaldrive 1I:1:4 (port 1I:box 1:bay 4, SAS, 300 GB, OK)
      physicaldrive 2I:1:5 (port 2I:box 1:bay 5, SAS, 600.1 GB, OK)
      physicaldrive 2I:1:6 (port 2I:box 1:bay 6, SAS, 300 GB, OK)



--OS will now recognize new size of disk as 1499.8 GB. Let us extend last partition to use recently added 300GB. Delete second partition and extend it in single session. It will alter partition table in MBR. Change ending secotor to new sector that is bigger than older one.
   [ CAUTION - below delete and extend operation MUST be done in single fdisk session and write operation MUST be only once at the end ]

# fdisk /dev/cciss/c0d0

Disk /dev/cciss/c0d0: 1499.8 GB, 1499830990848 bytes
255 heads, 63 sectors/track, 182344 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

           Device Boot      Start         End      Blocks   Id  System
/dev/cciss/c0d0p1   *           1          33      265041   83  Linux
/dev/cciss/c0d0p2              34      145875  1171475865   83  Linux


Command (m for help): d
Partition number (1-4): 2

Command (m for help): p

Disk /dev/cciss/c0d0: 1499.8 GB, 1499830990848 bytes
255 heads, 63 sectors/track, 182344 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

           Device Boot      Start         End      Blocks   Id  System
/dev/cciss/c0d0p1   *           1          33      265041   83  Linux

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (34-182344, default 34):
Using default value 34
Last cylinder or +size or +sizeM or +sizeK (34-182344, default 182344):
Using default value 182344

Command (m for help): p

Disk /dev/cciss/c0d0: 1499.8 GB, 1499830990848 bytes
255 heads, 63 sectors/track, 182344 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

           Device Boot      Start         End      Blocks   Id  System
/dev/cciss/c0d0p1   *           1          33      265041   83  Linux
/dev/cciss/c0d0p2              34      182344  1464413107+  83  Linux



--New End for partition is now 182344 (older was 145875 ). So partition is extended.

# fdisk -l /dev/cciss/c0d0

Disk /dev/cciss/c0d0: 1499.8 GB, 1499830990848 bytes
255 heads, 63 sectors/track, 182344 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

           Device Boot      Start         End      Blocks   Id  System
/dev/cciss/c0d0p1   *           1          33      265041   83  Linux
/dev/cciss/c0d0p2              34      182344  1464413107+  83  Linux



--Did you mess up anything ? If yes, you are gone ! Filesystems may be gone or corrupt. If file list complete sucessully, you  are out of risk now !

# ls -lR /u01



--Now, resize PV and extend LV, resize filesystem

# df -hP /u01
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/volume_grp-u01vol  783G  452G  291G  61% /u01

# pvs /dev/cciss/c0d0p2
  PV                VG         Fmt  Attr PSize   PFree
  /dev/cciss/c0d0p2 volume_grp lvm2 a-   837.81G    0

# pvresize /dev/cciss/c0d0p2
  Physical volume "/dev/cciss/c0d0p2" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized

# pvs /dev/cciss/c0d0p2
  PV                VG         Fmt  Attr PSize PFree
  /dev/cciss/c0d0p2 volume_grp lvm2 a-   1.09T 279.38G

# pvscan
  PV /dev/cciss/c0d0p2   VG volume_grp   lvm2 [1.09 TB / 279.38 GB free]
  Total: 1 [1.09 TB] / in use: 1 [1.09 TB] / in no VG: 0 [0   ]


# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "volume_grp" using metadata type lvm2

#    vgs volume_grp
  VG         #PV #LV #SN Attr   VSize VFree
  volume_grp   1   5   0 wz--n- 1.09T 279.38G

# lvextend -L +20G /dev/mapper/volume_grp-root_volume
  Extending logical volume root_volume to 21.94 GB
  Logical volume root_volume successfully resized


--Resize filesystems 

# resize2fs /dev/mapper/volume_grp-root_volume
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/mapper/volume_grp-root_volume is mounted on /; on-line resizing required
Performing an on-line resize of /dev/mapper/volume_grp-root_volume to 5750784 (4k) blocks.
The filesystem on /dev/mapper/volume_grp-root_volume is now 5750784 blocks long.

# df -hP /
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/volume_grp-root_volume   22G  1.6G   19G   8% /
#


Reference: Hpacucli Utility for Linux - All Commands Guide

http://h20565.www2.hpe.com/hpsc/doc/public/display?sp4ts.oid=435422&docId=emr_na-c03493210&docLocale=en_US

Sunday, November 1, 2015

How to find ALL available versions of a package in yum repository?


--I have 1.6.0-sun-1.6.0.45-1jpp.1.el5_9 version of java installed on my systems

# rpm -q java-1.6.0-sun
java-1.6.0-sun-1.6.0.45-1jpp.1.el5_9



--I need to downgrade or upgrade to specific version of java-1.6.0-sun. Now I need to find what i have in my repository.Simple list and search does not help here.

  --Command list       : show installed version and most recent version (for all arch).
  --Command search : shows all package matching with search string - demo, develp, src, jdbc etc.


# yum list java-1.6.0-sun
Installed Packages
java-1.6.0-sun.x86_64             1:1.6.0.45-1jpp.1.el5_9                    installed
Available Packages
java-1.6.0-sun.i586               1:1.6.0.81-1jpp.1.el5_10                   rhel-x86_64-5-oracle_java
java-1.6.0-sun.x86_64             1:1.6.0.81-1jpp.1.el5_10                   rhel-x86_64-5-oracle_java
#
#
# yum search  java-1.6.0-sun
============= Matched: java-1.6.0-sun ===================
java-1.6.0-sun.x86_64 : Sun Java Runtime Environment
java-1.6.0-sun.i586 : Sun Java Runtime Environment
java-1.6.0-sun-demo.x86_64 : Demonstration files for Sun JDK
java-1.6.0-sun-demo.i586 : Demonstration files for Sun JDK
java-1.6.0-sun-devel.x86_64 : Sun Java Development Kit
java-1.6.0-sun-devel.i586 : Sun Java Development Kit
java-1.6.0-sun-jdbc.x86_64 : Sun Java JDBC/ODBC bridge driver
java-1.6.0-sun-jdbc.i586 : Sun Java JDBC/ODBC bridge driver
java-1.6.0-sun-plugin.i586 : Sun Java browser plugin
java-1.6.0-sun-plugin.x86_64 : Sun Java browser plugin
java-1.6.0-sun-src.x86_64 : Source files for Sun JDK
java-1.6.0-sun-src.i586 : Source files for Sun JDK




--I need to use  list and search with --showduplicates  options.


# yum list   'java-1.6.0-sun' --showduplicates
Installed Packages
java-1.6.0-sun.x86_64   1:1.6.0.45-1jpp.1.el5_9     installed
Available Packages
java-1.6.0-sun.x86_64   1:1.6.0.5-1jpp.2.el5_1      rhel-x86_64-5-oracle_java
java-1.6.0-sun.x86_64   1:1.6.0.5-1jpp.2.el5_1      rhel-x86_64-server-supplementary-5
java-1.6.0-sun.x86_64   1:1.6.0.6-1jpp.1.el5        rhel-x86_64-5-oracle_java
java-1.6.0-sun.x86_64   1:1.6.0.6-1jpp.1.el5        rhel-x86_64-server-supplementary-5
      . . . . . .
java-1.6.0-sun.x86_64   1:1.6.0.25-1jpp.1.el5       rhel-x86_64-5-oracle_java
java-1.6.0-sun.x86_64   1:1.6.0.25-1jpp.1.el5       rhel-x86_64-server-supplementary-5
java-1.6.0-sun.i586     1:1.6.0.26-1jpp.1.el5       rhel-x86_64-5-oracle_java
java-1.6.0-sun.x86_64   1:1.6.0.26-1jpp.1.el5       rhel-x86_64-5-oracle_java
      . . . . . .
java-1.6.0-sun.x86_64   1:1.6.0.75-1jpp.3.el5_10    rhel-x86_64-5-oracle_java
java-1.6.0-sun.i586     1:1.6.0.81-1jpp.1.el5_10    rhel-x86_64-5-oracle_java
java-1.6.0-sun.x86_64   1:1.6.0.81-1jpp.1.el5_10    rhel-x86_64-5-oracle_java




# yum search   'java-1.6.0-sun' --showduplicates|less
================= Matched: java-1.6.0-sun ===================
1:java-1.6.0-sun-1.6.0.10-1jpp.2.el5.x86_64 : Sun Java Runtime Environment
1:java-1.6.0-sun-1.6.0.10-1jpp.2.el5.x86_64 : Sun Java Runtime Environment
1:java-1.6.0-sun-1.6.0.11-1jpp.1.el5.x86_64 : Sun Java Runtime Environment
1:java-1.6.0-sun-1.6.0.11-1jpp.1.el5.x86_64 : Sun Java Runtime Environment
      . . . . . .
1:java-1.6.0-sun-1.6.0.81-1jpp.1.el5_10.i586 : Sun Java Runtime Environment
1:java-1.6.0-sun-1.6.0.81-1jpp.1.el5_10.x86_64 : Sun Java Runtime Environment
      . . . . . .
      . . . . . .
1:java-1.6.0-sun-devel-1.6.0.10-1jpp.2.el5.x86_64 : Sun Java Development Kit
1:java-1.6.0-sun-devel-1.6.0.10-1jpp.2.el5.x86_64 : Sun Java Development Kit
      . . . . . .
1:java-1.6.0-sun-devel-1.6.0.81-1jpp.1.el5_10.i586 : Sun Java Development Kit
1:java-1.6.0-sun-devel-1.6.0.81-1jpp.1.el5_10.x86_64 : Sun Java Development Ki
      . . . . . .
      . . . . . .
1:java-1.6.0-sun-plugin-1.6.0.10-1jpp.2.el5.i586 : Sun Java browser plugin
1:java-1.6.0-sun-plugin-1.6.0.10-1jpp.2.el5.i586 : Sun Java browser plugin
      . . . . . .
1:java-1.6.0-sun-plugin-1.6.0.81-1jpp.1.el5_10.i586 : Sun Java browser plugin
1:java-1.6.0-sun-plugin-1.6.0.81-1jpp.1.el5_10.x86_64 : Sun Java browser plugin
      . . . . . .
      . . . . . .
1:java-1.6.0-sun-src-1.6.0.10-1jpp.2.el5.x86_64 : Source files for Sun JDK
1:java-1.6.0-sun-src-1.6.0.10-1jpp.2.el5.x86_64 : Source files for Sun JDK
      . . . . . .
1:java-1.6.0-sun-src-1.6.0.81-1jpp.1.el5_10.i586 : Source files for Sun JDK
1:java-1.6.0-sun-src-1.6.0.81-1jpp.1.el5_10.x86_64 : Source files for Sun JDK

Sunday, October 11, 2015

Connect Cisco VPN over CLI using Ubuntu vpn client - vpnc


Below CLI steps works nicely to connect Cisco VPN using vpnc Cisco generic client


VPN : Cisco ASA55xx
OS: Ubuntu 14.04 LTS
Client: Ubuntu generic vpnc client [3]


1-Enabled universe source on Ubuntu [2]


2-install vpnc only or network-manager-vpnc (includes vpnc)

   apt-get install network-manager-vpnc


3-Import pcf profile to vpn configuration

   pcf2vpn /tmp/your_pcf_profile.pcf >/etc/vpnc/vpn1_dc1.conf


4-check username is correct.

# cat /etc/vpnc/vpn1_dc1.conf
IPSec gateway vpn1dc1.company.com
IPSec ID my-company-token
IPSec secret
Xauth username your_name


5-Connect to vpn [1] 

# vpnc-connect /etc/vpnc/vpn1_dc1.conf
                    OR
# vpnc-connect vpn1_dc1  (just profile file name  without .conf)
Enter password for your_namei@vpn1dc1.company.com:
Connect Banner:
VPNC started in background (pid: 7422)...

#


References:
[1] http://man.cx/vpnc-connect(8)
[2] http://ubuntuhandbook.org/index.php/2013/08/install-cisco-vpn-client-ubuntu-13-04-13-10/
[3] http://packages.ubuntu.com/trusty/vpnc

Monday, September 28, 2015

Veritas Replication stopped :paused due to network disconnection (dcm resynchronization)

VVR replication stopped with below status. enabled, attached and consistent (are good sign) means, we are in state from where we can recover/resume quickly.

Status: (On Primary and Secondary both)


# vradmin -g data_dg repstatus data_rvg
Replicated Data Set: data_rvg
Primary:
  Host name:                  primary-vvr-host
  RVG name:                   data_rvg
  DG name:                    data_dg
  RVG state:                  enabled for I/O
  Data volumes:               1
  VSets:                      0
  SRL name:                   srl_volume
  SRL size:                   24.54 G
  Total secondaries:          1
Secondary:
  Host name:                  secondary-vvr-host
  RVG name:                   data_rvg
  DG name:                    data_dg
  Data status:                consistent, behind
  Replication status:         resync paused due to network disconnection (dcm resynchronization)
  Current mode:               asynchronous
  Logging to:                 DCM (contains  4567890  Kbytes) (SRL protection logging)


# vxprint -Pl
Disk group: data_dg

Rlink:    rlk_secondary-vvr-host
info:     timeout=500 rid=0.1076
          latency_high_mark=10000 latency_low_mark=9950
          bandwidth_limit=none
state:    state=ACTIVE
          synchronous=off latencyprot=off srlprot=autodcm
assoc:    rvg=data_rvg
          remote_host=secondary-vvr-host IP_addr=10.50.60.70 port=4145
          remote_dg=data_dg
          remote_dg_dgid=1397347157.35.secondary-host
          remote_rvg_version=unknown
          remote_rlink=rlk_primary-vvr-host
          remote_rlink_rid=0.1078
          local_host=primary-vvr-host IP_addr=10.20.30.58 port=4145
protocol: TCP/IP
flags:    write enabled attached consistent disconnected asynchronous dcm_logging

Possible Cause


Network disconnect between Primary and Secondary site at some point of time


Solution

CHECK VVR HEALTH


--What port VVR is using?

# /sbin/vrport
heartbeat=4145
vradmind=8199
vxrsyncd=8989
data=Anonymous-Ports
 
 
--What is daemon status ?

# /etc/init.d/vras-vradmind.sh status
VxVM VVR  V-5-4-0 VRAS daemon running: [  OK  ]
VxVM VVR  V-5-4-0 vvr_stats running: [  OK  ]
# /usr/sbin/vxstart_vvr status
VxVM VVR INFO V-5-2-3935 Using following ports:
heartbeat: 4145
vradmind: 8199
vxrsyncd: 8989
data: Anonymous-Ports
To change, see vrport(1M) command
VxVM VVR vxnetd INFO V-5-1-15103  Cannot create IPv6 socket Address family not supported by protocol
VxVM VVR  V-5-2-5942 Starting Communication daemon: [  OK  ]

 
--Are ports UP and listening on primary and secondary site ?

# netstat -nap|grep -Ew "4145|8199|8989"
  tcp        0      0 0.0.0.0:8199                0.0.0.0:*                   LISTEN      2080/vradmind
  tcp        0      0 0.0.0.0:4145                0.0.0.0:*                   LISTEN      -
  tcp        0      0 0.0.0.0:8989                0.0.0.0:*                   LISTEN      2161/in.vxrsyncd
  tcp        0      0 10.20.30.67:8199            10.20.30.57:47574           ESTABLISHED 2080/vradmind
  udp        0      0 0.0.0.0:4145                0.0.0.0:*                               -
 
 
--Are primary to secondary and vice versa remote_host ( name used for replication) are pinging?

# vxprint -Pl|grep remote_host # to find remote_host
# ping
 
 
--Are ports are reachable from primary -> secondary and secondary ->primary ?

# nc -zvw3 4145
# nc -zvw3 8199
# nc -zvw3 8989
 
 

FIX OF PROBLEM

--If above VVR health is not good, fix those issue first. 
If health is good, stop VVR on secondary node

# /usr/sbin/vxstart_vvr stop
 
--wait for 60 seconds otr so, stop VVR on Primary node
 
--start VVR on secondary node

# /usr/sbin/vxstart_vvr start
 
--wait for 60 seconds, start VVR on Primary node
 
--Check if status is connected now, it will be something below :connected resync_started

# vxprint -Pl |grep flags
flags:    write enabled attached inconsistent cant_sync connected asynchronous dcm_logging resync_started

# vradmin -g data_dg repstatus data_rvg|tail -5

  Data status:                inconsistent
  Replication status:         resync in progress (dcm resynchronization)
  Current mode:               asynchronous
  Logging to:                 DCM (contains  14461920  Kbytes) (SRL protection logging)
  Timestamp Information:      N/A


--You may required to resync rvg

# vradmin -g data_dg resync  data_rvg

--If all is good, tcpdump will show data transfer to remote site (use NIC used for replication)

# tcpdump -i ethX port 4145

--And, link status will be something like this

# vxrlink -g data_dg status rlk_secondary-vvr-host -i 1
  VxVM VVR vxrlink INFO V-5-1-12887 DCM is in use on rlink rlk_secondary-vvr-host. DCM contains 14298240 Kbytes (1%) of the Data Volume(s).


Monday, August 24, 2015

git - how to combine 2 commits into one single commit


-Say we have 2 commit 4c87195 ( It has first.txt file ) and bfa1b94 ( It has second.txt file )

$ git log
* bfa1b94 (HEAD, topic) second commit - commit-2
* 4c87195 first commit - commit-1
* 52d4c41 (master) inital repo - commit zero


-We want to combine the last 2 commits in one commit

-We need to un-index ( un-stage) both commit first.

$ git reset --soft HEAD~2
$ git s
# On branch topic
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#       new file:   first.txt
#       new file:   second.txt
#


-Then, create a new commit using un-index ( un-stage) file.

$ git commit -am "combined commit - using first and second commit
$ git log
* 6941ac6 (HEAD, topic) combined commit - using first and second commit
* 52d4c41 (master) inital repo - commit zero


-New commit 6941ac6  will have files from last 2 commits

$ git show |grep +++
+++ b/first.txt
+++ b/second.txt



Friday, July 10, 2015

kdump - installation,configuration and testing

kdump Installation


yum install kexec-tools

kdump Configuration

Configure crash save area

--Say you have a disk and create ext3 filesystem on it: /dev/sdb1

--Add following in kdump.conf

echo 'default reboot
> ext3 /dev/sdb1' >> /etc/kdump.conf

--Add crashkernel argument in default kernel entry of grub.conf

grubby --args='crashkernel=512M@16M' --update-kernel=/boot/vmlinuz-$(uname -r)

--Add folowing to sysctl

echo 'kernel.sysrq = 1' >>//etc/sysctl.conf

--reboot system
--ensure kdump is operation

service kdump status

Initiating kdump


-Ensure sysrq is enabled

cat /proc/sys/kernel/sysrq

-Initiate kdump by crashing system

echo c > /proc/sysrq-trigger

-collecting dump
Once system will reboot, mount /dev/sdb1 and you case find vmocore

127.0.01-YYYY-MM-DD-HH:MM:SS/vmcore



Reference

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/ch-kdump.html#s1-kdump-installation

Tuesday, June 9, 2015

Steps to delete a defunct nagios host from centreon mysql database

If you have deleted a Centreon host from GUI but still is shows in Centreon monitoring service status, you may need to clean up host and related services from MySQl DB.

Below is steps to delete a dead host. If select statement do not return any record, obviously, corresponding delete is not required.


# mysqld
myysql> connect centreon_status;

myysql> SELECT host_id        FROM nagios_hosts WHERE display_name LIKE '%deadsystem01%';
myysql> SELECT host_object_id FROM nagios_hosts WHERE display_name= 'deadsystem01';
myysql> SELECT *              FROM nagios_hosts WHERE display_name = 'deadsystem01';

myysql> DELETE from nagios_hosts WHERE  display_name = 'deadsystem01';


myysql> SELECT * FROM nagios_objects WHERE name1 = 'deadsystem01';
myysql> DELETE   FROM nagios_objects WHERE name1 = 'deadsystem01';


myysql> SELECT * FROM nagios_hostgroup_members WHERE host_object_id = '123456';
myysql> DELETE   FROM nagios_hostgroup_members WHERE host_object_id = '123456';


myysql> SELECT * FROM nagios_hosts WHERE host_object_id = '123456';
myysql> DELETE   FROM nagios_hosts WHERE host_object_id = '123456';


myysql> SELECT * FROM nagios_hoststatus WHERE host_object_id = '123456';
myysql> DELETE   FROM nagios_hoststatus WHERE host_object_id = '123456';


myysql> SELECT * FROM nagios_objects WHERE name1 = 'deadsystem01';
myysql> DELETE   FROM nagios_objects WHERE name1 = 'deadsystem01';


myysql> SELECT service_object_id FROM nagios_services WHERE host_object_id = '123456';
myysql> DELETE FROM nagios_services WHERE host_object_id = '123456';


myysql> SELECT * FROM nagios_servicestatus WHERE service_object_id = '$above_id';
myysql> DELETE   FROM nagios_servicestatus WHERE service_object_id = '$above_id';





Puppet : how to append a string as new item into existing array ?

What is hiera?


Hiera is simple Lightweight Pluggable Hierarchical Database. It is a key/value lookup tool for hiera_lookupiguration data. Key/value may be string, array or hash.

Using Hiera


Suppose you have a a_hiera_hash in your yaml. It has a_hiera_key in two different yaml. At one place it is string ( hiera/location/dc1.yaml ) and at another place it is array (hiera/location/dc2.yaml)

==> hiera/location/dc1.yaml

a_hiera_hash:
    a_hiera_key: item_string


==> hiera/location/dc2.yaml

a_hiera_hash:
    a_hiera_key:
        - item_one
        - item_two
        - item_three


Adding a string in a string or array returned by hiera_hash


Now, if you want to add another string 'item_string_2' at the end of a_hiera_hash, there are 2 cases:

Case-1:

system1.dc1.com - a system in DC1 - For this system, a_hiera_key will be evaluated as string.

hiera_lookup = hiera_hash('a_hiera_hash', {})
hiera_lookup['a_hiera_key'] = 'item_string'  << this is what we will get

So we need to add 'item_string_2' at the end of above string. Puppet code will look like below.

        $a_hiera_key = $hiera_lookup['a_hiera_key']
        $a_hiera_key_new = "${a_hiera_key} item_string_2"
        $a_hiera_key = $a_hiera_key_new


Case-1:

system2.dc2.com - a system in DC2 - For this system, a_hiera_key will be evaluated as array.

hiera_lookup = hiera_hash('a_hiera_hash', {})
a_hiera_hash['a_hiera_key'] = [ 'item_one', 'item_two', 'item_three' ] << this is what we will get

So, now we need to add 'item_string_2' string as a new item of above array ! (type mismatch)


There is no straight way to add string as a new item of array item ! 

1- Convert array item into space seprated string using join library function - 'item_one item_two item_three'

        $a_hiera_key = join($hiera_lookup['a_hiera_key'], ' ')


2- Add 'item_string_2' at the end of string - 'item_one item_two item_three item_string_2'

        $a_hiera_key_new = "${a_hiera_key} item_string_2"

3- Split string using space a separator to make an array using split function- [ 'item_one', 'item_two', 'item_three', 'item_string_2' ]

         $a_hiera_key = split($a_hiera_key_new, ' ')



So, puppet code will look like something this.

hiera_lookup = hiera_hash('a_hiera_hash', {})

      if is_array($hiera_lookup['a_hiera_key']) {
        $a_hiera_key = join($hiera_lookup['a_hiera_key'], ' ')
        $a_hiera_key_new = "${a_hiera_key} item_string_2"
        $a_hiera_key = split($a_hiera_key_new, ' ')
      } else {
        $a_hiera_key = $hiera_lookup['a_hiera_key']
        $a_hiera_key_new = "${a_hiera_key} item_string_2"
        $a_hiera_key = $a_hiera_key_new
      }


NOTE:
If dc1.yaml also has array (similar to dc2.yaml), hiera_has will automatically merge 2 arrays. For eacmple, if dc1.yaml array is following

a_hiera_hash:
    a_hiera_key:
        - item_dc1


Then, a_hiera_key will be merge as below.

hiera_lookup = hiera_hash('a_hiera_hash', {})
a_hiera_hash['a_hiera_key'] = [ 'item_one', 'item_two', 'item_three', 'item_dc1'] << this is what we will get

References:
https://github.com/puppetlabs/hiera (hiera)
https://docs.puppetlabs.com/hiera/1/lookup_types.html (hiera_hash)
https://docs.puppetlabs.com/references/latest/function.html (split)
https://forge.puppetlabs.com/puppetlabs/stdlib/readme (join)