`

centos6 tomcat 启动脚本 tomcat服务

 
阅读更多
系统自动启动tomcat
复制该脚本到/etc/init.d/目录,修改对应的tomcat参数
然后执行 chkconfig --add tomcat-biz 添加到系统服务

执行 service tomcat-biz start 启动tomcat


#!/bin/bash
#/etc/init.d/tomcat-biz
#chkconfig: 2345 91 99
# description: Starts and stops the tomcat-biz daemon.

. /etc/init.d/functions

prog_name="tomcat-biz"
tomcat_home="/opt/tomcat-biz"
export JAVA_HOME=/opt/jdk1.7.0_72
export JAVA_OPTS="-Xms256m -Xmx1024m -XX:MaxNewSize=256m -XX:PermSize=256m -XX:MaxPermSize=256m"

prog_user="root"
pidfile="/var/run/${prog_name}.pid"
lockfile="/var/lock/subsys/${prog_name}"

find_pid(){
   if [ ! -z "$1" ]; then
    pid=$(/bin/ps aux | grep $1/ | grep -v grep | awk '{print $2}')
    echo "$pid"
   else
    echo  ""
   fi
}

start(){
  echo $"Starting ${prog_name}: "
  if [ -f "$lockfile" ];then
     failure
     echo "$prog_name already running,can not start new one !"
     echo "${prog_name} pid is "
     cat ${pidfile}
     echo "if kill process manually must remove lockfile and pidfile"
     echo "lockfile ${lockfile}"
     echo "pidfile ${pidfile}"
    return 1
  fi

  if [ ! -x ${tomcat_home}/bin/startup.sh ]; then
        failure
	echo "${tomcat_home}/bin/startup.sh could not execute!"
  fi 
  daemon --user ${prog_user} ${tomcat_home}/bin/startup.sh 
  retval=$?
  prog_pid=$(find_pid $tomcat_home)
  if [ -z "$prog_pid" ]; then
    warning
    echo "Can't find pid!"
    echo "Can't stop and restart from service command!"
    echo "stop and restart need run shell manually"
  fi
  [ ! -z "${prog_pid}" ] && echo ${prog_pid} > ${pidfile}
  echo
  [ $retval -eq 0 ] && touch ${lockfile}
  success
  echo "$prog_name pid $prog_pid"
  return $retval
}

stop(){
  echo -n $"Stopping ${prog_name}: "
  killproc -p ${pidfile} ${prog_name}
  retval=$?
  echo
  [ $retval -eq 0 ] && rm -f ${lockfile}
  return $retval
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    stop
    sleep 1
    start
    ;;
  status)
    status -p ${pidfile} ${prog_name}
    ;;
  *)
    echo $"Usage: $0 {start|stop|restart|status}"
    exit 2
esac
exit $?



0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics