java service wrapper 在linux下實現jar用服務啟動 __linux

來源:互聯網
上載者:User

 這個東西我調查了好幾天,累啊不過還是沒有搞得很清楚,不過也有點收穫了(linux)

windows的網路上很多 ,不多說了,不過conf/wrapper.conf這個檔案差不多的


安裝JDK,此處略過。比如你的projecct安裝在/usr/local/myP目錄中。

使用命令wget 下載Java Service Wrapper(目前版本wrapper-linux-x86-32-3.2.3,官網:http://wrapper.tanukisoftware.org), 用命令tar -zxvc wrapper-linux-x86-32-3.2.3.tar.gz 解壓,得到目錄wrapper-linux-x86-32-3.2.3,使用ln -s wrapper-linux-x86-32-3.2.3 wrapper 給目錄wrapper-linux-x86-32-3.2.3 建一個名稱為wrapper的捷徑。

複製wrapper/src/bin/sh.script.in到/usr/local/myP/bin目錄,重新命名為tomcat

複製wrapper/src/conf/wrapper.conf.in到//usr/local/myP/conf目錄,重新命名為wrapper.conf

複製wrapper/src/lib/lib目錄下的所有3個檔案到/usr/local/myP/lib目錄

複製wrapper/bin目錄下的wrapper檔案到/usr/local/myP/bin目錄

修改/usr/local/myP/bin/tomcat檔案

APP_NAME="Servername  "

APP_LONG_NAME="Servername  Server"

WRAPPER_CMD="./wrapper"

WRAPPER_CONF="../conf/wrapper.conf"


#********************************************************************

# Wrapper Properties

#********************************************************************

# Java Application

wrapper.java.command=%JAVA_HOME%/bin/java       //系統需要設定JAVA_HOME


# 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/wrappertest.jar

wrapper.java.classpath.3=../bin/log4j-1.2.8.jar

wrapper.java.classpath.4=../bin/.

wrapper.java.classpath.5=../bin/myP.jar   //需要載入的包,這個包是你需要啟動並執行jar包,是需要載入的


# Java Library Path (location of Wrapper.DLL or libwrapper.so)

wrapper.java.library.path.1=../lib


# Java Additional Parameters

#wrapper.java.additional.1=


# Initial Java Heap Size (in MB)

#wrapper.java.initmemory=3


# Maximum Java Heap Size (in MB)

#wrapper.java.maxmemory=64


# Application parameters.  Add parameters as needed starting from 1

wrapper.app.parameter.1=com.client.ProcessMain   //是需要執行的mian函數(myP.jar )


#********************************************************************

# Wrapper Logging Properties

#********************************************************************

# Format of output for the console.  (See docs for formats)

wrapper.console.format=PM


# Log Level for console output.  (See docs for log levels)

wrapper.console.loglevel=INFO


# Log file to use for wrapper output logging.

wrapper.logfile=../logs/wrapper.log


# Format of output for the log file.  (See docs for formats)

wrapper.logfile.format=LPTM


# Log Level for log file output.  (See docs for log levels)

wrapper.logfile.loglevel=INFO


# Maximum size that the log file will be allowed to grow to before

#  the log is rolled. Size is specified in bytes.  The default value

#  of 0, disables log rolling.  May abbreviate with the 'k' (kb) or

#  'm' (mb) suffix.  For example: 10m = 10 megabytes.

wrapper.logfile.maxsize=0


# Maximum number of rolled log files which will be allowed before old

#  files are deleted.  The default value of 0 implies no limit.

wrapper.logfile.maxfiles=0


# Log Level for sys/event log output.  (See docs for log levels)

wrapper.syslog.loglevel=NONE


#********************************************************************

# Wrapper Windows Properties

#********************************************************************

# Title to use when running as a console

wrapper.console.title=WebAPFWonline Service     //看英文 名字


#********************************************************************

# Wrapper Windows NT/2000/XP Service Properties

#********************************************************************

# WARNING - Do not modify any of these properties when an application

#  using this configuration file has been installed as a service.

#  Please uninstall the service before modifying this section.  The

#  service can then be reinstalled.


# Name of the service

wrapper.ntservice.name=Servername  //服務名


# Display name of the service

wrapper.ntservice.displayname=Servername Service  //顯示的服務名


# Description of the service

wrapper.ntservice.description=Servername Service  //服務描述


# Service dependencies.  Add dependencies as needed starting from 1

wrapper.ntservice.dependency.1=


# Mode in which the service is installed.  AUTO_START or DEMAND_START

wrapper.ntservice.starttype=AUTO_START     //自動啟動


# Allow the service to interact with the desktop.

wrapper.ntservice.interactive=false


把ln   -s   /usr/asc/Servername      /etc/init.d    
注意( /usr/asc/Servername一定要全路徑,否則是一個複製的是個無效檔案)

     /etc/init.d/Appserver     start   這樣就可以了 測試了

注意:

如果我把wrapper.java.command=%JAVA_HOME%/bin/java        

寫成系統jdk的全路徑  /usr/java/jdk/bin/java

那麼         /usr/asc路徑下       運行       ./Appserver       start       是可以的

其他路徑下       運行       service       Appserver       start       也可以運行.  

估計service這個命令   不給他指定JAVA_HOME   可能讀不到JAVA_HOME了

這個我也不太清楚

(service       Appserver       start 會出現
Unable   to   locate   any   of   the   following   binaries:
    /etc/rc.d/init.d/./wrapper-linux-x86-32
    /etc/rc.d/init.d/./wrapper-linux-x86-64
    /etc/rc.d/init.d/./wrapper  錯誤)
或者無法啟動jvm(service       Appserver      console中提示)



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.