Linux でやりたかったんだけど、手元に Solaris10 しかなかったので、Solaris10で。
インストール・設定手順
- インストールする。
# wget http://ftp.riken.jp/net/apache/tomcat/tomcat-6/v6.0.24/bin/apache-tomcat-6.0.24.tar.gz # gunzip -c apache-tomcat-6.0.24.tar.gz|tar xvf # mv apache-tomcat-6.0.24 /opt/tomcat6 # useradd -d /opt/tomcat6 -s /usr/bin/false tomcat # chown -R tomcat:tomcat /opt/tomcat6
- 自動起動するよう設定する。
# cp -p /opt/tomcat6/bin/jsvc.tar.gz /tmp/ # cd /tmp # gunzip -c jsvc.tar.gz|tar xvf - # cd jsvc-src # export PATH=.:$PATH:/usr/sfw/bin:/usr/ccs/bin # chmod +x configure # ./configure --with-java=/usr/java # gmake # chown tomcat:tomcat jsvc # mv jsvc /opt/tomcat6/bin/ # cp -p /temp/jsvc-src/native/Tomcat5.sh /etc/init.d/jsvc # cd /; rm -rf /tmp/jsvc-src /tmp/jsvc.tar.gz # vi /etc/init.d/jsvc JAVA_HOME=/usr/java CATALINA_HOME=/opt/tomcat6 DAEMON_HOME=/opt/tomcat6/bin TOMCAT_USER=tomcat ... ATALINA_BASE=/opt/tomcat6 ... CATALINA_OPTS= ... # Start Tomcat # $DAEMON_HOME/jsvc \ ... # Stop Tomcat # $DAEMON_HOME/jsvc \ ... echo "Usage: jsvc start/stop" # chmod +x /etc/init.d/jsvc # ln -s /etc/init.d/jsvc /etc/rc3.d/S50jsvc # ln -s /etc/init.d/jsvc /etc/rc0.d/K50jsvc
確認手順
- OS を再起動する。
# init 6
- Tomcat のプロセスが起動していることを確認する。
$ ps -ef|egrep "[t]omcat" root 669 1 0 06:19:47 ? 0:00 /opt/tomcat6/bin/jsvc -user tomcat -home /usr/java -Dcatalina.home=/opt/tomcat6 tomcat 670 669 0 06:19:47 ? 0:04 /opt/tomcat6/bin/jsvc -user tomcat -home /usr/java -Dcatalina.home=/opt/tomcat6
- ブラウザからアクセスしてみる。
自動起動・停止スクリプト
- /etc/init.d/jsvc
#!/bin/sh ############################################################################## # # Copyright 2004 The Apache Software Foundation. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ############################################################################## # # Small shell script to show how to start/stop Tomcat using jsvc # If you want to have Tomcat running on port 80 please modify the server.xml # file: # # <!-- Define a non-SSL HTTP/1.1 Connector on port 80 --> # <Connector className="org.apache.catalina.connector.http.HttpConnector" # port="80" minProcessors="5" maxProcessors="75" # enableLookups="true" redirectPort="8443" # acceptCount="10" debug="0" connectionTimeout="60000"/> # # That is for Tomcat-5.0.x (Apache Tomcat/5.0) # # Adapt the following lines to your configuration JAVA_HOME=/usr/java CATALINA_HOME=/opt/tomcat6 DAEMON_HOME=/opt/tomcat6/bin TOMCAT_USER=tomcat # for multi instances adapt those lines. TMP_DIR=/var/tmp PID_FILE=/var/run/jsvc.pid CATALINA_BASE=/opt/tomcat6 CATALINA_OPTS= CLASSPATH=\ $JAVA_HOME/lib/tools.jar:\ $CATALINA_HOME/bin/commons-daemon.jar:\ $CATALINA_HOME/bin/bootstrap.jar case "$1" in start) # # Start Tomcat # $DAEMON_HOME/jsvc \ -user $TOMCAT_USER \ -home $JAVA_HOME \ -Dcatalina.home=$CATALINA_HOME \ -Dcatalina.base=$CATALINA_BASE \ -Djava.io.tmpdir=$TMP_DIR \ -wait 10 \ -pidfile $PID_FILE \ -outfile $CATALINA_HOME/logs/catalina.out \ -errfile '&1' \ $CATALINA_OPTS \ -cp $CLASSPATH \ org.apache.catalina.startup.Bootstrap # # To get a verbose JVM #-verbose \ # To get a debug of jsvc. #-debug \ exit $? ;; stop) # # Stop Tomcat # $DAEMON_HOME/jsvc \ -stop \ -pidfile $PID_FILE \ org.apache.catalina.startup.Bootstrap exit $? ;; *) echo "Usage: jsvc start/stop" exit 1;; esac
参考
- “安全”のためにTomcatを理解し、構築し、動作させる (1/3):Tomcatはどこまで“安全”にできるのか?(1) - @IT
- http://codeanimato.com/blog/2008/01/solaris10tomcat.html
- Apache Tomcat 6.0 (6.0.53) - Tomcat Setup
追記(2010/02/02):
umask を設定したい場合は、起動スクリプト内に以下のように「umask 027」などと普通に記述すればよさげ。
Here's an (edited) extract from my version.
# Set umask to avoid tomcat making tomcat-users.xml public readable umask 027 # == 640 PID_FILE=/var/run/jsvc.pid ..... /usr/lib/tcnative/jsvc \ -user $TOMCAT_USER \ -home $JAVA_HOME \ -Dcatalina.home=$CATALINA_HOME \ -Dcatalina.base=$CATALINA_BASE \ -Djava.io.tmpdir=$TMP_DIR \ -Xmx512m \ -XX:MaxPermSize=128m \ -wait 10 \ -pidfile $PID_FILE \ -outfile $CATALINA_HOME/logs/catalina.out \ -errfile '&1' \ $CATALINA_OPTS \ -cp $CLASSPATH \ org.apache.catalina.startup.Bootstraphttp://old.nabble.com/jsvc-creates-pid-file-owned-by-root-td16606528.html
追記(2010/02/24):
起動スクリプトのサンプル。以下は Linux で使ってるやつ。
#!/bin/sh # # chkconfig: 2345 80 25 # description: Starts and stops the Apache Tomcat JAVA_HOME="/usr/java/default" CATALINA_HOME="/usr/local/tomcat" DAEMON_HOME="/usr/local/tomcat/bin" TOMCAT_USER=tomcat # for multi instances adapt those lines. TMP_DIR="/var/tmp" PID_FILE="/var/run/jsvc.pid" CATALINA_BASE="/usr/local/tomcat" CATALINA_OPTS="-Xms128m -Xmx3072m -XX:PermSize=128m -XX:MaxPermSize=1050m" CLASSPATH="$JAVA_HOME/lib/tools.jar:$CATALINA_HOME/bin/commons-daemon.jar:$CATALINA_HOME/bin/bootstrap.jar" RETVAL=0 umask 002 start() { $DAEMON_HOME/jsvc \ -user $TOMCAT_USER \ -home $JAVA_HOME \ -Dcatalina.home=$CATALINA_HOME \ -Dcatalina.base=$CATALINA_BASE \ -Djava.io.tmpdir=$TMP_DIR \ -wait 10 \ -pidfile $PID_FILE \ -outfile $CATALINA_HOME/logs/catalina.out \ -errfile '&1' \ $CATALINA_OPTS \ -cp $CLASSPATH \ org.apache.catalina.startup.Bootstrap # # To get a verbose JVM #-verbose \ # To get a debug of jsvc. #-debug \ exit $? } stop() { $DAEMON_HOME/jsvc \ -stop \ -pidfile $PID_FILE \ org.apache.catalina.startup.Bootstrap exit $? } case "$1" in start) start ;; stop) stop ;; *) echo "Usage: jsvc start/stop" exit 1;; esac