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

DevOps JD's required skills from LinkedIn

From some of DevOps JD on linkedIn, I realised that DeveOps should be the leader of the organization. https://docs.google.com/spreadsheets/d/1P520nH0pYcAdN0rJcnMQqsgu9cV9GdknztJ92J8l7-s/pubhtml DevOps' Required Skills From LinkedIn on 8/30/16: DevOps should be the leader of the company! Yahoo Netflix Samsung Salesforce Fortinet SUM OS admin UNIX systems Unix platforms Linux administrator Linux VMs Docker VMs VMware, OpenStack, Hyper-V Openstack, KVM, VMWare Version control version control systems Git, SVN Cloud Amazon AWS AWS AWS, Azure DB MySql Oracle, MySQL, NoSQL Mysql administration and strong command of SQL MySQL RabbitMQ MySql, MongoDB, Redis, Oracle, ProgreSQL N/W TCP/IP networking, DNS, HTTP NAS Understanding of network stack, network tuning, subnet/VLANs. HAProxy, DNS, IPTable Script Lang Shell, Perl, Python, Ruby, PHP bash Python, Bash/tcsh a scripting language: Perl, Python and Unix Shell preferred Python, Perl, Ruby Python, Ruby, Shell, PHP Web LAMP stack

Ubuntu GUI with VNC on Xenserver

Xenserver 에서 Ubuntu GUI 를 쓰기 위해서는 VNC 가 답인 듯... Installing Ubuntu Gnome GUI on Ubuntu Server 12.10 with VNC Update Repositories # apt-get update Install gnome and vnc: # apt-get install gnome-core vnc4server Start VNC Server: # vncserver (You’ll then be prompted to create and verify a new VNC connect password) Kill the currently running VNC Session: # vncserver -kill :1 Edit VNC startup config file: # vim .vnc/xstartup Uncomment the following line: unset SESSION_MANAGER Add the following line: gnome-session --session=gnome-classic & Comment Out the following two lines: x-terminal-emulator -geometry 1280x1024+10+10 -ls -title "$VNCDESKTOP Desktop" & x-window-manager & End result should look like: #!/bin/sh # Uncomment the following two lines for normal desktop: unset SESSION_MANAGER # exec /etc/X11/xinit/xinitrc gnome-session --session=gnome-classic & [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup [ -r $HOME/

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 755 coreos-install sudo ./coreos-install \       -d /dev/sda \       -