`
zhoupinheng
  • 浏览: 33993 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

utuntu上设置Tomcat开机自动启动

 
阅读更多
一。环境:
操作系统: utuntu11.10
JAVA_HOME: /document/opt/jdk1.6
Tomcat安装目录: /documet/opt/tomcat6
二。编写服务启动脚本
在/etc/init.d/下创建文件tomcatd :
#! /bin/sh
# chkconfig: 35 30 70
# descripttion: VirtualBox Linux kernel module
#
### BEGIN INIT INFO
# Provides: tomcat
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Descripttion: tomcat
### END INIT INFO
export JAVA_HOME=/document/opt/jdk1.6
export CATALINA_HOME=/document/opt/tomcat-6
export CATALINA_PID=/var/run/tomcatd.pid
PIDFILE=/var/run/tomcatd.pid
pidof_tomcat() {
# if there is actually an apache2 process whose pid is in PIDFILE,
# print it and return 0.
if [ -e "$PIDFILE" ]; then
if pidof java | tr ' ' '\n' | grep -w $(cat $PIDFILE); then
return 0
fi
fi
return 1
}
start() {
PID=$(pidof_tomcat) || true
if [ -n "$PID" ]; then
echo "tomcat is running (pid $PID)."
exit 0
else
sh $CATALINA_HOME/bin/startup.sh
fi
}
stop() {
PID=$(pidof_tomcat) || true
if [ -n "$PID" ]; then
sh $CATALINA_HOME/bin/shutdown.sh
PID=$(pidof_tomcat) || true
if [ -n "$PID" ]; then
echo "tomcat is still running (pid $PID)."
echo "kill process..."
kill -9 $PID
fi
else
echo "tomcat is NOT running."
fi
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
PID=$(pidof_tomcat) || true
if [ -n "$PID" ]; then
echo "tomcat is running (pid $PID)."
exit 0
else
echo "tomcat is NOT running."
if [ -e "$PIDFILE" ]; then
exit 1
else
exit 3
fi
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
三。添加服务:
[root@root init.d]# chmod uog+rx tomcatd
[root@root init.d]# sysv-rc-conf --level 2345 tomcatd on
四。注意:
1. 在tomcat文件的头两行的注释语句中,需要包含chkconfig和descriptttion两部分内容(确认不要拼写错误),否则在执行“chkconfig --add  tomcatd”时,会出现“tomcatd 服务不支持 chkconfig”的错误提示。
2. 如果提示sysv-rc-conf 命令不存在就执行 apt-get install sysv-rc-conf 安装。
3. 如果tomcat用户不存在通过如下命令则建立:#useradd -U -s /sbin/nologin tomcat
查看服务添加结果:
[root@root init.d]# sysv-rc-conf --list tomcatd

tomcatd 2:on 3:on 4:on 5:on
[root@root init.d]# /etc/init.d/tomcatd start
删除服务:
[root@root init.d]# sysv-rc-conf tomcatd off
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics