How to deploy a Java Linux Daemon with Java Servcie Wrapper

Java Service Wrapper (http://wrapper.tanukisoftware.com/doc/english/integrate.html) is a tool that provides a set of binaries and scripts for different architectures and operating systems that allow Java developers to run a Java application as a service daemon.

For this post I used a 64-bit CentOS PC as a server.

The source code of my test program is :

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author XingNing OU
 */
public class SegmentServiceMain {

    public static void main(String[] args) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

        while (true) {
            System.out.println(sdf.format(new Date()));
            try {
                Thread.sleep(2000L);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

}

 

1. Preparing the environment:

# mkdir -p /data/app/segment/bin
# mkdir -p /data/app/segment/conf
# mkdir -p /data/app/segment/logs
# cp -r segment.jar /data/app/segment/bin/

 

2. Download and install Java Service Wrapper for Linux:

# wget http://wrapper.tanukisoftware.com/download/3.5.25/wrapper-linux-x86-64-3.5.25.tar.gz

3. Extract the package and copy the files needed:

# tar -zxvf wrapper-linux-x86-64-3.5.25.tar.gz
# cd wrapper-linux-x86-64-3.5.25
# cp bin/wrapper /data/app/segment/bin/
# cp src/bin/sh.script.in /data/app/segment/bin/
# cp lib/* /data/app/segment/bin/
# cp conf/wrapper.conf /data/app/segment/conf/

4. Rename the servcie script and set correct permissions:

# cd /data/app/segment/bin/
# mv sch.script.in segment-service
# chmod +x segment-servcie

5. Changeing some directive from the config file (wrapper.conf)

6. Edit inti script (segment-service)

7. Run the application at boot time:

# ln -s /data/app/segment/bin/segment-service /etc/init.d/segment-service
# chkconfig --levels 235 segment-service on

 

Reference:

http://opentodo.net/2013/03/deploying-java-unix-daemon-with-java-service-wrapper/

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。