浏览 8871 次
锁定老帖子 主题:tomcat自启动脚本
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-03-31
2、 在/etc/rc.d/rc3.d目录下,执行 ln –s /etc/init.d/tomcat /etc/rc.d/rc3.d/S99tomcat 这样,开机就会自动启动Tomcat了。 3.如果不能运行,请检查 chmod 755 /etc/init.d/tomcat chmod 755 apache-tomcat-5.5.25/ vi /etc/passwd 修改启动用户如 apache 的/sbin/nologin 为/bin/bash 4、 脚本 #!/bin/sh # # Start staff.macaufly.net webserver # Currently installed under /home/jira and should moved to /home/tomcat later # TOMCAT_BIN=/home/tomcat6/bin TOMCAT_USER=apache start() { stop su - $TOMCAT_USER -c $TOMCAT_BIN/startup.sh sleep 10 if netstat -an | grep 8080 >/dev/null then echo "Tomcat is running" return 0 else return 1 fi } stop() { if netstat -an | grep 8080 | grep LISTEN >/dev/null then # try to shutdown the server first echo "Now Shutdown the server..." su - $TOMCAT_USER -c $TOMCAT_BIN/shutdown.sh else echo "Tomcat is not running" return 0 fi if netstat -an | grep 8080 | grep LISTEN then sleep 10 echo "Now kill it" ps -ef | grep java | grep $TOMCAT_USER | awk '{print "kill -9 ", $2;}' | sh fi if netstat -an | grep 8080 | grep LISTEN >/dev/null then return 1 # still alive else echo "Tomcat is stopped" return 0 fi } case "$1" in start) start ;; stop) stop ;; restart) start ;; status) if netstat -an |grep 8080|grep LISTEN >/dev/null then echo "Tomcat is Running" else echo "Tomcat is Not Running" fi ;; *) echo $"Usage: $0 {start|stop|restart|status}" exit 1 esac exit 0 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2008-08-18
新的一段脚本
#!/bin/bash # # Startup script for the tomcat # # chkconfig: 345 95 15 # description: tomcat service script # # Source function library. . /etc/rc.d/init.d/functions TOMCAT_HOME=/home/tomcat RETVAL=0 checkjava(){ if [ -z "$JAVA_HOME" ]; then export JAVA_HOME=/home/jdk1.6.0_07 fi } start(){ checkjava checkrun if [ $RETVAL -eq 0 ]; then echo "Starting tomcat" su - tomcat -c "$TOMCAT_HOME/bin/startup.sh" touch /var/lock/subsys/tomcat else echo "tomcat allready running" fi } stop(){ checkjava checkrun if [ $RETVAL -eq 1 ]; then echo "Shutting down tomcat" su - tomcat -c "$TOMCAT_HOME/bin/shutdown.sh" #while [ $RETVAL -eq 1 ]; do # sleep 5 # checkrun #done rm -f /var/lock/subsys/tomcat else echo "tomcat not running" fi checkrun } checkrun(){ 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 RETVAL=1 return $RETVAL else RETVAL=0 return $RETVAL fi } status(){ checkrun if [ $RETVAL -eq 1 ]; then echo -n "Tomcat ( pid " ps ax --width=1000 | grep "org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' echo -n ") is running..." echo else echo "Tomcat is stopped" fi echo "---------------------------------------------" } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; status) status # su - tomcat -c "$TOMCAT_HOME/bin/catalina.sh version" ;; *) echo "Usage: $0 {start|stop|restart|status}" esac exit 0 |
|
返回顶楼 | |