本文介绍如何使用java wrapper service,步骤如下:(已在CentOS5.1 linux下测试通过)
1.从http://wrapper.tanukisoftware.org/doc/english/download.jsp
下载 wrapper-linux-x86-32-3.3.1.tar(请使用Community版本,因Professional和Standard版本需要购买Licenses);
2.解压wrapper-linux-x86-32-3.3.1.tar为wrapper-linux-x86-32-3.3.1;
3.准备应该程序(app)的目录,包括bin,conf,lib,logs:
4.拷贝wrapper-linux-x86-32-3.3.1\bin\wrapper(为二进制文件) 到bin\;
5.拷贝wrapper-linux-x86-32-3.3.1\src\bin\sh.script.in到bin\,并改名为app,将app用到的配置文件都拷贝到该目录下,包括.ini,.xml;
6.拷贝wrapper-linux-x86-32-3.3.1\src\conf\wrapper.conf.in到conf\,并改名为wrapper.conf;
7.拷贝wrapper-linux-x86-32-3.3.1\lib\wrapper.jar,libwrapper.so到lib\,将app用到的jar包也拷贝到该目录下;
8.编辑app,设置应用程序的名称(编辑时请使用NotePad2或EditPlus)
# Application
APP_NAME="MailSender"
APP_LONG_NAME="MailSender Application"
9.编辑wrapper.conf
#********************************************************************
# Wrapper Java Properties
#********************************************************************
# Java Application
wrapper.java.command=/usr/java/jdk1.5.0/bin/java
# Java Main class. This class must implement the WrapperListener interface
# or guarantee that the WrapperManager class is initialized. Helper
# classes are provided to do this for you. See the Integration section
# of the documentation for details.
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp #默认使用
# Java Classpath (include wrapper.jar) Add class path elements as
# needed starting from 1
wrapper.java.classpath.1=../lib/wrapper.jar
wrapper.java.classpath.2=../lib/classes12.jar #其它引入jar
wrapper.java.classpath.3=../lib/activation.jar #其它引入jar
wrapper.java.classpath.4=../lib/mail.jar #其它引入jar
wrapper.java.classpath.5=../lib/App.jar #当前应用jar
# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=../lib #Windows 版本使用Wrapper.DLL,Linux版本使用libwrapper.so
# Application parameters. Add parameters as needed starting from 1
wrapper.app.parameter.1=com.wisdom.mail.Main #app应用启动类
#********************************************************************
# Wrapper Windows Properties
#********************************************************************
# Title to use when running as a console
wrapper.console.title=AppName Application
10.使用ssh将app目录上传到linux服务器的/usr/local/app下;
11.登陆ssh,执行:
#chmod 755 /usr/local/app
#cd /usr/local/app/bin
#sudo chmod 755 app
#sudo chmod 755 wrapper
完成部署;
最后一个命令解决:Unable to locate any of the following binaries:
/app/bin/./wrapper-linux-x86-32
/app/bin/./wrapper-linux-x86-64
/app/./wrapper (Found but not executable.) 问题;
12.执行命令:/usr/local/app/bin/app console|start|stop|restart 即可以启动服务了。
如果要检查服务是否执行正常,可先使用console参数,如果正常就可以使用start来启动服务了。
Usage: /usr/local/TserverProxy/bin/app [ console | start | stop | restart | condrestart | status | install | remove | dump ]
Commands:
console Launch in the current console.
start Start in the background as a daemon process.
stop Stop if running as a daemon or in another console.
restart Stop if running and then start.
condrestart Restart only if already running.
status Query the current status.
install Install to start automatically when system boots.
remove Uninstall.
dump Request a Java thread dump if running.