Fixing JBoss Error installing to Start: name=IIOPInvoker state=Create: java.net.UnknownHostException:

If you ever see the following when attempting to start up an instance of JBoss 6.x:

15:41:15,740 ERROR [AbstractKernelController] Error installing to Start: name=IIOPInvoker state=Create: java.net.UnknownHostException: some_host_name: some_host_name
        at java.net.InetAddress.getLocalHost(InetAddress.java:1426)
        [:1.6.0_17] at org.jboss.invocation.iiop.IIOPInvoker.start(IIOPInvoker.java:233) [:6.0.0.Final]

It is because JBoss cannot resolve the host name of the machine on which it is running.  To fix:

 

  • Edit /etc/hosts and add the name of the box pointing to an ip address.
  • Set up a proper DNS entry for the host name of the machine.

Installing Jboss 6.1.0-Final under RHEL or CentOS

The following is a howto for installing Jboss under Red Hat Enterprise Linux or CentOS.  The steps are most likely the same under any other Linux distro.

  • Unpack your jboss.zip (or .tar)
  • Jboss requires a ‘place’ to store data as it runs.  Out of the box it uses org.jboss.jdbc.HypersonicDatabase which is horribly inefficient and should never be used in a production system.  So we’ll set up MySQL such that jboss can write to it (installing and configuring MySQL is an excersize for the reader) and create a DataStore instance in jboss that points to the MySQL server:

Add a jboss user to MySQL (This is with a 5.x version of MySQL)

INSERT INTO `user` VALUES (‘localhost’, ‘jboss’, ‘5d2e19393cc5ef67’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘N’, ‘N’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘N’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘N’, ”, ”, ”, ”, 0, 0, 0, 0)

Create a table for jboss

  • Create a DataSource definition:

Copy mysql-ds.xml from $JBOSS_HOME/docs/examples/jcs/mysql-ds.xml to $JBOSS_HOME/server_profile/deploy

Edit the mysql-ds.xml:

Change JNDI name to: DefaultDS

Update the URL to point to the MySQL server and jboss database.

Remove the ‘zeroDateTimeBehavior=convertToNull’ connection argument

# mv deploy/hsqldb-ds.xml deploy/hsqldb-ds.xml.removed.   This will disable the default HyperSonic db DataStore.

  • Unistall the services that you do not need.  This will greatly depend on what it is that you are trying to do with this application server instance.  Following are some examples of services that are removed and how to do it.  Each one is a bit different.

javamail:

In deployers/jsr77-deployers-jboss-beans.xml: Comment out the following: <property name=”mailService”>jboss:service=Mail</property>

# mv deploy/mail-service.xml deploy/mail-service.xml.removed

hornetq:

# rm -rf deploy/jms-ra.rar/
# rm -rf deploy/hornetq/
# mv deployers/hornetq-deployers-jboss-beans.xml deployers/hornetq-deployers-jboss-beans.xml.removed

clustering:

# mv ./deployers/clustering-deployer-jboss-beans.xml ./deployers/clustering-deployer-jboss-beans.xml.removed
# rm -rf ./deploy/mod_cluster.sar/

  • Update the admin console password:

Edit: $JBOSS_HOME/server_profile/conf/props/jmx-console-users.properties

Add a uid/password combination in the following format: uid=password

  • Secure the jmx-console:

Copy the jmx-console.war from the common directory into the server_profile server dir.

# cp -Rpf ./common/deploy/jmx-console.war/ server/amap/deploy

Edit: ./deploy/jmx-console.war/WEB-INF/jboss-web.xml

Uncomment the <security-domain> node

Edit: ./deploy/jmx-console.war/WEB-INF/web.xml

Uncomment the <security-constraint> node

Edit: ./deploy/jmx-jboss-beans.xml

Uncomment the line: <property name=”securityDomain”>jmx-console</property>

Edit: conf/props/jmx-console-users.properties

Change the password

With that, you should have an instance of JBoss up and running and ready for you to develop your applications.

Configuring JBoss 6.x to Run as a Service Under RHEL and CentOS

In most cases you will want to run JBoss as a non-privileged user.  For this example we will set up a jboss user (adding the user is an excersize for the user).  This example covers jboss-6.1.0-Final.

  • Add $JAVA_HOME and $JBOSS_HOME environmental vars to .bash_profile for your jboss user.  $JAVA_HOME points to your install of the JDK and $JBOSS_HOME points to your jboss installation directory.

    JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk.x86_64
    export JAVA_HOME
    PATH=$JAVA_HOME/bin:$PATH
    export PATH

JBOSS_HOME=/opt/jboss/
export JBOSS_HOME

  • Once you have done the basic JBoss installation set up, copy the jboss_init_redhat.sh to /etc/init.d/jboss.
  • Add the following directly below the #!/bin/bash line:

# description: JBoss Start Stop Restart
# processname: jboss
# chkconfig: 234 20 80

  • Set JBOSS_HOME
  • JAVAPTH to the location of your JDK
  • Set JBOSS_CONF to the profile you want to run
  • define a $JBOSS_HOST variable and set it to either the IP address or host name of the machine on which you are running jboss.
  • Update the JBOSSCP to include the jbossall-client.jar

JBOSSCP=${JBOSSCP:-“$JBOSS_HOME/bin/shutdown.jar:$JBOSS_HOME/client/jbossall-client.jar”}

  • Replace the JBOSS_CMD_STOP with the following line (the uid:password combo is whatever you used to lock down the admin console in jboss):

JBOSS_CMD_STOP=”$JBOSS_HOME/bin/shutdown.sh -s service:jmx:rmi:///jndi/rmi://192.168.126.128:1090/jmxrmi -u admin -p password”

  • Enable jboss as a service in the OS:
  • Make the jboss script executable:
  • # chmod 755 jboss

Add it as a service via chkconfig:

  • # chkconfig –add jboss

Set the run levels for the jboss service

  • # chkconfig –level 2345 jboss on

Fix For: Pango-WARNING **: failed to choose a font, expect ugly output and Other FireFox Errors

$ firefox &
[1] 1933

$
(firefox:1947): Pango-WARNING **: failed to choose a font, expect ugly output. engine-type=’PangoRenderFc’, script=’common’
GConf Error: Failed to contact configuration server; some possible causes are that you need to enable TCP/IP networking for ORBit, or you have stale NFS locks due to a system crash. See http://projects.gnome.org/gconf/ for information. (Details -? 1: Failed to get connection to session: /bin/dbus-launch terminated abnormally without any error message)

(firefox:1947): Pango-WARNING **: failed to choose a font, expect ugly output. engine-type=’PangoRenderFc’, script=’common’
GConf Error: Failed to contact configuration server; some possible causes are that you need to enable TCP/IP networking for ORBit, or you have stale NFS locks due to a system crash. See http://projects.gnome.org/gconf/ for information. (Details -? 1: Failed to get connection to session: /bin/dbus-launch terminated abnormally without any error message)
/usr/lib64/firefox-3.6/run-mozilla.sh: line 131:? 1947 Segmentation fault? “$prog” ${1+”$@”}

[1]+? Exit 139? firefox

Should you see such an error when attempting to run FireFox from a remote terminal connecting to a local XServer (Xming, or similar) check the following:

1. That the haldaemon is running
2. That the dbus-x11 package is installed. On RedHat based systems, you can yum install dbus-x11
3. That you have fonts installed. I did a bit of a brute force approach and ran: yum groupinstall ‘Fonts’

Redirecting All Web Requests to the WWW. DNS Entry for Your Web Site

If you would like to redirect all non ‘www’ requests for pages on your site to the ‘www’ dns entry add the following to your .htaccess file in the document root of your site:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Enabling Parsing and Processing of PHP code in Files With .html Extensions for GoDaddy.com Hosting Accounts

There are times when a web master will want to have the default file extension for a given website stay consistent regardless of how the files are preprocessed on the server-side or what server-side scripting language is being used.

To set up your GoDaddy.com 4GH, Linux hosted account to parse PHP code in .html files, do the following:

  1. Log in to your account.
  2. Go to the control panel for the web site in question.
  3. In the control panel click on the ‘Settings’ sub-section.
  4. Click on the ‘File Extensions Management’ icon/link.
  5. Click on the ‘Custom Extensions’ link in the left-hand column.
  6. Click on ‘New Extension’ in the upper right of the page.
  7. Enter ‘.html’ for the extension, and select ‘PHP 5.x.x’ from the drop-down.
  8. Click ‘OK’

Once you click the ‘OK’ button you can now add PHP code to your .html files.

Cloned VMware CentOS6 Server and "device eth0 does not seem to be present, delaying initialization" Error

Recently, I cloned a vmware install of CentOS6 and after firing up the clone and trying to start networking received the error: “device eth0 does not seem to be present, delaying initialization”

It turns out that the NIC on the cloned machine was being renamed and registered to eth1.

To list the current ethn devices:

# ls /sys/class/net
eth1 lo

There is a device manager, udev, which stores the settings from the NIC of the vm prior to the cloning process.  When you clone a vm it also changes the mac address of the NIC and as a result the vm sees it as a new NIC and assigns it to /dev/eth1.

As a result, we now have to edit the udev config file as well as the ifcfg-eth0 file to get the newly update virtual NIC card to operate on the eth0 device.

First, edit: /etc/udev/rules.d/70-persistent-net.rules

# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# PCI device 0x15ad:0x07b0 (vmxnet3) (custom name provided by external tool)
SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”00:50:56:bc:00:45″, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth0″

# PCI device 0x15ad:0x07b0 (vmxnet3)
SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”00:50:56:bc:00:46″, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth1″

Delete the first SUBSYSTEM entry in the file.

Update the ‘eth1’ attribute in the remaining entry to ‘eth0’

Edit /etc/sysconfig/network-scripts/ifcfg-eth0

. Change the HWADDR to match the new mac address listed in the newly edited 70-persistent-net.rules file.

reboot.

Java: How To Use RandomAccessFile and FileChannel to Write to a Specific Location in a File

If there is ever a need to write bytes to a specific location to an existing file, here is an example of how to use the RandomAccessFile and FileChannel Java classes to do so:

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * Will write bytes to the beginning of an existing file.
 *
 * @author Ryan Chapin
 */
public class RandomAccessFileTest {

    public static void main(String[] args) {

        // Generate input string and the ByteBuffer for it
        String stringToInsert = “This is a string to insert into a file.”;
        byte[] answerByteArray = stringToInsert.getBytes();
        ByteBuffer byteBuffer = ByteBuffer.wrap(answerByteArray);

        File fileToModify = new File(“/path/to/file”);

        RandomAccessFile randomAccessFile = null;
        try {
            randomAccessFile = new RandomAccessFile(fileToModify, “rw”);
        } catch (FileNotFoundException e1) {
            // TODO error handling and logging
        }

        FileChannel outputFileChannel = randomAccessFile.getChannel();

        // Move to the beginning of the file and write out the contents
        // of the byteBuffer.
        try {
            outputFileChannel.position(0);

            while(byteBuffer.hasRemaining()) {
                outputFileChannel.write(byteBuffer);
            }
        } catch (IOException e) {
            // TODO error handling and logging
        }

        try {
            outputFileChannel.close();
        } catch (IOException e) {
            // TODO error handling and logging
        }

        try {
            randomAccessFile.close();
        } catch (IOException e) {
            // TODO error handling and logging
        }
    }
}