java daemon - jvm install and daemon coding

in #java7 years ago (edited)

java jdk down
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

linux - getconf LONG_BIT
=> 64bit

gunzip jdk-8u151-linux-x64.tar.gz

tar -xvf jdk-8u151-linux-x64.tar

mv jdk1.8.0_151 /usr/local/jdk1.8.0_151

cd /usr/local/

ln -s jdk1.8.0_151/ java

vi /etc/profile

JAVA_HOME=/usr/local/java
CLASSPATH=.:$JAVA_HOME/lib/tools.jar
PATH=$PATH:$JAVA_HOME/bin
export JAVA_HOME CLASSPATH PATH
===

source /etc/profile



wget http://mirror.apache-kr.org//commons/daemon/source/commons-daemon-1.0.15-src.tar.gz wget http://www.apache.org/dist/commons/daemon/binaries/commons-daemon-1.0.15.jar

tar -xzvf commons-daemon-1.0.15-src.tar.gz

cd commons-daemon-1.0.15-src/src/native/unix/

yum install libtool
yum install gcc

support/buildconf.sh

./configure --with-java=/usr/local/java
or
export JAVA_HOME=/usr/local/jdk1.8.0_151
./configure

  • java dir
    type -p java => /usr/local/java/bin/java

mv jsvc /home/ec2-user/daemon/

cp -r /home/ec2-user/daemon/commons-daemon-1.0.15-src/src/samples /home/ec2-user/daemon/

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

vi test.sh

#!/bin/sh
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

javac -d . SimpleApplication.java

jar cvf SimpleApplication.jar ./SimpleApplication*.class