码迷,mamicode.com
首页 > 移动开发 > 详细

How to deploy a Java Linux Daemon with Java Servcie Wrapper

时间:2014-12-03 14:12:33      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   ar   color   os   sp   

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/

 

How to deploy a Java Linux Daemon with Java Servcie Wrapper

标签:des   style   blog   http   io   ar   color   os   sp   

原文地址:http://www.cnblogs.com/ouxingning/p/java_daemon_servcie.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!