以前,どこかのホームページに書かれていたものを参考させてもらったのをメモに.
#!/bin/bash ### BEGIN INIT INFO # Provides:tomcat7 # 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 TOMCAT="/opt/apache-tomcat-7" CATALINA_HOME="/opt/tomcat7" TOMCAT_USER="user_name" 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