How to run OFBiz as a Service on linux
Windows
See this specific guide: How to Run OFBiz as Windows Service with Java Service Wrapper
Linux
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. 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!
1. Create a linux user dedicated to run OFBiz (should NOT be root, for many good reasons that I will not go into here). This user should have full permissions over OFBiz installation dir and its subdir (for simplicity, in fact you could tune this). Your commands will be SOMETHING LIKE...
useradd -m ofbiz
chown -R ofbiz /opt/ofbiz
chmod 700 /opt/ofbiz
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:
cp /opt/ofbiz/rc.ofbiz /etc/init.d/ofbiz
3. Edit the various variables at the top of the script to reflect
your environment, for instance where OFBiz is installed, where your
JVM is installed, etc.
For Debian based distrib replace all "echo_" by "echo "
We may rather use the following snippet. But, as I'm not a Linux
specialist, I let it here as an example for now...
# detect the distribution:
if [ -f /etc/redhat-release -o -f /etc/fedora-release ] ; then
DISTRIBUTION="redhat"
elif [ -f /etc/SuSE-release ] ; then
DISTRIBUTION="suse"
elif [ -f /etc/debian_version ] ; then
DISTRIBUTION="debian"
else
DISTRIBUTION="debian"
fi # Source function library.
[ "$DISTRIBUTION" = "redhat" ] && . /etc/init.d/functions
[ "$DISTRIBUTION" = "suse" ] && . /etc/rc.status if [ "$DISTRIBUTION" = "suse" ] ; then
echo_success() {
rc_status -v
}
echo_failure() {
rc_status -v
}
success() {
echo_success
}
failure() {
echo_success
}
elif [ "$DISTRIBUTION" = "debian" ] ; then
echo_success() {
echo ok
}
echo_failure() {
echo failed
}
success() {
echo_success
}
failure() {
echo_success
}
fi
4. Give this script the correct permissions. Here is a typical example.
chmod 700 /etc/init.d/ofbiz
5. At this point, you should be able to test the script manually, via root or sudo. If you execute the following command, OFBiz should stop (if it was already up), and then start again. Bear in mind that this process can take between 10s and 3 minutes, depending on your macine! If this command does not work, something is wrong, investigate the command output or OFBiz logs to find out what.
/etc/init.d/ofbiz restart
6. Finally, we are ready to tell our Operating system, to execute this script automatically at certain points during OS startup/shutdown. How we do this depends on our specific Linux Distro. I have only put instructions here for those distros I am familiar with. A generic point is that it is IMPORTANT here that your OFBiz starts AFTER any services on which it depends. Typically this is your DB server. If you use MySQL for instance, and MySQL starts with sequence 20, then OFbiz must start with sequence 21 or higher. Invert this logic for stopping.
RedHat/Fedora
6a. Edit the comment line in your /etc/init.d/ofbiz, starting with # chkconfig, to reflect specific runlevels at which to start your service, and the order in which to start it. For instance the following says "start ofbiz in runlevels 2, 3, 4 and 5, at position 21. At any other runlevels (ie 1 and 6), stop OFBiz in position 19."
# chkconfig: 2345 21 19
6b. Now execute the following command as root
chkconfig --add ofbiz
Debian/Ubuntu
6a. Execute the following commands as a user with sudo permissions (on a typical Ubuntu installation, this means a member of the admin group). Do not omit the two dots in the second command, they are important.
sudo update-rc.d -f ofbiz remove
sudo update-rc.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.
#!/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
#!/bin/sh JAVA_BINARY=/export/home/ofbiz/jdk1.6.0_13/bin/java
OFBIZ_HOME=/export/home/ofbiz/ofbiz
OFBIZ_LOG=$OFBIZ_HOME/runtime/logs/console.log JAVA_VMOPTIONS="-Xms768M -Xmx1024M -Duser.language=en"
JAVA_ARGS="-jar ${OFBIZ_HOME}/ofbiz.jar"
OFBIZ_USER=ofbiz ofbizprocs() {
OFBIZ_PROCS=`pgrep -u ${OFBIZ_USER} java`
} start() {
echo "Starting OFBiz: "
ofbizprocs
if [ "$OFBIZ_PROCS" != "" ]; then
echo "OFBiz is already running..."
return 1
fi # All clear
cd $OFBIZ_HOME
umask 007
/bin/rm -f $OFBIZ_LOG
su - ofbiz -c "cd $OFBIZ_HOME && $JAVA_BINARY $JAVA_VMOPTIONS
$JAVA_ARGS >>$OFBIZ_LOG 2>>$OFBIZ_LOG&"
echo "startup return value: " $?
return 0
} # Stop OFBiz
stop() {
echo -n "Stopping OFBiz: "
ofbizprocs
if [ "$OFBIZ_PROCS" = "" ]; then
echo "OFBiz is not running..."
return 1
fi # All clear
cd $OFBIZ_HOME
umask 007
su - ofbiz -c "cd $OFBIZ_HOME && $JAVA_BINARY $JAVA_VMOPTIONS
$JAVA_ARGS -shutdown >>$OFBIZ_LOG"
ofbizprocs
if [ "$OFBIZ_PROCS" != "" ]; then
# Let's try to -TERM
/bin/kill -TERM $OFBIZ_PROCS
fi
ofbizprocs
if [ "$OFBIZ_PROCS" != "" ]; then
# Let's try it the hard way!
/bin/kill -9 $OFBIZ_PROCS
fi
ofbizprocs
if [ "$OFBIZ_PROCS" != "" ]; then
echo "Some processes could not be stopped:"
echo $OFBIZ_PROCS
echo "A possible solution is to try this command once more!"
return 1
else
return 0
fi
} case "$1" in
'start')
start
;;
'stop')
stop
;;
'restart')
stop
start
;;
'status')
ofbizprocs
if [ "$OFBIZ_PROCS" = "" ]; then
echo "OFBiz is stopped"
exit 1
else
echo "OFBiz is running"
exit 0
fi
;;
*)
echo "Usage: $0 {start|stop|kill|restart|status|help}"
exit 1
;;
esac
echo
exit $?
7. Fire 'er up!
Let's test the fecker ! We need to restart the machine. Your distro may offer a graphical option for this but the standard unix command, to be executed via root or sudo, is the following. Run it, wait a wee while, then try to login to your OFBiz from another machine on your LAN!
shutdown -r now
OS X (10.4+)
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:
<?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>./startofbiz.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
You can change the RunAtLoad property if you want to stop OFBiz auto-starting.
2. To test the startup script you use launchctl. The following command will start OFBiz as the current user:
$ launchctl load org.apache.ofbiz.plist
You can view the status and process ID by running:
$ launchctl list | grep ofbiz
To unload the service after confirming it is working, run:
$ launchctl unload org.apache.ofbiz.plist
3. Deploy the startup script (assumes running as root):
$ 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.
$ 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):
$ sudo launchctl stop org.apache.ofbiz
To Start
$ sudo launchctl start org.apache.ofbiz
How to run OFBiz as a Service on linux的更多相关文章
- How To Install WildFly as a Service on Linux
Installing WildFly as a service on Linux has multiple advantages like automatic start on system boot ...
- HowTo: Restart SSH Service under Linux / UNIX
How do I restart SSH service under Linux or UNIX operating systems? The command to restart ssh are a ...
- 【Azure 应用服务】App Service For Linux 如何在 Web 应用实例上住抓取网络日志
问题描述 在App Service For Windows的环境中,我们可以通过ArmClient 工具发送POST请求在Web应用的实例中抓取网络日志,但是在App Service For Linu ...
- 【Azure 应用服务】App Service For Linux 部署Java Spring Boot应用后,查看日志文件时的疑惑
编写Java Spring Boot应用,通过配置logging.path路径把日志输出在指定的文件夹中. 第一步:通过VS Code创建一个空的Spring Boot项目 第二步:在applicat ...
- 【Azure 应用服务】App Service for Linux 中实现 WebSocket 功能 (Python SocketIO)
问题描述 使用 python websockets 模块作为Socket的服务端,发布到App Service for Linux环境后,发现Docker Container无法启动.错误消息为: 2 ...
- 【Azure 应用服务】Azure App Service For Linux 上实现 Python Flask Web Socket 项目 Http/Https
问题描述 在上篇博文"[Azure 应用服务]App Service for Linux 中实现 WebSocket 功能 (Python SocketIO)"中,实现了通过 HT ...
- 【Azure 应用服务】部署Jar到App Service for Linux,因启动命令路径配置错误而引起:( Application Error 问题
问题描述 App Service for Linux 资源创建完成后,通过FTP方式把 .jar包(logdemo.jar)包上传到 /site/wwwroot/ 文件夹后,在App Service的 ...
- 【Azure 应用服务】PHP应用部署在App Service for Linux环境中,上传文件大于1MB时,遇见了413 Request Entity Too Large 错误的解决方法
问题描述 在PHP项目部署在App Service后,上传文件如果大于1MB就会遇见 413 Request Entity Too Large 的问题. 问题解决 目前这个问题,首先需要分析应用所在的 ...
- 【Azure 应用服务】App Service For Linux 部署PHP Laravel 项目,如何修改首页路径为 wwwroot\public\index.php
问题描述 参考官方文档部署 PHP Laravel 项目到App Service for Linux环境中,但是访问应用时候遇见了500 Server Error 错误. 从部署的日志中,可以明确看出 ...
随机推荐
- Java中线程池的学习
线程池的基本思想还是一种对象池的思想,开辟一块内存空间,里面存放了众多(未死亡)的线程,池中线程执行调度由池管理器来处理.当有线程任务时,从池中取一个,执行完成后线程对象归池,这样可以避免反复创建线程 ...
- 编程之美2015初赛第一场 hihoCoder #1156 : 彩色的树(染色问题)
#1156 : 彩色的树 时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给定一棵n个节点的树,节点编号为1, , …, n.树中有n - 1条边,任意两个节点间恰好有一条 ...
- Activity与Fragment之间的通信
由于Fragment的生命周期完全依赖宿主Activity,所以当我们在使用Fragment时难免出现Activity和Fragment间的传值通信操作. 1.Activity向Fragment,通过 ...
- python calendar标准库基础学习
# -*- coding: utf-8 -*-# 作者:新手__author__ = 'Administrator'#标准库:日期时间基础学习:calendar:处理日期#例1import calen ...
- [Redux] Generating Containers with connect() from React Redux (VisibleTodoList)
Learn how to use the that comes with React Redux instead of the hand-rolled implementation from the ...
- [CSAPP笔记][第十章 系统级I/O]
第十章 系统级I/O 输入/输出(I/O) : 是指主存和外部设备(如磁盘,终端,网络)之间拷贝数据过程. 高级别I/O函数 scanf和printf <<和>> 使用系统级I ...
- asp.net实现将网页内容输出到word并下载到本地
个人觉得要实现这个功能如果没有类库提供的几个关键函数,还是比较繁琐的.所以首先介绍几个将要在代码中使用的关键函数和参数,然后再说函数实现.注意问题等. 关键函数: 1.函数原型:Response.Ap ...
- scala中的view bound与context bound
1.scala中的<%意识是“view bounds”(视界) ,它比<:的使用范围更广,还能进行隐式转换,是一种语法糖. 下面的两种写法是等效的,在编译之后完全一样. object Te ...
- 附加到IIS调试出现不会命中断点
当项目附加到IIS进行调试时,如果在IIS中没有配置该项目则在设置断点是会出现:当前不会命中断点 还没有为该文档加载任何符号
- (转) .NET实现Repeater控件+AspNetPager控件分页
SqlConnection (.NET C#) 连接及分页 .net的访问数据机制决定了访问大量数据时会致使客户端机器消耗大量资源,因此有必要对数据进行分页显示,开发工具vs.net+sqlserve ...