Raspberry Pi Tomcat

Raspbian (Debian Wheezy) on Raspberry Pi で Tomcat 8

投稿日:2014-06-12 更新日:

Raspbian (Debian Wheezy) on Raspberry Pi に Tomcat 8.0.8 をインストールし,OS 起動時に Tomcat を自動起動させてみます.

Raspbian は,2014-01-07-wheezy-raspbian.zip です.

# ++++++++++++++++++++++++++++++
# Tomcat のインストール
# ++++++++++++++++++++++++++++++

# Apache Tomcat
# http://tomcat.apache.org/
cd ~/Downloads
wget http://ftp.jaist.ac.jp/pub/apache/tomcat/tomcat-8/v8.0.8/bin/apache-tomcat-8.0.8.tar.gz
tar zxvf apache-tomcat-8.0.8.tar.gz
# /usr/local, /opt 等お好みのパスへ.
sudo mv apache-tomcat-8.0.8 /usr/local/
sudo ln -s /usr/local/apache-tomcat-8.0.8 /usr/local/tomcat8
# /usr/local/tomcat8/bin/startup.sh を実行後,tcp:8080 で Tomcat にアクセスできることを確認します.

# ++++++++++++++++++++++++++++++
# Tomcat の自動起動
# ++++++++++++++++++++++++++++++
sudo vi /etc/init.d/tomcat8
# tomcat8 の内容については後述.
sudo chmod 755 /etc/init.d/tomcat8
sudo insserv tomcat8
# この後,念のため OS を reboot して,Tomcat が自動起動することを確かめましょう.
# insserv については,http://server-setting.info/debian/debian-like-chkconfig.html

また,nginx と Tomcat との連携についてはいくつかのサイトで紹介されています.

tomcat8 ファイル (Tomcat 8 の起動スクリプト) のサンプル (以前どこかのサイトで紹介されていたものをそのまま使用しています)

#!/bin/bash
### BEGIN INIT INFO
# Provides:tomcat8
# Required-Start:
# Required-Stop:
# Default-Start:2 3 4 5
# Default-Stop:0 1 6
# Short-Description:
# Description:
### END INIT INFO
#
# tomcat
#
# chkconfig:
# description:  Start up the Tomcat servlet engine.
 
# Source function library.
# /etc/init.d/functions
 
CATALINA_HOME="/usr/local/tomcat8"
TOMCAT_USER="ここには Tomcat を動かすユーザー名を記入しておきます."
SHUTDOWN_WAIT=10
 
tomcat_pid() {
  echo `ps aux | grep $TOMCAT | grep -v grep | awk '{ print $2 }'`
}
 
start() {
  pid=$(tomcat_pid)
  if [ -n "$pid" ]
     then
        echo "Tomcat is already running (pid: $pid)"
     else
        echo "Starting Tomcat"
        /bin/su $TOMCAT_USER $CATALINA_HOME/bin/startup.sh
   fi
 
   return 0
}
 
stop() {
 pid=$(tomcat_pid)
  if [ -n "$pid" ]
  then
 
  echo "Stoping Tomcat"
   /bin/su $TOMCAT_USER $CATALINA_HOME/bin/shutdown.sh
 
   echo -n "Waiting for processes to exit ["
   let kwait=$SHUTDOWN_WAIT
    count=0;
    until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
    do
      echo -n ".";
      sleep 1
      let count=$count+1;
    done
    echo "Done]"
 
    if [ $count -gt $kwait ]
    then
      echo "Killing processes ($pid) which didn't stop after $SHUTDOWN_WAIT seconds"
      kill -9 $pid
    fi
  else
    echo "Tomcat is not running"
  fi
 
  return 0
}
 
status() {
  pid=$(tomcat_pid)
  if [ -n "$pid" ]
  then
    echo "Tomcat is running with pid: $pid"
  else
    echo "Tomcat is not running"
  fi
}
 
case "$1" in
 start)
        start
        ;;
 stop)
        stop
        ;;
 restart)
       stop
       start
       ;;
 status)
       status
       ;;
*)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1
        ;;
esac
exit 0

-Raspberry Pi, Tomcat

Copyright© hirooka.pro , 2013-2018 All Rights Reserved.