tomcat7 linux service

來源:互聯網
上載者:User

標籤:

1. 建立tomcat使用者

useradd -r -m -d /usr/local/tomcat7 -s /sbin/nologin tomcat

 

2. 將下面指令碼命名為tomcat7 放入/etc/init.d/檔案夾下即可

#!/bin/bash## tomcat7     This shell script takes care of starting and stopping Tomcat## chkconfig: - 80 20#### BEGIN INIT INFO# Provides: tomcat7# Required-Start: $network $syslog# Required-Stop: $network $syslog# Default-Start:# Default-Stop:# Description: Release implementation for Servlet 2.5 and JSP 2.1# Short-Description: start and stop tomcat### END INIT INFO #useradd -r -m -d ${TOMCAT_HOME} -s /sbin/nologin tomcat#useradd -r -m -d /usr/local/tomcat7 -s /sbin/nologin tomcat## Source function library.#. /etc/rc.d/init.d/functionsexport JAVA_OPTS="-Dfile.encoding=UTF-8 \  -Dcatalina.logbase=/var/log/tomcat7   -Dnet.sf.ehcache.skipUpdateCheck=true   -Djava.nio.channels.spi.SelectorProvider=sun.nio.ch.EPollSelectorProvider   -XX:+DoEscapeAnalysis   -XX:+UseConcMarkSweepGC   -XX:+CMSClassUnloadingEnabled   -XX:+UseParNewGC   -XX:MaxPermSize=256m   -XX:PermSize=256m   -XX:MaxNewSize=512m   -Xms4096m -Xmx4096m"TOMCAT_HOME=/usr/local/tomcat7SHUTDOWN_WAIT=5export JAVA_HOME=‘/usr/java/jdk1.7.0_67‘export PATH=$JAVA_HOME/bin:$PATH tomcat_pid() {  echo `ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk ‘{ print $2 }‘`} start() {  pid=$(tomcat_pid)  if [ -n "$pid" ]   then    echo "Tomcat is already running (pid: $pid)"  else    # Start tomcat    echo "Starting tomcat"    ulimit -n 100000    umask 007    /bin/su -p -s /bin/sh tomcat $TOMCAT_HOME/bin/startup.sh  fi    return 0} stop() {  pid=$(tomcat_pid)  if [ -n "$pid" ]  then    echo "Stoping Tomcat"    /bin/su -p -s /bin/sh tomcat $TOMCAT_HOME/bin/shutdown.sh     let kwait=$SHUTDOWN_WAIT    count=0;    until [ `ps -p $pid | grep -c $pid` = ‘0‘ ] || [ $count -gt $kwait ]    do      echo -n -e "\nwaiting for processes to exit";      sleep 1      let count=$count+1;    done     if [ $count -gt $kwait ]; then      echo -n -e "\nkilling processes which didn‘t stop after $SHUTDOWN_WAIT seconds"      kill -9 $pid    fi  else    echo "Tomcat is not running"  fi   return 0}log(){     /bin/su -p -s /bin/sh tomcat -c "/usr/bin/tail -f $TOMCAT_HOME/logs/catalina.out"} case $1 inlog)  log;;start)  start;; stop)     stop;; restart)  stop  start;;status)  pid=$(tomcat_pid)  if [ -n "$pid" ]  then    echo "Tomcat is running with pid: $pid"  else    echo "Tomcat is not running"  fi;; esac    exit 0

 

tomcat7 linux service

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.