Installing XWiki on FreeBSD
Introduction
This guide takes one through all processes of installing XWiki into a FreeBSD environment. This guide has been provisioned to be used in a FreeBSD Jail architecture but easily contributes itself to a normal environment too as the extra Jail steps provided are not necessary.
Creating the Jail
The first thing we need to do in order to get XWiki up and running is create the jail that the software will reside in. First of all I'm going to position this jail in my ZFS pool and call it wiki and then I will start on the jail creation itself:
Test-BSD# mkdir /zfs/jail/wiki
Test-BSD# setenv D /zfs/jail/wiki
Test-BSD# mkdir -p $D
Test-BSD# make installworld DESTDIR=$D
Test-BSD# make distribution DESTDIR=$D
Test-BSD# mount -t devfs devfs $D/devOnce the jail has been created we can now add it to the /etc/rc.conf file:
ifconfig_de0_alias1="inet 192.168.0.151 netmask 255.255.255.0"
jail_list="dns wiki"
jail_wiki_rootdir="/zfs/jail/wiki"
jail_wiki_hostname="wiki.yourdomain.net"
jail_wiki_interface="de0"
jail_wiki_ip="192.168.0.151"
jail_wiki_devfs_enable="YES"and then start the newly built and configured jail:
Test-BSD# /etc/rc.d/jail start wiki
Configuring jails:.
Starting jails: wiki.yourdomain.net.From there we can test to see if it has been successfully activated:
Test-BSD# jls
JID IP Address Hostname Path
1 192.168.0.149 ns1.yourdomain.net /zfs/jail/dns
2 192.168.0.151 wiki.yourdomain.net /zfs/jail/wikiand now mount the ports collection inside it:
Test-BSD# sh
# D=/zfs/jail/wiki
# mkdir -p $D/usr/ports
# mount_nullfs /usr/ports $D/usr/ports
# mount | sort
/dev/ad0s1a on / (ufs, local)
/usr/ports on /zfs/jail/wiki/usr/ports (nullfs, local)
ZPOOL_1 on /zfs (zfs, local)
devfs on /dev (devfs, local, multilabel)
devfs on /zfs/jail/dns/dev (devfs, local, multilabel)
devfs on /zfs/jail/wiki/dev (devfs, local, multilabel)From here we can login to the jail and build the applications we need starting with the Nano text editor:
Test-BSD# jexec 2 tcsh
wiki# cd /usr/ports/*/nano
wiki# make install cleanThe next task is to setup the /etc/rc.conf, /etc/hosts, and /etc/resolv.conf files within the jail, while taking some prerequisites into consideration:
wiki#cat /etc/rc.conf
defaultrouter="192.168.0.254"
hostname="wiki.yourdomain.net"
tomcat60_enable="YES"
postgresql_enable="YES"
postgresql_user="root"
jail_sysvipc_allow="YES"wiki#cat /etc/hosts
# $FreeBSD: src/etc/hosts,v 1.16.34.1.2.1 2009/10/25 01:10:29 kensmith Exp $
#
# Host Database
#
# This file should contain the addresses and aliases for local hosts that
# share this file. Replace 'my.domain' below with the domainname of your
# machine.
#
# In the presence of the domain name service or NIS, this file may
# not be consulted at all; see /etc/nsswitch.conf for the resolution order.
#
#
::1 localhost localhost.my.domain
127.0.0.1 localhost localhost.my.domain
#
# Imaginary network.
#10.0.0.2 myname.my.domain myname
#10.0.0.3 myfriend.my.domain myfriend
#
# According to RFC 1918, you can use the following IP networks for
# private nets which will never be connected to the Internet:
#
# 10.0.0.0 - 10.255.255.255
# 172.16.0.0 - 172.31.255.255
# 192.168.0.0 - 192.168.255.255
#
# In case you want to be able to connect to the Internet, you need
# real official assigned numbers. Do not try to invent your own network
# numbers but instead get one from your network provider (if any) or
# from your regional registry (ARIN, APNIC, LACNIC, RIPE NCC, or AfriNIC.)
#
192.168.0.151 wiki.yourdomain.net wiki
192.168.0.151 wiki.yourdomain.net.wiki# cat /etc/resolv.conf
nameserver 192.168.0.149Now that the jail internals have been setup, it is time to start adding the software needed to run XWiki.
Apache Tomcat Installation
The installation of Tomcat will be version 6 built from the ports repository.
wiki# cd /usr/ports/*/tomcat6
wiki# make install cleanIf all went to plan there should be an error message at the tail end of the install:
Please open http://java.sun.com/javase/downloads/index.jsp
in a web browser and follow the "Download" link for
"JDK US DST Timezone Update Tool - 1_3_18" to obtain the
time zone update file, tzupdater-1_3_18-2009k.zip.
Please download the patchset, bsd-jdk16-patches-4.tar.bz2, from
http://www.eyesbeyond.com/freebsddom/java/jdk16.html.
Please place the downloaded file(s) in /usr/ports/distfiles
and restart the build.
*** Error code 1
Stop in /usr/ports/java/jdk16.
*** Error code 1
Stop in /usr/ports/java/jdk16.
*** Error code 1
Stop in /usr/ports/www/tomcat6.This basically tells us that we need to install the JDK US DST Timezone Update Tool and also the JDK16 environment in order to proceed. Since both these packages have license agreements they cannot be downloaded directly using a utility such as wget, so one has to actually open up a browser in order to navigate to the links, accept the license agreements and download the packages.
For the JDK US DST Timezone Update Tool go here and for the JDK16 go here although depending on how new the port is, it may complain and ask for a different set of downloads.
Once downloaded, upload the files to the server using ftp, sftp, scp, rsync, or another method then move the files into the ports directory:
scp tzupdater-1_3_31-2010i.zip [email protected]:/usr/home/mark/
scp diablo-jdk-freebsd7.i386.1.6.0.07.02.tbz [email protected]:/usr/home/mark/
ssh [email protected]
$ su -
Test-BSD# cd /usr/home/mark
Test-BSD# mv diablo-jdk-freebsd7.i386.1.6.0.07.02.tbz /usr/ports/distfiles/
Test-BSD# mv tzupdater-1_3_31-2010i.zip /usr/ports/distfiles/From there we need to login to the jail again and build the JDK port:
wiki# cd /usr/ports/java/diablo-jdk16/
wiki# make install cleanAgain the system may blow up and come up with an error meaning that the directions on screen need to be followed:
Because of licensing restrictions, you must fetch the distribution
manually.
Please access
http://www.FreeBSDFoundation.org/cgi-bin/download?download=diablo-caffe-freebsd7-amd64-1.6.0_07-b02.tar.bz2
with a web browser and "Accept" the End User License Agreement for
"Caffe Diablo 1.6.0".
Please open http://java.sun.com/javase/downloads/index.jsp
in a web browser and follow the "Download" link for
"JDK US DST Timezone Update Tool - 1_3_18" to obtain the
time zone update file, tzupdater-1_3_18-2009k.zip.
Please place the downloaded file(s) in /usr/ports/distfiles.
*** Error code 1
Stop in /usr/ports/java/diablo-jdk16.
*** Error code 1
Stop in /usr/ports/java/diablo-jdk16.Once downloaded again scp or other method can be used to upload the package to the server:
scp diablo-caffe-freebsd7-amd64-1.6.0_07-b02.tar.bz2 [email protected]:/usr/home/mark/
ssh [email protected]
$ su -
Test-BSD# cd /usr/home/mark
Test-BSD# mv diablo-caffe-freebsd7-amd64-1.6.0_07-b02.tar.bz2 /usr/ports/distfiles/
wiki# cd /usr/ports/java/diablo-jdk16/
wiki# make install cleanIf the system starts complaining about the JDK US DST Timezone Update Tool it means that either the older version needs to be found or alternatively a port upgrade must be performed. Of course an easier way would be to just turn it off altogether however we will proceed as per the dialogs.
Since an older version of the JDK US DST Timezone Update Tool isn't available and the port upgrade didn't manage to solve the problem either, even after having a production build with the same packages the best way to proceed at this point was to disable the tool.
# cd /usr/ports/java/jdk16
# make configThen unselect tzupdate and press OK. After another attempt at building the JDK environment the system again complains with this error:
wiki# make install clean
===> Vulnerability check disabled, database not found
===> Found saved configuration for jdk-1.6.0.3p4_12
IMPORTANT: To build the JDK 1.6.0 port, you should have at least
2.5Gb of free disk space in the build area!
Due to licensing restrictions, certain files must be fetched manually.
Please download the Update 3 Source from
http://www.java.net/download/jdk6/6u3/promoted/b05/jdk-6u3-fcs-src-b05-jrl-24_sep_2007.jar
and the Source Binaries from
http://www.java.net/download/jdk6/6u3/promoted/b05/jdk-6u3-fcs-bin-b05-jrl-24_sep_2007.jar
and the Mozilla Headers from
http://www.java.net/download/jdk6/6u3/promoted/b05/jdk-6u3-fcs-mozilla_headers-b05-unix-24_sep_2007.jar
.
Please download the patchset, bsd-jdk16-patches-4.tar.bz2, from
http://www.eyesbeyond.com/freebsddom/java/jdk16.html.
Please place the downloaded file(s) in /usr/ports/distfiles
and restart the build.
*** Error code 1
Stop in /usr/ports/java/jdk16.
*** Error code 1
Stop in /usr/ports/java/jdk16.Meaning that we need to fetch each and every one of those components and drop them into the /usr/ports/distfiles directory. A trick however is to use the wget tool in the directory itself meaning that no other work needs to be done:
wget http://www.java.net/download/jdk6/6u3/promoted/b05/jdk-6u3-fcs-src-b05-jrl-24_sep_2007.jar
wget http://www.java.net/download/jdk6/6u3/promoted/b05/jdk-6u3-fcs-bin-b05-jrl-24_sep_2007.jar
wget http://www.java.net/download/jdk6/6u3/promoted/b05/jdk-6u3-fcs-mozilla_headers-b05-unix-24_sep_2007.jarOnce all that is done and finished we can run the make install clean command again from within the JDK port. If there are any more errors that pop-up just follow the on-screen instructions in order to overcome them. The majority of the errors will be to build Java components without the tzupdate enabled.
And finally install Tomcat6 into the system:
wiki# cd /usr/ports/*/tomcat6
wiki# make install cleanPostgresql
The next stage in getting the XWiki system up and running is to install the Postgresql database backend. Many different types of databases are compatible with XWiki, however for FreeBSD the Postgresql is the only database that has been functional and able to be tested.
So now let's start by installing both server and client components; the version that is going to be installed is: 8.2.17_1. This is a simple procedure that will be done from the ports collection.
wiki# cd /usr/ports/databases/postgresql82-client
wiki# make install clean
wiki# cd ../postgresql82-server
wiki# make install cleanNow it's a good idea to restart the jail:
Test-BSD# /etc/rc.d/jail restart wiki**and login again:
Test-BSD# jls
JID IP Address Hostname Path
1 192.168.0.149 ns1.yourdomain.net /zfs/jail/dns
4 192.168.0.151 wiki.yourdomain.net /zfs/jail/wiki
Test-BSD# jexec 4 tcshFrom here create the database cluster:
wiki# su pgsql
$ /usr/local/bin/initdb /usr/local/pgsql/data
The files belonging to this database system will be owned by user "pgsql".
This user must also own the server process.
The database cluster will be initialized with locale C.
creating directory /usr/local/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 10
selecting default shared_buffers/max_fsm_pages ... 400kB/20000
creating configuration files ... ok
creating template1 database in /usr/local/pgsql/data/base/1 ... FATAL: could not create shared memory segment: Function not implemented
DETAIL: Failed system call was shmget(key=1, size=1818624, 03600).
child process exited with exit code 1
initdb: removing data directory "/usr/local/pgsql/data"As can be seen there is an error which is specifically caused by running PostgreSQL in a jail environment. This can be overcome by adding: jail_sysvipc_allow="YES" to the /etc/rc.conf file in the base install and re-running the PostgreSQL initialization:
wiki# su pgsql
$ /usr/local/bin/initdb /usr/local/pgsql/data
The files belonging to this database system will be owned by user "pgsql".
This user must also own the server process.
The database cluster will be initialized with locale C.
creating directory /usr/local/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 40
selecting default shared_buffers/max_fsm_pages ... 28MB/179200
creating configuration files ... ok
creating template1 database in /usr/local/pgsql/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating conversions ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.
Success. You can now start the database server using:
/usr/local/bin/postgres -D /usr/local/pgsql/data
or
/usr/local/bin/pg_ctl -D /usr/local/pgsql/data -l logfile startNow let's start the Postgresql service:
wiki# su - pgsql
$ /usr/local/bin/postgres -D /usr/local/pgsql/dataThe process can be further tested using the: ps -aux | grep postgres command. Now that the service is up and running we can go on to creating the XWiki user and database:
$ createuser xwiki -S -D -R -P -Upgsql
Enter password for new role:
Enter it again:
CREATE ROLE
$ createdb xwiki -Eunicode -Oxwiki -Upgsql
CREATE DATABASEFrom here the final stage in PostgreSQL configuration is to add a line trusting the interface in the /usr/local/pgsql/data/pg_hba.conf file so that the bottom of the file looks like this:
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
host all all 192.168.0.151/32 trustAll that is needed to be done now is the Postgresql service restarted and for security the database can even be listed to ensure it's creation:
wiki# /usr/local/etc/rc.d/postgresql restart$ su -
Password:
Test-BSD# jls
JID IP Address Hostname Path
1 192.168.0.149 ns1.yourdomain.net /zfs/jail/dns
2 192.168.0.151 wiki.yourdomain.net /zfs/jail/wiki
Test-BSD# jexec 2 tcsh
wiki# su - pgsql
$ psql -l
List of databases
Name | Owner | Encoding
-----------+-------+-----------
postgres | pgsql | SQL_ASCII
template0 | pgsql | SQL_ASCII
template1 | pgsql | SQL_ASCII
xwiki | xwiki | UTF8
(4 rows)Installing XWiki
To start with let's download the XWiki war file:
wiki# wget http://download.forge.objectweb.org/xwiki/xwiki-enterprise-web-3.5.1.war
--2010-09-11 20:56:48-- http://download.forge.objectweb.org/xwiki/xwiki-enterprise-web-3.5.1.war
Resolving download.forge.objectweb.org... 88.191.79.12, 2a01:e0b:1:79:2e0:f4ff:fe1b:b525
Connecting to download.forge.objectweb.org|88.191.79.12|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 141657140 (135M) [text/plain]
Saving to: `xwiki-enterprise-web-3.5.1.war'
100%[======================================>] 141,657,140 406K/s in 5m 48s
2010-09-11 21:02:36 (406 KB/s) - `xwiki-enterprise-web-3.5.1.war' saved [141657140/141657140]This will now get renamed to xwiki.war and moved to the $TOMCAT_HOME/webapps directory:
wiki# mv xwiki-enterprise-web-3.5.1.war xwiki.war
wiki# mv xwiki.war /usr/local/apache-tomcat-6.0/webapps/From this moment we can start Tomcat6 and look at the WAR file extracting into the webapps directory:
wiki# ls /usr/local/apache-tomcat-6.0/webapps
ROOT examples manager
docs host-manager xwiki.war
wiki# /usr/local/etc/rc.d/tomcat6 restart
tomcat60 not running? (check /var/run/tomcat60.pid).
Starting tomcat60.
wiki# ls /usr/local/apache-tomcat-6.0/webapps
ROOT examples manager xwiki.war
docs host-manager xwikiConfiguring the database connection
We must install the JDBC connector for PostgreSQL into XWiki:
wiki# cd /usr/local/apache-tomcat-6.0/webapps/xwiki/WEB-INF/lib
wiki# wget http://jdbc.postgresql.org/download/postgresql-8.3-606.jdbc4.jar
--2010-09-11 21:11:19-- http://jdbc.postgresql.org/download/postgresql-8.3-606.jdbc4.jar
Resolving jdbc.postgresql.org... 200.46.204.71
Connecting to jdbc.postgresql.org|200.46.204.71|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 476213 (465K) [application/octet-stream]
Saving to: `postgresql-8.3-606.jdbc4.jar'
100%[======================================>] 476,213 151K/s in 3.1s
2010-09-11 21:11:24 (151 KB/s) - `postgresql-8.3-606.jdbc4.jar' saved [476213/476213]Edit the WEB-INF/hibernate.cfg.xml file and comment out there rest of the config that doesn't apply:
<!-- Configuration for the default database.
Comment out this section and uncomment other sections below if you want to use another database.
Note that the database tables will be created automatically if they don't already exist.
-->
<!--
<property name="connection.url">jdbc:hsqldb:file:database/xwiki_db;shutdown=true</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
<property name="connection.pool_size">2</property>
<property name="statement_cache.size">2</property>
<mapping resource="xwiki.hbm.xml"/>
<mapping resource="feeds.hbm.xml"/>
<mapping resource="activitystream.hbm.xml"/>
-->
...
<!-- PostgreSQL configuration.
Uncomment if you want to use PostgreSQL and comment out other database configurations. -->
<property name="connection.url">jdbc:postgresql://localhost:5432/xwiki</property>
<property name="connection.username">xwiki</property>
<property name="connection.password">xwiki</property>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
<property name="connection.pool_size">2</property>
<property name="statement_cache.size">2</property>
<property name="jdbc.use_streams_for_binary">false</property>
<mapping resource="xwiki.postgresql.hbm.xml"/>
<mapping resource="feeds.hbm.xml"/>
<mapping resource="activitystream.hbm.xml"/>
...Restart Tomcat again:
wiki# /usr/local/etc/rc.d/tomcat6 restart
Stopping tomcat60.
Waiting (max 10 secs) for PIDS: 7591, 7591.
Starting tomcat60.Point the web browser to the URL: http://wiki.yourdomain.net:8180/xwiki at this point and the page should appear!!
If for some reason an error is given in the browser:
then add this to the: /usr/local/apache-tomcat-6.0/conf/catalina.policy file:
grant codeBase "file:${catalina.base}/webapps/xwiki/-" {
permission java.security.AllPermission;
permission java.io.FilePermission "${catalina.base}/webapps/xwiki/-", "read,write,delete";
permission java.io.FilePermission "/var/log/tomcat60/-", "read,write";
permission java.io.FilePermission "/WEB-INF/xwiki.cfg", "read";
permission java.io.FilePermission "/WEB-INF/hibernate.cfg.xml", "read";
permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
permission java.util.PropertyPermission "user.name", "read";
permission java.util.PropertyPermission "office.*", "read";
permission java.util.PropertyPermission "file.encoding", "read";
permission java.util.PropertyPermission "org.apache.commons.logging.LogFactory.HashtableImpl", "read";
permission java.util.PropertyPermission "org.quartz.properties", "read";
permission java.util.PropertyPermission "ANTLR_DO_NOT_EXIT", "read";
permission java.util.PropertyPermission "ANTLR_USE_DIRECT_CLASS_LOADING", "read";
permission java.util.PropertyPermission "org.apache.xerces.xni.parser.XMLParserConfiguration", "read";
permission java.net.SocketPermission "127.0.0.1:3306", "connect,resolve";
permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
permission java.lang.RuntimePermission "getClassLoader";
permission java.lang.RuntimePermission "createClassLoader";
permission java.lang.RuntimePermission "setContextClassLoader";
permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina";
permission java.lang.RuntimePermission "accessDeclaredMembers";
permission java.lang.RuntimePermission "getenv.ProgramFiles";
permission java.lang.RuntimePermission "getenv.APPDATA";
};If still getting errors after this then update the ports tree until the Tomcat and Postgresql versions are the latest up-to-date ones.
Once XWiki is up and running the initial screen should look like this:
Initial Configuration
As claimed by XWiki it currently doesn't have any pages or templates, meaning that we manually have to do this. Access the Administration section of the XWiki interface:

Then download the XWiki template from http://download.forge.objectweb.org/xwiki/xwiki-enterprise-ui-all-3.5.1.xar, and upload them into the XWiki instance:

After the xar file has been selected from a folder in your computer click the Upload button:

Click the link on the xar file itself to reveal the package contents and click on Import:

The screen will finally display confirmation that the templates have been loaded into the XWiki instance and that it is time to login:

Finally go back to the XWiki homepage and test that everything has been loaded as planned:

Then login as the Administrator:

And begin customizing your new install of XWiki:

Memory Errors
If one experiences random timeouts while attempting to connect to the URL of XWiki, the solution can usually be found within the Tomcat log file.
First login to the system or Jail environment and go to /usr/local/apache-tomcat-6.0/logs. From there open stdout.log and either pipe to 'tail' to get the end of the file or grep to 'space':
cat stidout.log | tail
cat stdout.log | grep spaceWhat will eventually be returned among other things should be the lines:
java.lang.OutOfMemoryError: Java heap space
Exception in thread "http-8180-Acceptor-0" java.lang.OutOfMemoryError: Java heap spaceThe error mainly should be contained as Java heap space however, it could also come up as Java perm space.
In order to elleviate the issue add:
tomcat60_java_opts="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms3072m -Xmx3072m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m -XX:MaxPermSize=256m -XX:+DisableExplicitGC"to /etc/rc.conf, where the -Xms and -Xmx values should be set in accordance with what is needed as setting too high could cause Java to use up the system Swap space, thus causing instability inside the OS environment.
To test if the Java service is online or not one can use the netstat and sockstat commands:
www# netstat -ap tcp | grep 8180
tcp4 0 0 www.8180 *.* LISTEN
www# sockstat | grep java
www java 51547 33 tcp4 192.168.1.170:8180 *:*
www java 51547 40 tcp4 192.168.1.170:8009 *:*
www java 51547 42 tcp4 192.168.1.170:8005 *:*
www java 51547 48 tcp4 192.168.1.170:25739 192.168.1.170:5432
www java 51547 302 tcp4 192.168.1.170:56498 192.168.1.170:5432
www java 51547 304 stream(not connected)
www java 51547 307 tcp4 192.168.1.170:39540 192.168.1.170:5432If for some reason the process has exited and both stderr.log and stdout.log don't show any valid means of 'why?'. An answer could be that the system has run out of memory and so some intelligence needs to be built in, in order to detect the Java process not being online.
It is also a wise idea to check /var/log/messages for any errors or 'unhandled exceptions'.
Another method would be to check the root user mail or/and get emailed an output of the systems logs daily. This can lead to detecting messages such as this:
+pid 21242 (java), uid 80, was killed: out of swap spaceA failsafe however, can be built into the system to prevent 'downtime';
The script below will detect if Tomcat stops running and restart the process automatically:
#!/usr/local/bin/bash
export PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
#set -v -x
ntstat=`netstat -ap tcp | grep 8180 | sed -n '1p'`
port="8180"
sock=`sockstat | grep java`
sock_name="java"
#echo $ntstat
#echo $port
if [[ $sock =~ $sock_name ]]; then
echo "Output of Sockstat command" > /root/java_restart/java_restart.log;
echo "" >> /root/java_restart/java_restart.log;
echo "$sock" >> /root/java_restart/java_restart.log;
echo "" >> /root/java_restart/java_restart.log;
echo "Socket type $sock_name" >> /root/java_restart/java_restart.log;
echo "" >> /root/java_restart/java_restart.log;
echo "Output of Netstat command" >> /root/java_restart/java_restart.log;
echo "" >> /root/java_restart/java_restart.log;
echo "$ntstat" >> /root/java_restart/java_restart.log;
echo "" >> /root/java_restart/java_restart.log;
echo "Port number is:" >> /root/java_restart/java_restart.log;
echo "$port" >> /root/java_restart/java_restart.log;
else
sleep 60; /usr/local/etc/rc.d/tomcat6 restart;
fiThe log for this file will show:
Output of Sockstat command
www java 28878 33 tcp4 192.168.1.130:8180 *:*
www java 28878 41 tcp4 192.168.1.130:8009 *:*
www java 28878 43 tcp4 192.168.1.130:8005 *:*
www java 28878 49 tcp4 192.168.1.130:47415 192.168.1.130:5432
www java 28878 50 tcp4 192.168.1.130:60852 192.168.1.130:5432
www java 28878 303 tcp4 192.168.1.130:12587 192.168.1.130:5432
www java 28878 305 stream(not connected)
Socket type java
Output of Netstat command
tcp4 0 0 wiki.8180 *.* LISTEN
Port number is:
8180which is really a validation check on the Tomcat process rather then giving debug information.
This script can be loaded into crontab now and be automated completely:
0/10 * * * * /usr/local/bin/bash /root/java_restart/java_restart.shwith 0/10 designating how 'frequently' the script is to be run (every 10 minutes in this example).


