转自:http://opentodo.net/2013/03/deploying-java-unix-daemon-with-java-service-wrapper/
- Preparing the environment:
1
2
3
4
|
# mkdir -p /usr/local/queuesApp/bin/
# mkdir /usr/local/queuesApp/conf
# mkdir /usr/local/queuesApp/logs
# cp -r rabbitmqConsumer.jar lib/ /usr/local/queuesApp/bin/
|
- Preparing the environment:
1
2
3
4
|
# mkdir -p /usr/local/queuesApp/bin/
# mkdir /usr/local/queuesApp/conf
# mkdir /usr/local/queuesApp/logs
# cp -r rabbitmqConsumer.jar lib/ /usr/local/queuesApp/bin/
|
- Download and install java service wrapper for Linux:
- 32 bits systems:
- 64 bits systems:
- Extract the package and copy the files needed:
1
2
3
4
5
6
|
# tar -xzvf wrapper-linux-x86-*-3.5.17.tar.gz
# cd wrapper-linux-x86-*-3.5.17/
# cp bin/wrapper /usr/local/queuesApp/bin/
# cp src/bin/sh.script.in /usr/local/queuesApp/bin/
# cp lib/* /usr/local/queuesApp/bin/
# cp conf/wrapper.conf /usr/local/queuesApp/conf/
|
- Rename the service script and set correct permissions:
1
2
3
|
# cd /usr/local/queuesApp/bin/
# mv sh.script.in consumer-daemon
# chmod +x consumer-daemon
|
- Changing some directive from the config file for our application:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# cd /usr/local/queuesApp/conf/
# vi wrapper.conf
#********************************************************************
# Wrapper Java Properties
#********************************************************************
# Java Application
# Locate the java binary on the system PATH:
wrapper.java.
command
=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.WrapperJarApp
# Java Classpath (include wrapper.jar) Add class path elements as
# needed starting from 1
wrapper.java.classpath.1=..
/bin/wrapper
.jar
# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=..
/bin
# Application parameters. Add parameters as needed starting from 1
wrapper.app.parameter.1=..
/bin/rabbitmqConsumer
.jar
|
- wrapper.java.command : It’s the path for the java binary, by default in Linux it’s found in the PATH.
- wrapper.java.mainclass: The main class to load our program, it may be different depending of the integration method used.
- wrapper.java.classpath.1 : the location for the wrapper jar.
- wrapper.java.library.path.1 : The path for the wrapper binary.
- wrapper.app.parameter.1 : The jar package for our program.
- Edit init script:
1
2
3
4
|
# vi /usr/local/queuesApp/bin/consumer-daemon
APP_NAME=
"consumer-daemon"
APP_LONG_NAME=
"Consumer Java Daemon for RabbitMQ"
|
- Run the aplication at boot time:
1
2
|
# ln -s /usr/local/queuesApp/bin/consumer-daemon /etc/init.d/consumer-daemon
# chkconfig --levels 235 consumer-daemon on
|