How to deploy a Java Linux Daemon with Java Servcie Wrapper

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.