LINUX
2019.07.16 / 18:42

Linux - Java µ¥¸ó ½ÇÇà(Apache commons daemon, Jsvc)

Źµ¹ÀÌ°³¹ßÀÚ
Ãßõ ¼ö 256

# jsvc ¼³Ä¡¹× java µ¥¸ó »ùÇà ±¸µ¿¹× ÁßÁö


Âü°í ÀÚ·á :
 http://commons.apache.org/proper/commons-daemon/jsvc.html

jsvc¸¦ ÀÌ¿ëÇÑ Linux ¿î¿µÃ¼Á¦¿¡¼­ java ÇÁ·Î¼¼½º¸¦ µ¥¸óÇü½Ä(¹é±×¶ó¿îµå)À¸·Î ½ÇÇà¹× ÁßÁö

»ùÇà ÀÚ·á À§Ä¡ : commons-daemon-1.0.15-src/src/samples


> µð·ºÅ丮 »ý¼º¹× À̵¿

[sunshiny@node01 ~]$ pwd
/home/sunshiny
[sunshiny@node01 ~]$ mkdir commons-daemon
[sunshiny@node01 ~]$ cd commons-daemon


> µ¥¸ó ¼Ò½º¹×  jar ÆÄÀÏ ´Ù¿î·Îµå

[sunshiny@node01 ]$ wget http://mirror.apache-kr.org//commons/daemon/source/commons-daemon-1.0.15-src.tar.gz
[sunshiny@node01 ]$ wget http://www.apache.org/dist/commons/daemon/binaries/commons-daemon-1.0.15.jar

[sunshiny@node01 ]$ ls
commons-daemon-1.0.15.jar  commons-daemon-1.0.15-src.tar.gz


> µ¥¸ó ¼Ò½º ¾ÐÃà ÇØÁ¦

[sunshiny@node01 ]$ tar -xzvf commons-daemon-1.0.15-src.tar.gz


> µð·ºÅ丮 À̵¿

[sunshiny@node01 ]$ cd commons-daemon-1.0.15-src/src/native/unix/
[sunshiny@node01 ]$ ls
CHANGES.txt  configure  configure.in  INSTALL.txt  Makedefs.in  Makefile.in  man  native  support


> buildconf ½ºÅ©¸³Æ® ½ÇÇà(autoconf: command not found ¿¡·¯ ¹ß»ý½Ã ¸Ç ¾Æ·¡ ÂüÁ¶)

[sunshiny@node01 ]$ support/buildconf.sh 
support/buildconf.sh: configure script generated successfully


> java ȨÁ¤º¸¸¦ ¼³Á¤ÈÄ ½Ã½ºÅÛ configure ½ÇÇà

[sunshiny@node01 ]$ ./configure --with-java=/usr/java_home
¶Ç´Â
[sunshiny@node01 ]$ export JAVA_HOME=/usr/java/jdk1.6.0_45
[sunshiny@node01 ]$ ./configure


> jsvc »ý¼º

[sunshiny@node01 ]$ make


> jsvc Á¶È¸

[sunshiny@node01 ]$ ls
autom4te.cache  config.nice    configure.in  Makedefs     Makefile.in  support
CHANGES.txt     config.status  INSTALL.txt   Makedefs.in  man
config.log      configure      jsvc          Makefile     native

[sunshiny@node01 ]$ ./jsvc -help
Usage: jsvc [-options] class [args...]

Where options include:

    -help | --help | -?
        show this help page (implies -nodetach)
    -jvm <JVM name>
        use a specific Java Virtual Machine. Available JVMs:
            'server'
    -client
        use a client Java Virtual Machine.
    -server
        use a server Java Virtual Machine.
    -cp | -classpath <directories and zip/jar files>
        set search path for service classes and resouces
    -java-home | -home <directory>
        set the path of your JDK or JRE installation (or set
        the JAVA_HOME environment variable)
    -version
        show the current Java environment version (to check
        correctness of -home and -jvm. Implies -nodetach)
    -showversion
        show the current Java environment version (to check
        correctness of -home and -jvm) and continue execution.
    -nodetach
        don't detach from parent process and become a daemon
    -debug
        verbosely print debugging information
    -check
        only check service (implies -nodetach)
    -user <user>
        user used to run the daemon (defaults to current user)
    -verbose[:class|gc|jni]
        enable verbose output
    -cwd </full/path>
        set working directory to given location (defaults to /)
    -outfile </full/path/to/file>
        Location for output from stdout (defaults to /dev/null)
        Use the value '&2' to simulate '1>&2'
    -errfile </full/path/to/file>
        Location for output from stderr (defaults to /dev/null)
        Use the value '&1' to simulate '2>&1'
    -pidfile </full/path/to/file>
        Location for output from the file containing the pid of jsvc
        (defaults to /var/run/jsvc.pid)
    -D<name>=<value>
        set a Java system property
    -X<option>
        set Virtual Machine specific option
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
        enable assertions
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
        disable assertions
    -esa | -enablesystemassertions
        enable system assertions
    -dsa | -disablesystemassertions
        disable system assertions
    -agentlib:<libname>[=<options>]
        load native agent library <libname>, e.g. -agentlib:hprof
    -agentpath:<pathname>[=<options>]
        load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
        load Java programming language agent, see java.lang.instrument
    -procname <procname>
        use the specified process name
    -wait <waittime>
        wait waittime seconds for the service to start
        waittime should multiple of 10 (min=10)
    -stop
        stop the service using the file given in the -pidfile option
    -keepstdin
        does not redirect stdin to /dev/null

jsvc (Apache Commons Daemon) 1.0.15-dev
Copyright (c) 1999-2013 Apache Software Foundation.


> jsvc ÆÄÀÏÀ» »ç¿ëµÉ À§Ä¡·Î À̵¿

[sunshiny@node01 ]$ mv jsvc ~/commons-daemon/
[sunshiny@node01 ]$ cd ~/commons-daemon/



# java µ¥¸ó »ùÇà ±¸µ¿


> commons-daemon-1.0.15-src/src/samples µð·ºÅ丮ÀÇ »ùÇà ÆÄÀÏ º¹»ç

[sunshiny@node01 ]$ cp -r samples ~/commons-daemon/
[sunshiny@node01 ]$ cd ~/commons-daemon/samples/


> µ¥¸ó ±¸µ¿¹× ÁßÁö ½ºÅ©¸³Æ® ¼³Á¤
[sunshiny@node01 ]$ vi SimpleApplication.sh 

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Small shell script to show how to start the sample services.
#
# Adapt the following lines to your configuration
JSVC_HOME=/home/sunshiny/commons-daemon      # jsvc ÆÄÀÏ À§Ä¡ µð·ºÅ丮
JAVA_HOME=/usr/java/jdk1.6.0_45
PROGRAM=SimpleApplication
CLASSPATH=`pwd`/$PROGRAM.jar:`pwd`/commons-daemon-1.0.15.jar
 
case "$1" in
  start )
    shift
    $JSVC_HOME/jsvc \
        -home $JAVA_HOME \
        -cp $CLASSPATH \
        -nodetach \
        -errfile "&2" \
        -pidfile `pwd`/$PROGRAM.pid \
        @$PROGRAM \
        -start-method main \
        $*
    exit $?
    ;;
  stop )
    shift
    $JSVC_HOME/jsvc \
        -home $JAVA_HOME \
        -cp $CLASSPATH \
        -stop \
        -nodetach \
        -errfile "&2" \
        -pidfile `pwd`/$PROGRAM.pid \
        @$PROGRAM \
        -start-method main \
        $*
    exit $?
    ;;
    * )
    echo 'Usage SimpleApplication.sh start | stop'
    exit 1
    ;;
esac 



> SimpleApplication ÄÄÆÄÀÏ

[sunshiny@node01 ]$ javac -d . SimpleApplication.java
Note: SimpleApplication.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

[sunshiny@node01 ]$ ls SimpleApp* commons*
commons-daemon-1.0.15.jar        SimpleApplication$ShutdownHook.class
SimpleApplication.class          SimpleApplication.java
SimpleApplication$Handler.class  SimpleApplication.sh


> ÄÄÆÄÀÏµÈ SimpleApplication.class ÆÄÀÏ ¸ðµÎ jar·Î ¹­À½

[sunshiny@node01 ]$ jar cvf SimpleApplication.jar ./SimpleApplication*.class
added manifest
adding: SimpleApplication.class(in = 3901) (out= 2024)(deflated 48%)
adding: SimpleApplication$Handler.class(in = 4431) (out= 2408)(deflated 45%)
adding: SimpleApplication$ShutdownHook.class(in = 773) (out= 491)(deflated 36%)

[sunshiny@node01 ]$ ls SimpleApp* commons*
commons-daemon-1.0.15.jar        SimpleApplication.jar   SimpleApplication$ShutdownHook.class
SimpleApplication.class          SimpleApplication.java
SimpleApplication$Handler.class  SimpleApplication.sh


> µ¥¸ó ½ºÅ©¸³Æ® ±¸µ¿¹× ÁßÁö

[sunshiny@node01 ]$ ./SimpleApplication.sh 
Usage SimpleApplication.sh start | stop

[sunshiny@node01 ]$ ./SimpleApplication.sh start
SimpleApplication: instance 2103957824 created
SimpleApplication: instance 2103957824 init 0
SimpleApplication: loading on port 1200
SimpleApplication: starting
SimpleApplication: started acceptor loop

[sunshiny@node01 ]$ ./SimpleApplication.sh stop
SimpleApplication: stopping
SimpleApplication: exiting acceptor loop
SimpleApplication: stopped




> buildconf.sh ¿¡·¯

[sunshiny@node01 ]$ support/buildconf.sh
support/buildconf.sh: line 25: autoconf: command not found
support/buildconf.sh: cannot generate configure script

> libtool ÆÐÅ°Áö ¼³Ä¡ÈÄ ´Ù½Ã ÁøÇà
[sunshiny@node01 ]$ yum install libtool