Oracle DB startup details

After installing Oracle DB 11g R2, we have to create a BD using :

$ dbca

If you don’t have (yet) the environment variables, you have to create at .bash_profile :

ORACLE_BASE="/home/oracle/Oracle/angellore/"
ORACLE_HOME="/home/oracle/Oracle/angellore/product/11.2.0/dbhome_1/"
ORACLE_SID="soa"
ORACLE_HOME_LISTNER=LISTENER

After creating the database we have to configure the listener to allow TCP connections :

$ netmgr

After NetManager opens, go to Oracle Net Configuration > Local > Listeners > LISTENER and provide the SID as you defined in the DB creation steps. Save the configuration and close the NetManager.

After that, we have to start the listener as :

$ lsnrctl start && dbstart

Automatic statartup script

Depending on your system, you have to create script at startup scripts; we can create (on Fedora/RedHat) the script /etc/init.d/oracle as :

#!/bin/sh
#
# /etc/rc.d/init.d/oracle
# Description: Starts and stops the Oracle database, listeners and Enterprise Manager
# See how we were called.
case "$1" in
start)
echo "Starting Oracle"
echo -n "Starting Oracle Databases: "
su angellore -c dbstart >> /tmp/oracle.log
echo "Done."

echo -n "Starting Oracle Listeners: "
su angellore -c "lsnrctl start" >> /tmp/oracle.log
echo "Done."

echo -n "Starting Oracle Enterprise Manager: "
su angellore -c "emctl start dbconsole" >> /tmp/oracle.log
echo "Done."
touch /var/lock/subsys/oracle
;;
stop)
echo "Shutting Down Oracle"
echo -n "Shutting Down Oracle Enterprise Manager: "
su angellore -c "emctl stop dbconsole" >> /tmp/oracle.log
echo "Done."

echo -n "Shutting Down Oracle Listeners: "
su angellore -c "lsnrctl stop" >> /tmp/oracle.log
echo "Done."

rm -f /var/lock/subsys/oracle
echo -n "Shutting Down Oracle Databases: "
su angellore -c dbshut >> /tmp/oracle.log
echo "Done."
;;
*)
echo "Usage: oracle {start|stop|restart}"
esac

Finally, in /etc/oratab we have to tell oracle that out instance has to be started up at boot time :

# This file is used by ORACLE utilities. It is created by root.sh
# and updated by the Database Configuration Assistant when creating
# a database.

# A colon, ‘:’, is used as the field terminator. A new line terminates
# the entry. Lines beginning with a pound sign, ‘#’, are comments.
#
# Entries are of the form:
# $ORACLE_SID:$ORACLE_HOME::
#
# The first and second fields are the system identifier and home
# directory of the database respectively. The third filed indicates
# to the dbstart utility that the database should , “Y”, or should not,
# “N”, be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
oracle:/home/angellore/Oracle/angellore/product/11.2.0/dbhome_1:Y
soa:/home/angellore/Oracle/angellore/product/11.2.0/dbhome_1:Y

If you have problems with the shared memory at startup time, you have to create more shared memory space as :

$ mount -t tmpfs shmfs -o size=4g /dev/shm && echo "shmfs /dev/shm tmpfs size=4g 0" >> /etc/fstab

Weblogic NodeManager issues

After installing Weblogic Server on many machines in order to create a cluster, we need to create a template in our AdminServer, after that, we have to make a template in order to transfer it to the rest of the servers. There are another way to do this, but I’ll leave this for other post.

Create the template

$ ~/Oracle/Middleware/wlserver_10.3/common/bin/pack.sh -managed=false -domain=../maleficarum/ -template=maleficarum.jar -template_name="maleficarum"

Once the template is created, we have to transfer it to the other ManagedServer via ssh, and then, restore the template:

$ ./Oracle/Middleware/wlserver_10.3/common/bin/unpack.sh -template=maleficarum.jar -domain=./Oracle/Middleware/user_projects/domains/maleficarum

After the replication of the template, we have to tart our AdminServer and enroll out managed server using WSLT :

$ cd ~/Oracle/Middleware/wlserver_10.3/common/bin
$ ./wlst.sh
Initializing WebLogic Scripting Tool (WLST) ...

wls:/offline> connect('weblogic','weblogic','t3://adminserver:7001')

wls:/maleficarum/serverConfig> nmEnroll('/home/usuario/Oracle/Middleware/user_projects/domains/maleficarum','/home/usuario/Oracle/Middleware/wlserver_10.3/common/nodemanager')

Enrolling this machine with the domain directory at /home/usuario/Oracle/Middleware/user_projects/domains/maleficarum ...
Successfully enrolled this machine with the domain directory at /home/usuario/Oracle/Middleware/user_projects/domains/maleficarum.

exit()

This will registrer out NodeManager in the cluster, and creates all the needed files; As first parameter pass the domain root directory and the second one is the nodemanager location.

Starting nodemanger

$ cd ~/Oracle/Middleware/wlserver_10.3/common/nodemanager
$ ./startNodeManager.sh

If we get the error “Native version is enabled but nodemanager native library could not be loaded“, we can edit the nodemanager.properties file as :

$ cd Oracle/Middleware/wlserver_12.1/common/nodemanager/
$ cat > nodemanager.properties
$ NativeVersionEnabled=false

From AdminServer console we now start all servers (domain > environment > servers > ManagedServer1 > control)

Restfull Groovy Service with Restlet

Looking for lightweight solution for my raspberry-pi, found Restlet; a framework that allows groovy (and java) programmers to implement restfull services without a servlet container or application server.

In this example, we’ll write a small app that routes the requests based on the URL requested pattern; for this, we’ll write two files:

MainApplication.groovy

import mx.maleficarum.Status
import org.restlet.Application
import org.restlet.Component
import org.restlet.Restlet
import org.restlet.data.Protocol
import org.restlet.routing.Router

Application application = new Application() {

public synchronized Restlet createInboundRoot() {
Router router = new Router(getContext());
router.attach(“/sample/status”,Status.class );
return router;
}
};

Component component = new Component()
component.getServers().add(Protocol.HTTP, 8080)
component.getDefaultHost().attach(application);
component.start()

This class is the entry point for the application, defining a router for each URL pattern and defining the port-protocolo for our HTTP server.

Status.groovy

package mx.maleficarum

import org.restlet.data.MediaType
import org.restlet.representation.Representation
import org.restlet.representation.StringRepresentation
import org.restlet.resource.Get
import org.restlet.resource.ServerResource

class Status extends ServerResource {

@Get
public Representation doGet(){
def msg = “This is our status message!”
return new StringRepresentation(“{\”message\”:${msg}\”}”, MediaType.APPLICATION_JSON);
}
}

This class is the handler for the URL http://localhost:8080/status, and just returns a JSON message.

Finally we shall run the script as :

groovy -classpath ../lib/org.restlet.jar mx/maleficarum/RestletApplication.groovy

We just need to add to classpath org.restlet.jar.

Weblogic Spring Console

Oracle Weblogic 12c, now includes a spring console to monitoring all spring beans enabled applications. In order to activate this feature you have to follow the next steps.

Activate spring console extension

  • In the preferences panel, extensions tab, select spring-console, using the checkbox, and click ‘Enable’.
  • Restar Weblogic to activate the extension.

Deploy weblogic-spring.jar.

  • Locate weblogic-spring.jar, located in ${WL_HOME}/server/lib
  • Deploy as library the jar using weblogic console.

Enable spring in your application.

  • As all spring enabled application, you have to include the spring listener in web.xml :
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring-config.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
</web-app>
  • Add WeblogicSpringApplicationListener in your spring context configuration file in order to generate all MBeans needed to display the beans in the enabled console.

<bean class=”weblogic.spring.monitoring.WeblogicSpringApplicationListener” />

  • Add or change the MANIFEST.MF file with the following lines

Extension-List: WeblogicSpring
WeblogicSpring-Extension-Name: weblogic-spring
WeblogicSpring-Specification-Version: 12.1.1.0
WeblogicSpring-Implementation-Version: 12.1.1.0

  • Deploy your application, and go to deployed app details, and navigate to SpringFramework tab to see the detailed spring configuration information.