Starting Tomcat as a Service on Linux
来源:互联网 发布:推销产品 下载什么软件 编辑:程序博客网 时间:2024/05/21 17:34
Source: http://www.spaceprogram.com/knowledge/2004/01/starting-tomcat-as-service-on-linux.html
Introduction
This document will teach you how to setup Tomcat to run as a service (startup when booted) on Linux.Intended Audience
System admins.Instructions
This is actually pretty easy and will be presented step by step.1. Save tomcat start / stop script
Copy and paste the following script into your text editor:# This is the init script for starting up the
# Jakarta Tomcat server
#
# chkconfig: 345 91 10
# description: Starts and stops the Tomcat daemon.
#
# Source function library.
. /etc/rc.d/init.d/functions
# Get config.
. /etc/sysconfig/network
# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0
tomcat=/usr/local/jakarta-tomcat
startup=$tomcat/bin/startup.sh
shutdown=$tomcat/bin/shutdown.sh
export JAVA_HOME=/usr/local/jdk
start(){
echo -n ___FCKpd___0quot;Starting Tomcat service: "
#daemon -c
$startup
RETVAL=$?
echo
}
stop(){
action ___FCKpd___0quot;Stopping Tomcat service: " $shutdown
RETVAL=$?
echo
}
restart(){
stop
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
# This doesn't work ;)
status tomcat
;;
restart)
restart
;;
*)
echo ___FCKpd___0quot;Usage: $0 {start|stop|status|restart}"
exit 1
esac
exit 0
Edit the lines that start with tomcat and export to match where you installed
tomcat and your jdk.
Note: I can't remember where I first got the original version of this script
so if you deserve credit for this, let us know.
2. Save to /etc/init.d and chmod
Save the edited file above to /etc/init.d directory as "tomcat" (at
least on most newer releases since /etc/init.d is a standard now). Then
you have to allow execute access to the script, so run:
chmod a+x tomcat
3. Add to appropriate run level directories
The easy way to do this is to just simply run:chkconfig --add tomcatAnd that's all she wrote.
5 Comments:
- Starting Tomcat as a Service on Linux
- Starting Tomcat as a Service on Linux
- Starting MySQL as a Windows Service
- Run a Java Application as a Service on Linux
- Beginning configuration step: Starting Server Starting MySQL as a service 解决方案
- Starting a Service
- config Tomcat service on ubuntu14 server as daemon thread
- How to install JBoss AS 7 as a Linux service
- function as a service
- Spark(十二) -- Spark On Yarn & Spark as a Service & Spark On Tachyon
- Running Tomcat on Port 80 via a Service Wrapper
- To start or stop dbconsole as a service on Microsoft Windows:
- SaaS: Software as a Service
- keylogger, runs as a Service
- 征服Spark as a Service
- tap as a service 分析
- Apache Spark as a Service
- 09 Container as a Service
- 篮球部落—麦蒂的九种得分招式
- 篮球部落—麦蒂的九种得分招式
- AnonymousClassDemo.java
- asp.net textbox readonly
- 设计模式
- Starting Tomcat as a Service on Linux
- IE与Firefox对CSS解析的区别--及兼容要点分析
- 第三章例子:(Numbercheck.java)
- 打开新的窗体
- Delphi中各个包中包含的控件
- 稀疏文件
- Word中显示/隐藏图片工具栏的另类用法
- 常用算法,插入,选择,冒泡
- getElementById getElementsByName getElementsByTagName 大概介绍
Here's one way to get a status.. add this function:
status(){
numproc=`ps -ef | grep catalina | grep -v "grep catalina" | wc -l`
if [ $numproc -gt 0 ]; then
echo "Tomcat is running..."
else
echo "Tomcat is stopped..."
fi
}
Then call that in your case statement when "status" is used. Hope that helps!
This seems to work a bit better for me I have found (running on RHEL3 WS):
ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' | wc | awk '{print $2}' > /tmp/tomcat_process_count.txt
read line < /tmp/tomcat_process_count.txt
if [ $line -gt 0 ]; then
echo -n "tomcatd ( pid "
ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
echo -n ") is running..."
echo
else
echo "Tomcat is stopped"
fi
Hello,
The problem with this is that Tomcat is then running as root, isn't it?
How shall we make it run as another user?
Thanks,
Timok
To change it so tomcat runs as another user, change the $startup line to:
su - $user -c "$startup"
and $shutdown line to:
action $"Stopping Tomcat service: " su - $user "$shutdown"
And of course, define user up at the top where the paths are defined. Voila.
tomcat5 sets default service in /etc/rc.d/init.d directory, however it does not start automatically. running the chkconfig line starts the service automatically.
Thanks for your help!
Kris