Skip to main content

Making debian file for java application.

Making debian file for java application.

ㅇ deployed resources
/opt/testApp/bin/testApp.jar
/etc/testApp/testApp.conf
/etc/testApp/log4j.conf

ㅇ Preparation
1. install dpkg-deb
ㅇ install debian packaging
# install macport
https://guide.macports.org/#installing.macports
cd /opt/local/bin
sudo port selfupdate
sudo port install dpkg

brew install dpkg
2. make jar in dist/lib
        3. init file in /testApp/etc/init/testApp.conf

ㅇ Make debian for jar

VERSION="0.0.1"
PROJ_NAME="testApp"

#now we build .deb package
mkdir -p builds
rm -rf builds/$VERSION
mkdir -p builds/$VERSION/$PROJ_NAME/etc/$PROJ_NAME
mkdir -p builds/$VERSION/$PROJ_NAME/opt/$PROJ_NAME/bin
mkdir -p builds/$VERSION/$PROJ_NAME/opt/$PROJ_NAME/log
mkdir -p builds/$VERSION/$PROJ_NAME/DEBIAN/

# debian control file
echo "Package: $PROJ_NAME" >> builds/$VERSION/$PROJ_NAME/DEBIAN/control
echo "Architecture: amd64" >> builds/$VERSION/$PROJ_NAME/DEBIAN/control
echo "Maintainer: Dewey Hong" >> builds/$VERSION/$PROJ_NAME/DEBIAN/control
echo "Priority: optional" >> builds/$VERSION/$PROJ_NAME/DEBIAN/control
echo "Version: $VERSION" >> builds/$VERSION/$PROJ_NAME/DEBIAN/control
echo "Description: $PROJ_NAME" >> builds/$VERSION/$PROJ_NAME/DEBIAN/control

# debian conffiles file
echo "etc/$PROJ_NAME/$PROJ_NAME.conf" >> builds/$VERSION/$PROJ_NAME/DEBIAN/conffiles
echo "etc/$PROJ_NAME/log4j.conf" >> builds/$VERSION/$PROJ_NAME/DEBIAN/conffiles

# debian preinst file
echo "#!/bin/sh" >> builds/$VERSION/$PROJ_NAME/DEBIAN/preinst
echo "set -e" >> builds/$VERSION/$PROJ_NAME/DEBIAN/preinst
echo "if [ \"\$(pidof $PROJ_NAME)\" ] " >> builds/$VERSION/$PROJ_NAME/DEBIAN/preinst
echo "then" >> builds/$VERSION/$PROJ_NAME/DEBIAN/preinst
echo " echo \"stoping $PROJ_NAME \"" >> builds/$VERSION/$PROJ_NAME/DEBIAN/preinst
echo " stop $PROJ_NAME" >> builds/$VERSION/$PROJ_NAME/DEBIAN/preinst
echo "fi" >> builds/$VERSION/$PROJ_NAME/DEBIAN/preinst
chmod 775 builds/$VERSION/$PROJ_NAME/DEBIAN/preinst

# copy files where they need to be
cp dist/lib/$PROJ_NAME.jar  builds/$VERSION/$PROJ_NAME/opt/$PROJ_NAME/bin/$PROJ_NAME.jar
cp src/main/resources/localhost.conf  builds/$VERSION/$PROJ_NAME/etc/$PROJ_NAME/$PROJ_NAME.conf
cp src/main/resources/log4j.conf  builds/$VERSION/$PROJ_NAME/etc/$PROJ_NAME/log4j.conf

# make debian
dpkg-deb --build builds/$VERSION/$PROJ_NAME
DEBIAN=${PROJ_NAME}-${VERSION}_amd64.deb
echo mv builds/$VERSION/$PROJ_NAME.deb builds/$VERSION/$DEBIAN
mv builds/$VERSION/$PROJ_NAME.deb builds/$VERSION/$DEBIAN


= [testApp.conf] =================================================
#!upstart
description "testApp"
author      "Dewey Hong"

# used to be: start on startup
# until we found some mounts weren't ready yet while booting:
start on runlevel [2345]
stop on runlevel [016]

# Automatically Respawn:
respawn
respawn limit 99 5

#modify limits
limit nofile 64000 64000

env PROJ_NAME=testApp
env JMX_PORT=28001
env JDB_PORT=28002

script
    ulimit -n 65000
    # Not sure why $HOME is needed, but it is:
    export HOME="/root"
    export JARFILE="/opt/$PROJ_NAME/bin/$PROJ_NAME.jar"
    export IPADDR=`ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'|head -n 1`
    
# configure the -Dproperties
    #JOPTS="-Xmx xxx -Xms=xxx -Xmn xxx"
    JOPTS="$JOPTS -server -Djava.net.preferIPv4Stack=true"
    JOPTS="$JOPTS -Xmx1G -Xms1G -Xmn128M -XX:+UseParNewGC -XX:ParallelCMSThreads=2 -XX:+UseConcMarkSweepGC -Xloggc:/var/log/testApp/gc.log -XX:+PrintGCDateStamps"
    JOPTS="$JOPTS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$JDB_PORT"
    JOPTS="$JOPTS -Dsun.jnu.encoding=ISO-8859-1 -Dfile.encoding=ISO-8859-1"
    JOPTS="$JOPTS -Djava.rmi.server.hostname=$IPADDR \
  -Dcom.sun.management.jmxremote \
           -Dcom.sun.management.jmxremote.port=$JMX_PORT \
           -Dcom.sun.management.jmxremote.authenticate=false \
           -Dcom.sun.management.jmxremote.ssl=false"

    # configure application apps
    JARGS="$JARGS -c /etc/$PROJ_NAME/$PROJ_NAME.conf"
    JARGS="$JARGS -l /etc/$PROJ_NAME/log4j.conf"
    JLOGFILE=$LOGS_DIR/$PROJ_NAME_error.log
    # Override JOPTS with OVERRIDE_JOPTS from commandline while starting this script
    # Override JARGS with OVERRIDE_JARGS from commandline while starting this script
    set -x
echo "============ restart process !!!! ============" >> /opt/$PROJ_NAME/log/$PROJ_NAME.log
echo java $JOPTS $OVERRIDE_JOPTS -jar $JARFILE $JARGS $OVERRIDE_JARGS >> /opt/$PROJ_NAME/log/service.log
    exec java $JOPTS $OVERRIDE_JOPTS -jar $JARFILE $JARGS $OVERRIDE_JARGS > /opt/$PROJ_NAME/log/$PROJ_NAME.log  2>&1
    set +x
end script

post-start script
    PID=`ps -ef | grep $PROJ_NAME.jar | egrep -v 'grep|nohup' | awk '{print $2}'`
    echo $PID > /opt/run/$PROJ_NAME.pid
end script

pre-start script
if [ -f /opt/run/$PROJ_NAME.pid] ; then
        rm /opt/run/$PROJ_NAME.pid
    fi
    # Date format same as (new Date()).toISOString() for consistency
    echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >> /opt/$PROJ_NAME/log/$PROJ_NAME.log
end script

pre-stop script
    if [ -f /opt/run/$PROJ_NAME.pid] ; then
        rm /opt/run/$PROJ_NAME.pid
    fi
    echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> /opt/$PROJ_NAME/log/$PROJ_NAME.log
end script




Comments

Popular posts from this blog

Amazon RDS Blue/Green Deployments

In order to avoid some errors I experienced when proceeding as described in the official documentation, I describe what I did in order. 1) Modify parameters of source_database * error: Blue Green Deployments requires cluster parameter group has binlog enabled. RDS Parameter groups: source-params-group binlog_format => MIXED mysql> show global variables like 'binlog_format'; 2) Insert a row after rebooting the source database, to avoid this error. * error: Correct the replication errors and then switch over. Read Replica Replication Error - IOError: 1236, reason: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file' => To Fix: You need to change the data in the source database. INSERT INTO dummy_table ( `favorite_id` , `favorite_order` , `user_id` , `board_id` ) VALUES ('100001', '1', '11111', '11111'); 3) Modify the param...

Fluentd for mysql in AWS

(0) preparation ulimit -n If your console shows 1024, it is insufficient. Please add following lines to your /etc/security/limits.conf file and reboot your machine. root soft nofile 65536 root hard nofile 65536 (1) install Fluentd // “Ubuntu 12.04 LTS / Precise” curl -L http://toolbelt.treasuredata.com/sh/install-ubuntu-precise.sh | sh /etc/init.d/td-agent start/stop/restart/status // test curl -X POST -d 'json={"json":"message"}' http://localhost:8888/debug.test /etc/init.d/td-agent stop chown: changing ownership of `/var/run/td-agent/td-agent.pid': Operation not permitted chown: changing ownership of `/var/run/td-agent': Operation not permitted  * Stopping td-agent td-agent                                                                                   ...

Install CoreOs on linode without VM

Install CoreOs on linode without VM 1. Add a Linode 2. Create a new Disk   CoreOS 3. Rescue > Reboot into Rescue Mode 4. Remote Access   Launch Lish Console 5. make an install script cat <<'EOF1' > install.sh # add needed package sudo apt-get update sudo apt-get install -y curl wget whois sudo apt-get install -y ca-certificates #sudo apt-get install gawk -y # get discovery url discoveryUrl=`curl https://discovery.etcd.io/new` # write cloud-config.yml cat <<EOF2 > cloud-config.yml #cloud-config users:   - name: core     groups:       - sudo       - docker coreos:   etcd:     name: node01     discovery: $discoveryUrl hostname: node01 EOF2 # get the coreos installation script #wget https://raw.github.com/coreos/init/master/bin/coreos-install wget https://raw.githubusercontent.com/coreos/init/master/bin/coreos-install # run installation chmod 75...