Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Assuming your Linux distro uses some variant of the System V Init framework to run its services, you can use the rc.ofbiz script inside the root OFBiz installation dir"tools" folder of the home folder of OFBiz (or in the home folder itself for releases older than 12.04).  I HAVE NOT TESTED THIS SCRIPT.  In my own firm, we use our own custom-written script for various reasons.  But the rc.ofbiz script was written by David E. Jones so it is probably reasonable!   You may need to perform some of the commands below as root or via sudo, if you don't know what that means, please find out BEFORE you start hosting OFBiz on Linux!

...

2. Copy the rc.ofbiz script to the /etc/init.d directory, with the name ofbiz, so you end up with: /etc/init.d/ofbiz    .   For instance:

Code Block
cp /opt/ofbiz/tools/rc.ofbiz /etc/init.d/ofbiz

...

Code Block
sudo update-rc.d -f ofbiz remove
sudo update-rc.d ofbiz start 21 2 3 4 5 . stop 19 0 1 6 ..d ofbiz start 21 2 3 4 5 . stop 19 0 1 6 .


 6b. Alternative: Without proper shutdown the Ofbiz database can not be restartet anymore. So this /etc/init.d/ofbiz script is a mix of the Solaris script below, startofbiz.bat and a Linux startup/stop script. You might use the sysv-rc-conf package/ command to let it run in state 2, 3, 4, 5 as many other services/server do in Debian or Ubuntu.

The Solaris shell function ofbizprocs() does not work with bash. Instead simply executing the external program pgrep does the job here. You need to install the Debian or Ubuntu package procps in order to use pgrep.

Code Block

#!/bin/bash -e

### BEGIN INIT INFO
# Provides:          ofbiz
# Required-Start:    $syslog $time $remote_fs
# Required-Stop:     $syslog $time $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: start Apache Ofbiz
# Description:       Debian init script for the Apache Ofbiz,
#                    the open source enterprise automation software 
### END INIT INFO
set -e
######################################################################
export JAVA_HOME=/usr/local/src/jdk1.6.0_18
export CLASSPATH=/usr/local/src/jdk1.6.0_18
export PATH=.:/usr/local/src/jdk1.6.0_18/bin:/bin:/usr/bin:/sbin:/usr/sbin
cd /var/www/Ofbiz/
######################################################################
export JAVA_BINARY=/usr/local/src/jdk1.6.0_18/bin/java
export JAVA=$JAVA_BINARY
OFBIZ_HOME=/var/www/Ofbiz/
OFBIZ_LOG=$OFBIZ_HOME/runtime/logs/console.log
OFBIZ_OUT=/tmp/OfbizOut
# JAVA_VMOPTIONS="-Duser.language=de"
# JAVA_VMOPTIONS="-Xms768M -Xmx1024M -Duser.language=en"
JAVA_ARGS="-jar ${OFBIZ_HOME}/ofbiz.jar"
OFBIZ_USER=ofbiz
######################################################################
# shutdown settings
ADMIN_PORT=10523
ADMIN_KEY="InsertYourOwnKeyHere!"

# VM args
ADMIN="-Dofbiz.admin.port=$ADMIN_PORT -Dofbiz.admin.key=$ADMIN_KEY"
MEMIF="-Xms128M -Xmx512M"
MISC="-Duser.language=de"
VMARGS="$MEMIF $MISC $DEBUG $RMIIF $ADMIN"
######################################################################
# The original shell function ofbizprocs() does NOT work with bash.
# Therefore simply executing the external program does the job here:

ofbizprocs="pgrep -u ${OFBIZ_USER} java"
# We need the Debian or Ubuntu package procps for this!

start() {
    echo "Starting OFBiz: "
    echo "Testing running OFBiz: "
    if [ "$($ofbizprocs)" != "" ]; then
        echo "OFBiz is already running..."
        return 1
    fi

    # All clear
    cd $OFBIZ_HOME
    umask 007
    /bin/rm -f $OFBIZ_OUT $OFBIZ_LOG
    echo "Now really starting OFBiz: "
    su - $OFBIZ_USER \
-c "cd $OFBIZ_HOME && $JAVA_BINARY $VMARGS $JAVA_ARGS >$OFBIZ_OUT 2>>$OFBIZ_LOG &"
    echo "startup return value: " $?
    return $?
}

# Stop OFBiz
stop() {
    echo -n "Stopping OFBiz: "
    if [ "$($ofbizprocs)" = "" ]; then
        echo "OFBiz is not running..."
        return 1
    fi
    # All clear
    cd $OFBIZ_HOME
    umask 007    
    su - ofbiz \
-c "cd $OFBIZ_HOME && $JAVA_BINARY $VMARGS $JAVA_ARGS -shutdown >$OFBIZ_OUT 2>>$OFBIZ_LOG&"
	sleep 15
    if [ "$($ofbizprocs)" != "" ]; then
        # Let's try to -TERM
        /bin/kill -TERM "$($ofbizprocs)"
    else
        return 0
    fi
	sleep 10
    if [ "$($ofbizprocs)" != "" ]; then
        # Let's try it the hard way!
        /bin/kill -9 "$($ofbizprocs)"
    else
        return 0
    fi
	sleep 10
    if [ "$($ofbizprocs)" != "" ]; then
        echo "Some processes could not be stopped:"
        echo "$($ofbizprocs)"
        echo "A possible solution is to try this command once more!"
        return 1
    else
        return 0
    fi
}

######################################################################
. /lib/lsb/init-functions

case "$1" in
    start)
	log_daemon_msg "Starting Apache Ofbiz" "ofbiz"
	start
	log_end_msg $?
    ;;
  stop)
	log_daemon_msg "Stopping deferred Apache Ofbiz" "ofbiz"
	stop
	log_end_msg $?
    ;;
  force-reload|restart)
    stop
    start
    ;;
  *)
    echo "Usage: /etc/init.d/atd {start|stop|restart|force-reload}"
    exit 1
    ;;
esac

exit 0


Solaris (at least v10)

To be adapted maybe, from a Christopher Snow's message on user ML

...

OS X 10.4+ uses the launchd daemon for startup services. Getting OFBiz to run as a server is really simple using this approach.

1. Create the org.apache.ofbiz.plist configuration file. A plist configuration file is nothing more than an XML file with the .plist extension. Use the sample script below (but be sure to change the WorkingDirectory property and create a file named org.apache.ofbiz.plist:

Code Block
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Disabled</key>
	<false/>
	<key>Label</key>
	<string>org.apache.ofbiz</string>
	<key>WorkingDirectory</key>
	<string>/Users/jaz/Sandbox/ofbiz</string>
	<key>ProgramArguments</key>
	<array>
		<string>./tools/startofbiz.sh</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
</dict>
</plist>

You can change the RunAtLoad property if you want to stop OFBiz auto-starting.

1 2. To test the startup script you use launchctl. The following command will start OFBiz as the current user:

...

Code Block
$ launchctl unload org.apache.ofbiz.plist

3. Deploy the startup script (assumes running as root):

Code Block

$ sudo chown root:wheel org.apache.ofbiz.plist
$ sudo mv org.apache.ofbiz.plist /Library/LaunchDaemons/

You can now reboot and have OFBiz startup automatically. To load the script without rebooting you run the load command as root.

Code Block
$ sudo launchctl load /Library/LaunchDaemons/org.apache.ofbiz.plist

4. To stop/start the process after it has been loaded either by rebooting or by running the load command you can run the following:
To Stop (note that the .plist is not specified for starting/stopping):

Code Block

$ sudo launchctl stop org.apache.ofbiz

To Start

Code Block
$ sudo launchctl start org.apache.ofbiz