5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

playアプリの起動スクリプトサンプル

Last updated at Posted at 2015-11-29

/etc/init.d/functions の関数を使った形で、playアプリのrc起動スクリプトのひながたを作成。

start,stop,statusがあれば十分という方針。

検証して、もう少し整理していく。

play-app
#!/bin/sh
# chkconfig:345 99 1
# description: play-app 
# processname: $APP

IP_ADDRESS=`ip -f inet -o addr show eth0|cut -d\  -f 7 | cut -d/ -f 1`

APP=app
APP_USER=appuser
APP_HOME=/home/${APP_USER}/${APP}

CONF="-Dconfig.file=conf/application.conf -Dlogger.file=conf/logger.xml"

MEM="-J-Xms1024M -J-Xmx1024M -XX:MaxPermSize=256m -XX:PermSize=256m"

GC="-J-Xloggc:/var/log/${APP}/gc_%p_%t.log 
-J-XX:+UseGCLogFileRotation -J-XX:NumberOfGCLogFiles=10 -J-XX:GCLogFileSize=100k 
-J-XX:+PrintGCDetails 
-J-XX:+PrintGCTimeStamps"

HEAPDUMP="-J-XX:+HeapDumpOnOutOfMemoryError"

JMX="-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false 
-Dcom.sun.management.jmxremote.port=1111
-Djava.rmi.server.hostname=${IP_ADDRESS}"

HEAPSTATS="-J-agentlib:heapstats"


JAVA_OPTIONS="$CONF $MEM $GC $HEAPDUMP $JMX $HEAPSTATS"

# Source function library.
. /etc/rc.d/init.d/functions

prog=$(basename $APP)
lockfile=${LOCKFILE-/var/lock/subsys/${APP_NAME}}
pidfile=${APP_HOME}/RUNNING_PID
RETVAL=0

start(){
    echo  "starting ${prog}:"
    su - $APP_USER -c "cd $Dir; ./bin/${APP} $JAVA_OPTIONS &"
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && touch ${lockfile}
    return $RETVAL
}

stop(){
    killproc -p ${pidfile} ${prog} -QUIT
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}

status(){
    status -p ${pidfile} ${prog}
    RETVAL=$?
}

case "$1" in
  start)
    start
      ;;
  stop)
    stop
     ;;
  status)
     status
     ;;
  restart)
    stop
    start
     ;;
     *)
      echo $"Usage: $0 {start|stop|status|restart}"
      exit 2
esac

参考サイト

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?