Sunday, January 04, 2015

Running Glassfish 4.1 in Nova-Docker Container on RDO Juno

 This post follows up http://www.linux.com/community/blogs/133-general-linux/799569-running-nova-docker-on-openstack-rdo-juno-centos-7
 Docker image been built bellow has pre-installed  JDK 1.8 and GlassFish 4.1,
providing ssh connect to Nova-Docker container ( launched via this image ),
basically extending   rastasheep/ubuntu-sshd ([1]). It allows initialize Glassfish with JPA support manually.  Image provided by ([2]) doesn't bring up Derby database (asadmin start-database is not in CMD script && and attempt just to include this command in run.sh via my experience fails).
So Glassfish 4.1 provided by ([2]) doesn't allow to test JSF/JPA applications working with Derby Pool.

Clone https://github.com/rastasheep/ubuntu-sshd.git ([1]) :-

# git clone https://github.com/rastasheep/ubuntu-sshd.git
# cd ubuntu-sshd/14.04

******************************************
Update original Dockerfile as follows :-
******************************************

FROM       ubuntu:14.04
MAINTAINER Aleksandar Diklic "https://github.com/rastasheep"

RUN apt-get update
RUN apt-get install -y openssh-server wget tar
RUN mkdir /var/run/sshd
RUN echo 'root:root' |chpasswd
RUN sed -ri 's/^PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config

RUN wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u25-b17/jdk-8u25-linux-x64.tar.gz
RUN cp  jdk-8u25-linux-x64.tar.gz /opt
RUN cd /opt; tar -zxvf jdk-8u25-linux-x64.tar.gz
ENV PATH /opt/jdk1.8.0_25/bin:$PATH
RUN echo "export JAVA_HOME=/opt/jdk1.8.0_25" >> /etc/bash.bashrc
RUN echo "export PATH=$JAVA_HOME/bin:$PATH"  >> /etc/bash.bashrc

RUN apt-get update && \
    apt-get install -y wget unzip pwgen expect && \
    wget http://download.java.net/glassfish/4.1/release/glassfish-4.1.zip && \
    unzip glassfish-4.1.zip -d /opt && \
    rm glassfish-4.1.zip && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

EXPOSE 22 4848 8080 8181

CMD    ["/usr/sbin/sshd", "-D"]

**********************
Rebuild Image
**********************
# docker build -t rastasheep/ubuntu-sshd:14.04  .

*************************
Upload image to glance
*************************
# . keystonerc_admin
# docker save rastasheep/ubuntu-sshd:14.04 | glance image-create --is-public=True   --container-format=docker --disk-format=raw --name rastasheep/ubuntu-sshd:14.04

**********************
Launch instance
**********************
# .  keystonerc_demo
# nova boot --image "rastasheep/ubuntu-sshd:14.04" --flavor m1.small --key-name  osxkey    --nic net-id=demo_network-id Glassfish41


***********************************************************
Login to dashboard && assign floating IP via dashboard:-
*********************************************************** 
  

   *********************
   Login to container :-
   ********************

   # ssh root@192.168.1.172
   root@instance-0000003d:~# hostname
   instance-0000003d


   **********************
   Update /etc/hosts :-
   **********************   
   root@instance-0000003d:~# cat /etc/hosts
    fe00::0    ip6-localnet
    ff00::0    ip6-mcastprefix
    ff02::1    ip6-allnodes
    ff02::2    ip6-allrouters
    127.0.0.1    localhost instance-0000003d
    192.168.1.172  instance-0000003d
   ::1    localhost ip6-localhost ip6-loopback


Any next container restart requires same update of /etc/hosts via startup.sh
script.

  **********************
  Initialize server :-
  **********************
  root@instance-0000003d:/# cd /opt
  root@instance-0000003d:/opt# chown -R root:root jdk1.8.0_25
  root@instance-0000003d:/opt# cd glassfish4/bin
  ./asadmin
   asadmin> start-database
Starting database in Network Server mode on host 0.0.0.0 and port 1527.
--------- Derby Network Server Information --------
Version: CSS10100/10.10.2.0 - (1582446)  Build: 1582446  DRDA Product Id: CSS10100
-- listing properties --
derby.drda.traceDirectory=/opt/glassfish4/glassfish/databases
derby.drda.maxThreads=0
derby.drda.sslMode=off
derby.drda.keepAlive=true
derby.drda.minThreads=0
derby.drda.portNumber=1527
derby.drda.logConnections=false
derby.drda.timeSlice=0
derby.drda.startNetworkServer=false
derby.drda.host=0.0.0.0
derby.drda.traceAll=false
------------------ Java Information ------------------
Java Version:    1.8.0_25
Java Vendor:     Oracle Corporation
Java home:       /opt/jdk1.8.0_25/jre
Java classpath:  /opt/glassfish4/glassfish/lib/asadmin/cli-optional.jar:/opt/glassfish4/javadb/lib/derby.jar:/opt/glassfish4/javadb/lib/derbytools.jar:/opt/glassfish4/javadb/lib/derbynet.jar:/opt/glassfish4/javadb/lib/derbyclient.jar
OS name:         Linux
OS architecture: amd64
OS version:      3.10.0-123.el7.x86_64
Java user name:  root
Java user home:  /root
Java user dir:   /opt/glassfish4/bin
java.specification.name: Java Platform API Specification
java.specification.version: 1.8
java.runtime.version: 1.8.0_25-b17
--------- Derby Information --------
[/opt/glassfish4/javadb/lib/derby.jar] 10.10.2.0 - (1582446)
[/opt/glassfish4/javadb/lib/derbytools.jar] 10.10.2.0 - (1582446)
[/opt/glassfish4/javadb/lib/derbynet.jar] 10.10.2.0 - (1582446)
[/opt/glassfish4/javadb/lib/derbyclient.jar] 10.10.2.0 - (1582446)
------------------------------------------------------
----------------- Locale Information -----------------
Current Locale :  [English/United States [en_US]]
Found support for locale: [cs]
     version: 10.10.2.0 - (1582446)
Found support for locale: [de_DE]
.  .  .  .  .

Starting database in the background.
Log redirected to /opt/glassfish4/glassfish/databases/derby.log.
Command start-database executed successfully.

asadmin> start-domain
Waiting for domain1 to start ......
Successfully started the domain : domain1
domain  Location: /opt/glassfish4/glassfish/domains/domain1
Log File: /opt/glassfish4/glassfish/domains/domain1/logs/server.log
Admin Port: 4848
Command start-domain executed successfully.

asadmin> change-admin-password
Enter admin user name [default: admin]>
Enter the admin password>
Enter the new admin password>
Enter the new admin password again>
Command change-admin-password executed successfully.

asadmin> enable-secure-admin
Enter admin user name>  admin
Enter admin password for user "admin">
You must restart all running servers for the change in secure admin to take effect.
Command enable-secure-admin executed successfully.

asadmin> restart-domain
Successfully restarted the domain
Command restart-domain executed successfully.
asadmin> exit
Command multimode executed successfully.

root@instance-0000003d:/opt/glassfish4/bin# ./asadmin create-service
Found the Linux Service and successfully uninstalled it.
The Service was created successfully. Here are the details:
Name of the service:domain1
Type of the service:Domain
Configuration location of the service:/etc/init.d/GlassFish_domain1
User account that will run the service: root
You have created the service but you need to start it yourself.  Here are the most typical Linux commands of interest:

* /etc/init.d/GlassFish_domain1 start
* /etc/init.d/GlassFish_domain1 stop
* /etc/init.d/GlassFish_domain1 restart

For your convenience this message has also been saved to this file: /opt/glassfish4/glassfish/domains/domain1/PlatformServices.log
Command create-service executed successfully.

*********************************
Service GlassFish_domain1
*********************************

ASADMIN="/opt/glassfish4/glassfish/lib/nadmin"

case "$1" in
start)
    $ASADMIN start-domain    --domaindir /opt/glassfish4/glassfish/domains  domain1 &
    $ASADMIN start-database &
    ;;
stop)
    $ASADMIN stop-domain   --domaindir /opt/glassfish4/glassfish/domains  domain1 &
    $ASADMIN stop-databse &
    ;;
restart)
    $ASADMIN restart-domain   --domaindir /opt/glassfish4/glassfish/domains  domain1 &
    ;;
*)
    echo "usage: $0 (start|stop|restart|help)"
esac