Tuesday, April 12, 2016

MySQL setup on Ubuntu 14.04

Thankfully for us installation of mysql on ubuntu 14.04 is pretty straightforward:

- First do an update :

sudo apt-get update

- Then execute the install :
sudo apt-get install mysql-server

You will be prompted to enter at some point the password , so do that on the screen.

You can check whether the service is running using the following command :
sudo netstat -tap | grep mysql

To create a database or execute any command you need to access mysql prompt and provide password:
mysql -u root -p


Friday, April 08, 2016

Tomcat 8 Docker install on Ubuntu 14.04

Below are the steps for installing Tomcat 8 within a Docker container on Ubuntu 14 , in my case on Amazon Ec2.

Docker Install

You need to first follow the instructions for setting up docker :

Tomcat Install

- identify your Ubuntu instance in my case I wanted to run it with JDK 8 so first navigate to Docker Hub :


- Then choose the correct docker image version :

So this is going to be version 8.0.33-jre8

- Login to your ubuntu
- Execute the following command

sudo docker run -it --rm -p 8080:8080 tomcat:8.0.33-jre8

This will download the Tomcat 8 with JDK 8 image and start it on port 8080 .

You will be able to access your tomcat instance http://public_id_address:8080

Docker Commands

- To check which docker containers are running execute the command

sudo docker ps

You should see something like this:

CONTAINER ID        IMAGE                COMMAND             CREATED             STATUS              PORTS                    NAMES
40586996cebe        tomcat:8.0.33-jre8   "catalina.sh run"   31 minutes ago      Up 31 minutes>8080/tcp   jolly_almeida

- To stop the docker container choose the docker container id , which you find when doing docker ps :

sudo docker stop 40586996cebe

- To restart the tomcat conatiner re-execute:

sudo docker run -it --rm -p 8080:8080 tomcat:8.0.33-jre8

Installing Jenkins 2.0 on Unbuntu 14 running on Amazon Ec2

This post is really a common set of instructions to have a Jenkins War installed on a Amazon EC2 instance .

Note that another option would be to use docker but right now I want to do it from scratch first.

So the first requirement is obviously to have a Ubuntu instance running , in my case its on Amazon's awesome EC2 service.

Once you have launched your instance follow the following instructions:

Tomcat Install

- Download Tomcat 8.0.33 ( not that there might be a later version so change URL accordingly)

wget http://mirrors.ibiblio.org/apache/tomcat/tomcat-8/v8.0.33/bin/apache-tomcat-8.0.33.tar.gz

- Extract the tar.gz file in your /home/ubuntu directory

tar xvzf apache-tomcat-8.0.33.tar.gz

Now that this has been done move the tar.gz to /opt/tomcat ( create directory if not avalailable)

sudo mkdir /opt/tomcat
sudo mv apache-tomcat-8.0.33 /opt/tomcat

OpenJDK 7 install

JDK 7 is not available by default on the ubuntu EC2 image ( at least the one am using ) so you might want to installing using:

apt-get install openjdk-7-jdk

Check that it installed using

java -version

Environment Variables

Set your environment variables by doing

nano ~/.bashrc

Then appending the following at the end of the file ( Remember to change to actual location of your tomcat install )

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export CATALINA_HOME=/opt/tomcat/apache-tomcat-8.0.33

Execute the following command to take effect:
. ~/.bashrc


To test that your tomcat install is working simply do :


EC2 security

You should be able to access your tomcat instance page by going to ;


Note that you get your my_public_ip_adress from your EC2 Instances page on the Public IP column .

If you cannot access the URL try clicking on the Security Groups link on the Instances page against your instance .

Then add a TCP rule on the Inbound tab :

That should be it , not re-start or whatever required.

Note that if you do not have an elastic ip address assigned to your ubuntu EC2 instance each time you shutdown and restart the server the Public Ip address will change dynamically .

Jenkins Install

We are going to install the WAR for Jenkins 2  so simply download the WAR

wget http://mirrors.jenkins-ci.org/war-rc/2.0/jenkins.war/

However do note that you need to check what is the current war from the Jenkins 2.0 site , always use the latest version !

Shutdown your tomcat it is up:


Ok now we have downloaded Jenkins lets copy it to /opt/tomcat/webapps

sudo mv jenkins.war $CATALINA_HOME/webapps

Restart your server

Now navigate to the following location to continue with the Jenkins install


I will create another post for what is in regards to configuration of Jenkins .

Thursday, April 07, 2016

Installing OpenJDK 8 on Ubuntu 14.04

Tried to install OpenJDK 8 on Ubuntu 14.04 thought it would be as simple as doing a :

sudo apt-get install openjdk-8-jdk
but that didn't work out instead you need to do add the following repository:

sudo apt-add-repository ppa:webupd8team/java
Then execute

sudo apt-get update 

sudo apt-get install oracle-java8-installer

Optionally if you have multiple versions of the JDK then you choose which JDK should be the default one:
sudo update-alternatives --config java
Basically you choose the number and thats it.

You verify by doing :

java -version



Saturday, March 26, 2016

Keeping Ubuntu background process running after exit of ssh

At times you launch a process on ubuntu/linux e.g starting a server from your putty and the moment that you close the terminal you see that the process is killed , server down. 

I just had this on an Amazon EC2 linux instance tried a number of things like adding "&" at the end of the command which I was told would work without fail ...but turns out it didn't.

What did work was this solution from askubuntu that worked liked a charm, so am sharing it such as it can help others :


  • ssh into the remote machine
  • start tmux by typing tmux into the shell
  • start the process you want inside the started tmux session
  • leave/detach the tmux session by typing Ctrl+B and then D

Monday, February 08, 2016

JHipster Entities, JDL and how to regenerate

I have been playing around with jhipster for 1-2 days now to understand how this could help out on some of our projects. Note that I have been using jhipster on Windows 10 , basically pre-requisites is that you have installed the following :
1. npm
2. Java 8
3. maven 3

We have been using spring-boot for quite some time now on a number of different projects
 and jhipster is an interesting framework to consider on top of spring-boot to quickly setup a project which has :

  1. Security already enabled
  2. Domain layer already configured
  3. Basic AngularJS UI in place for CRUD operations
  4. Metrics information
  5. REST api
  6. Swagger integration
  7. Liquidbase integration
  8. and a host other neat features
Now everything really is based on the entities within your domain model . There are different means of Entity generation :

1. through  command line using : yo jhipster:entity NameofYourEntity 
2. or using jhipster-uml

I prefer the jhipster-uml option as its much faster for you to generate your entities rather than having to go through the command line which is error prone and more time consuming.

Assuming that you have installed jhipster properly the first thing you need to do is to install jhipster-uml using the following command :

npm install -g jhipster-uml

Now for jhipster-uml there are a basically 2 fundamental ways to use it either through:

1. UML editors such as Modelio or UML Designers
2. or using the JHipster Domain Language  (JDL)

In our case we are going to use the  JDL because  its agnostic of any UML tooling , faster and you can provide more options e.g pagination which typically you cannot do with the UML tools as they are not specific to jhipster .

1. So first things first create a directory e.g Parking ( am creating a  sample Parking app )

2. Execute yo jhipster on the directory and follow the standard questions depending on what you want  in terms of project name , packing , caching , websockets etc.., this will roughly take a good 3-5 mins to generate a project depending how fast our internet connection is to download everything , am executing this on a Windows Amazon Ec2 instance and its pretty fast 

3. Now we need to create a .jh file in the root folder which will contain our  Entities , their relationships and the options we want enabled. We will call it parking-uml.jh

4. The file content looks like the following, note that the JDL is pretty straightforward: 

-- parking-uml.jh contents-----------

entity ParkingSpace {
  name String required,
  description String  minlength(5) maxlength(50),
  expiration LocalDate

enum AvailabilityReason {

entity AvailabilitySlot {
  description String  minlength(5) maxlength(50),
  availabilityReason AvailabilityReason required,
  fromDate ZonedDateTime,
  toDate ZonedDateTime

entity BookingSlot {
  description String  minlength(5) maxlength(50),
  fromDate ZonedDateTime,
  toDate ZonedDateTime

relationship OneToMany {
  ParkingSpace{availabilitySlots} to AvailabilitySlot{parkingSpace(name)}

relationship OneToMany {
  ParkingSpace{bookingSlots} to BookingSlot{parkingSpace(name)}

paginate ParkingSpace, AvailabilitySlot, BookingSlot with pagination

service ParkingSpace, AvailabilitySlot, BookingSlot with serviceImpl


The documentation page at jhipster-uml already explains the structure of the JDL so i will not go duplicate information from there in this post , however I will explain some of the stuffs to look out for.

The options paginate and  service need to contain all the entities that share the same pagination option on the same line . For example if you wrote them with same option but on different lines for each entitiy then only the BookingSlot will have pagination within the generated AnjularJS pages , ParkingSpace will have no pagination:

paginate ParkingSpace with pagination
paginate BookingSlot with pagination

However if you have different options per entity then you need to have a line per option eg.

paginate ParkingSpace, AvailabilitySlot with pagination
paginate  BookingSlot with infinite-scroll

Also each time you define a relationship create a specific block for that relationship as shown above.

It took me some amount of time to figure this out as was not explicit within the docs.

Now we are ready to generate the Entities , navigate on command line to the root of the directory and execute :

jhipster-uml parking-uml.jh

This will go about generating a number of classes and AngularJS files .

You will see that there is a .jhipster directory which created in your root directory that contains a number of JSON files representing your entities. Do take the time to open the JSON files to  have a look at the generated data.

Running the application is then pretty straight-forward execute on command line:
mvn spring-boot:run
This will tell maven to launch an instance of the application typically at .

Entities Regeneration

Now the tricky bit is when you need to re-generate your entity classes and I spent hours trying to find the right set of actions so this is what i find works best :

1. update your .jh JDL file in our case its parking-uml.jh with your changes
2. execute a mvn clean this will delete the target directory from all previousy generated classes
3. navigate from within your root directory to src\main\resources\config\liquibase 
4. now edit the master.xml file by removing all the include tags except for  :

<include file="classpath:config/liquibase/changelog/00000000000000_initial_schema.xml" relativeToChangelogFile="false"/>

5. Now go to the changelog sub-directory and delete all xml files except 00000000000000_initial_schema.xml  .

6. We are done with our cleansing , we can regenerate entities using jhipster-uml parking-uml.jh
7. Execute  mvn spring-boot:run to start your app

You should be able to have  now a jhipster app with the updated entities .

Thursday, July 23, 2015

Docker first steps

Currently looking at implementing DevOps based solution at work and whenever you hear DevOps one of the most famous trending buzz work is Docker .

I decided to give it a try on a Windows 7  pc , basically you need to follow the tutorial to install Boot2Docker which will is simple enough in terms of just being an exe that will kick start a stripped down Linux instance on your Windows pc or Mac .

The first thing you need to do is try out this simple command:

docker run hello-world

The picture below explains syntax within the commands:
Now the first issue I got however that no Docker images were being downloaded , i just kept getting i/0 timeout errors . Figureout that something might be blocking the images being downloaded.

A simple googling provided a rapid answer that the problem had to do with Cisco Connect Anywhere , if you have it installed either you need to exit it ( and close from system tray ) or you  can follow the instructions from this stackoverflow query:


Sure enough once Cisco Connect Anywhere was closed i was able to download the image.

Sunday, April 12, 2015

Control GPIO Pins on Raspberry Pi 2 using Webiopi

I recently started working on a robot controlled with my Raspberry Pi , it is at the moment kind of rover which is attached to my Raspberry Pi through a long umbellical cord of wires. There are 2 servos to which my Raspberry Pi sends out data through an L298N H-Bridge which makes the Robot "Rover" wheels  move either backward or forward .

I managed to also write a python code to send signals to the servers which looks a bit like this :

import RPi.GPIO as GPIO
import time



Now that is great but what would have been better would be to access to the GPIO pin remotely via a REST API for example and here is where Webiopi kicks in which basically provides you a WEB and a REST interface to connect to you GPIO pins of your PI :

As a first setup you need to follow the instructions from the Webiopi install page above .

Note: that current version ,  WebIOPi-0.7.1 ,didn't work straight off with my Raspberry Pi 2 I had to do the following changes to the following c files  once the Webiopi setup was completed:

1.python/native/cpuinfo.c,change "BCM2708" to "BCM2709";
2.python/native/gpio.c, change "#define BCM2708_PERI_BASE 0x20000000" to "#define BCM2708_PERI_BASE 0x3f000000";
3.run setup.sh again.

The above solution was found from RaspberryPi forums .

Now you should be up and running after having re-run the setup for WebIOPI. You launch the server using command:

sudo /etc/init.d/webiopi start

Then you go to navigate to the following location on your PI :


Note that you can get the IP_ADDRESS_OF_YOUR_PI using ifconfig command .

To quickly test the setup navigate to :

For those pins on which servos are connected change them from IN to OUT  and click on the number corresponding to the pin to execute .


Note that WebIOPI is supported by Weaved which provides you to install a package on your Raspberry PI that allows you to control your RaspberryPi WebIOPI from anywhere as long as  you and your PI are connected to the internet .

What nice is that this is a free service and I justed it works .