Thursday, 30 November 2017

How to check system information on CentOS Linux from CLI

To check the system information of CentOS Linux from command line interface, the following commands will come in handy.

cat /proc/cpuinfo

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 45
model name      : Intel(R) Xeon(R) CPU E5-4620 0 @ 2.20GHz
stepping        : 2
microcode       : 0x710
cpu MHz         : 2200.000
cache size      : 16384 KB
physical id     : 2
siblings        : 1
core id         : 0
cpu cores       : 1
apicid          : 2
initial apicid  : 2
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 popcnt aes xsave avx hypervisor lahf_lm ida arat pln pts dtherm
bogomips        : 4400.00
clflush size    : 64
cache_alignment : 64
address sizes   : 40 bits physical, 48 bits virtual
power management:

To check the memory details use the following :

vmstat -s

 3883788 K total memory
      3758516 K used memory
      2232252 K active memory
      1263620 K inactive memory
       125272 K free memory
            0 K buffer memory
       259872 K swap cache
      8191996 K total swap
      3114568 K used swap
      5077428 K free swap
    411521845 non-nice user cpu ticks
        23449 nice user cpu ticks
    116773236 system cpu ticks
   5900085167 idle cpu ticks
      1174004 IO-wait cpu ticks
         1058 IRQ cpu ticks
      7376135 softirq cpu ticks
            0 stolen cpu ticks
    234643114 pages paged in
    380977726 pages paged out
      3875967 pages swapped in
      4295358 pages swapped out
    948364036 interrupts
   1524453860 CPU context switches
   1479654445 boot time
    130969946 forks

You could also use an alternative command :

cat /proc/meminfo

MemTotal:        3883788 kB
MemFree:          119860 kB
MemAvailable:      89684 kB
Buffers:               0 kB
Cached:            64528 kB
SwapCached:       455596 kB
Active:          2526176 kB
Inactive:         993336 kB
Active(anon):    2503132 kB
Inactive(anon):   954552 kB
Active(file):      23044 kB
Inactive(file):    38784 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       8191996 kB
SwapFree:        4795948 kB
Dirty:                96 kB
Writeback:             0 kB

Listing repositories in CentOS Linux

In CentOS and Red Hat flavors of Linux, if we want to list all the configured repositories, we need to use the following command.

yum repolist

This will list information with columns like repo id, repo name, status.

Use the verbose mode with the -v switch for more detailed information.

yum -v repolist

For listing only enabled and/or disabled repositories, use the following syntax

yum repolist enabled

OR

yum repolist disabled

For listing all of the repositories (i.e enabled and disabled), use :

yum repolist all

Now, from the list of of all configured repositories, if we want to disable/enable a specific repository, use the following :

yum-config-manager --disable test-repo-name.repo

OR

yum-config-manager --enable test-repo-name.repo

Hope it helps guys. Ciao!

Execute Shell in Jenkins - Update Permissions Example

Hello guys. How's it going? In today's post, let us look into an example of how to execute a shell command in Jenkins.

For illustration, let us consider a Java based project which is under IBM Clearcase source control and built using Maven on a Linux machine. Now we want to execute a bash command to update the permissions of all pom.xml files (i.e Parent pom's and Child pom's).

Check a few sample commands for reference :

find $WORKSPACE/$CLEARCASE_VIEWNAME/PROJECT_SRC_CVOB/SRC -type f -name pom.xml -exec chmod 755 {} \;

find $WORKSPACE/$CLEARCASE_VIEWNAME/PROJECT_SRC_CVOB/SRC -type f -name pom.xml -exec chmod 444 {} \;

find $WORKSPACE/$CLEARCASE_VIEWNAME/PROJECT_SRC_CVOB/SRC -type f -name pom.xml -exec chmod 777 {} \;

Hope it helps. Ciao!

Tuesday, 28 November 2017

Learn Deutsche - German nouns : Set 1

Guys, in the past few posts, we looked into a few random word sets covering most commonly used Deutsche verbs. In this post, let us look into a new word-list of proper nouns used in our daily lives. We will also mention the gender of these words i.e der (Masculine) /die (Feminine) /das (Neutral). This should aid you in remembering the same. In today's set let us look into the most common words for office supplies/stationary.


Set 1 (Stationary / Office Supplies) - 12 words :

Pencil : der Bleistift
Pen : der Kuli
Eraser : der Radiergummi
Ruler : das Lineal
Notebook : das Heft
Dictionary : das Wörterbuch
Glue Stick : der Kleibstift
Scissors : die Schere
Ink : die Tinte
Paper : das Papier
Stapler : der Hefter
Picture : das Bild

Thursday, 23 November 2017

How to enforce specific JDK for a Maven build

As you maybe aware, the Maven enforcer plugin provides the option to enforce specific rules while building a project. For instance we could enforce a specific version of JDK to be used for a build.

For instance, let us enforce the usage of JDK 1.8.0. In that case, check the configuration of maven-enforcer-plugin in your main parent POM

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce</id>
<goals>
<goal>enforce</goal>
</goals>
<phase>validate</phase>
</execution>
</executions>
<configuration>
<rules>
<requireJavaVersion>
                  <version>1.8.0</version>
                </requireJavaVersion>
</rules>
</configuration>
</plugin>

Note the <requireJavaVersion> tag used for the same. For more information, check the following link as well.

How to configure Jacoco plugin in Maven

Guys, for getting the unit test coverage report in SonarQube for code quality and analysis, let us look into how to use the Jacoco plugin for the same. In this post we'll see how to configure Maven with the Jacoco plugin. FYI Jacoco is a free code coverage tool for Java


In your main parent POM, let us enter the Sonar properties firstly, as follows :

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Sonar -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.jacoco.reportPath>${project.basedir}/target/jacoco.exec</sonar.jacoco.reportPath>
<sonar.language>java</sonar.language>
<drools.version>5.5.0.Final</drools.version> 
</properties> 

Now in the <pluginManagement> section, let us enter the configuration for the Jacoco plugin.

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.2.201409121644</version>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>

Hope it helps guys. Until next time, ciao!

Automate regular backups of SonarQube's DB using bash script

Guys, this post will be useful if you are using SonarQube for code analysis and quality control. In today's post we will look into how to automate taking regular backups of SonarQube's back-end database.


For illustration, we will use MySql DB to store SonarQube's metadata which includes analysis parameters like code smells, bugs, code coverage, unit test coverage etc. In this case we host Sonar on a linux machine, so we write a bash script to take regular backups of the MySql DB. Take a look at a simple sample script below :

#!/bin/bash
# script for taking database dump of sonar

user="root";
hostname="localhost";
db_name="sonar";
dateformat=`date +%d-%m-%y`;

mysqldump --defaults-extra-file="/usr/local/cron_scripts/.my.cnf" -u $user -h $hostname sonar | gzip > /usr/local/mysql_dumps/sonar_dump_$dateformat.sql.gz

chmod 755 /usr/local/mysql_dumps/sonar_dump_$dateformat.sql.gz

As you see, we have used mysqldump to take dump of the database, zip it, append it with the current date and store it at the said location.

Taking dumps of Sonar can be extremely useful for the purpose of importing and exporting of a Sonar instance from one machine to another without losing the analysis history.

Change default javadoc output directory in Maven

When using the Maven javadoc plugin for generating javadoc for your project, we also have the option of changing the default output directory. As you know, by default the javadoc gets created within the project-folder/target/apidocs directory.

So, when updating the location of javadoc's output directory, use the <reportOutputDirectory> tag. Consider the illustration below :

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
<reportOutputDirectory>E:\\Javadoc\${project.name}</reportOutputDirectory>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

As you see in this case we have updated the javadoc output directory to a different drive itself i.e. E:\\Javadoc\${project.name}. Kindly check this link as well for additional reference.
Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker