微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!
快速启动专题提供快速启动的最新资讯内容,帮你更好的了解快速启动。
写一个shell 快速启动停止你的微服务吧
在这个微服务盛行的时代,docker获得了巨大的成功,因为我们需要在一台服务器装上N个服务。本文不是想讨论如何使用docker,而是,在一台服务器安装了多个服务后,怎样启动方便的启动服务呢?一、在tomcat的时代中,直接使用tomcat的启动停止命令,轻松搞定,(tomcat的启动脚本很有水平,感兴趣的点开'+'号查看源码学习下吧)#!/bin/sh# chkconfig: 2345 10 90# description:tomcat serviceJAVA_OPTS="$JAVA_OPTS -server -XX:PermSize=128M -XX:MaxPermSize=512m"CATALINA_PID=/opt/tomcat7/pid.logCATALINA_HOME=/opt/tomcat7# OS specific support. $var _must_ be set to either true or false.cygwin=falsedarwin=falseos400=falsecase "`uname`" inCYGWIN*) cygwin=true;;Darwin*) darwin=true;;OS400*) os400=true;;esac# resolve links - $0 may be a softlinkPRG="$0"while [ -h "$PRG" ]; dols=`ls -ld "$PRG"`link=`expr "$ls" : '.*-> (.*)$'`if expr "$link" : '/.*' > /dev/null; thenPRG="$link"elsePRG=`dirname "$PRG"`/"$link"fidone# Get standard environment variablesPRGDIR=`dirname "$PRG"`# Only set CATALINA_HOME if not already set[ -z "$CATALINA_HOME" ] && CATALINA_HOME=`cd "$PRGDIR/.." >/dev/null; pwd`# Copy CATALINA_BASE from CATALINA_HOME if not already set[ -z "$CATALINA_BASE" ] && CATALINA_BASE="$CATALINA_HOME"# Ensure that any user defined CLASSPATH variables are not used on startup,# but allow them to be specified in setenv.sh, in rare case when it is needed.CLASSPATH=if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then. "$CATALINA_BASE/bin/setenv.sh"elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then. "$CATALINA_HOME/bin/setenv.sh"fi# For Cygwin, ensure paths are in UNIX format before anything is touchedif $cygwin; then[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`[ -n "$JRE_HOME" ] && JRE_HOME=`cygpath --unix "$JRE_HOME"`[ -n "$CATALINA_HOME" ] && CATALINA_HOME=`cygpath --unix "$CATALINA_HOME"`[ -n "$CATALINA_BASE" ] && CATALINA_BASE=`cygpath --unix "$CATALINA_BASE"`[ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"`fi# For OS400if $os400; then# Set job priority to standard for interactive (interactive - 6) by using# the interactive priority - 6, the helper threads that respond to requests# will be running at the same priority as interactive jobs.COMMAND='chgjob job('$JOBNAME') runpty(6)'system $COMMAND# Enable multi threadingexport QIBM_MULTI_THREADED=Yfi# Get standard Java environment variablesif $os400; then# -r will Only work on the os400 if the files are:# 1. owned by the user# 2. owned by the PRIMARY group of the user# this will not work if the user belongs in secondary groups. "$CATALINA_HOME"/bin/setclasspath.shelseif [ -r "$CATALINA_HOME"/bin/setclasspath.sh ]; then. "$CATALINA_HOME"/bin/setclasspath.shelseecho "Cannot find $CATALINA_HOME/bin/setclasspath.sh"echo "This file is needed to run this program"exit 1fifi# Add on extra jar files to CLASSPATHif [ ! -z "$CLASSPATH" ] ; thenCLASSPATH="$CLASSPATH":fiCLASSPATH="$CLASSPATH""$CATALINA_HOME"/bin/bootstrap.jarif [ -z "$CATALINA_OUT" ] ; thenCATALINA_OUT="$CATALINA_BASE"/logs/catalina.outfiif [ -z "$CATALINA_TMPDIR" ] ; then# Define the java.io.tmpdir to use for CatalinaCATALINA_TMPDIR="$CATALINA_BASE"/tempfi# Add tomcat-juli.jar to classpath# tomcat-juli.jar can be over-ridden per instanceif [ -r "$CATALINA_BASE/bin/tomcat-juli.jar" ] ; thenCLASSPATH=$CLASSPATH:$CATALINA_BASE/bin/tomcat-juli.jarelseCLASSPATH=$CLASSPATH:$CATALINA_HOME/bin/tomcat-juli.jarfi# Bugzilla 37848: When no TTY is available, don't output to consolehave_tty=0if [ "`tty`" != "not a tty" ]; thenhave_tty=1fi# For Cygwin, switch paths to Windows format before running javaif $cygwin; thenJAVA_HOME=`cygpath --absolute --windows "$JAVA_HOME"`JRE_HOME=`cygpath --absolute --windows "$JRE_HOME"`CATALINA_HOME=`cygpath --absolute --windows "$CATALINA_HOME"`CATALINA_BASE=`cygpath --absolute --windows "$CATALINA_BASE"`CATALINA_TMPDIR=`cygpath --absolute --windows "$CATALINA_TMPDIR"`CLASSPATH=`cygpath --path --windows "$CLASSPATH"`JAVA_ENDORSED_DIRS=`cygpath --path --windows "$JAVA_ENDORSED_DIRS"`fi# Set juli LogManager config file if it is present and an override has not been issuedif [ -z "$LOGGING_CONFIG" ]; thenif [ -r "$CATALINA_BASE"/conf/logging.properties ]; thenLOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"else# Bugzilla 45585LOGGING_CONFIG="-Dnop"fifiif [ -z "$LOGGING_MANAGER" ]; thenLOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"fi# Uncomment the following line to make the umask available when using the# org.apache.catalina.security.SecurityListener#JAVA_OPTS="$JAVA_OPTS -Dorg.apache.catalina.security.SecurityListener.UMASK=`umask`"# ----- Execute The Requested Command ---------------------------------------