resin-启动脚本httpd.sh分析
分析完tomcat的各启动脚本,发现catalina.sh脚本在停止方面存在问题,而作者在生产环境使用resin却从没有发现,resin在停止时出现服务停不了的现象,那么带大家先分析下resin的启动脚本httpd.sh.
#! /bin/sh # # httpd.sh can be called like apachectl # # httpd.sh -- execs the web server in the foreground # httpd.sh start -- starts the web server in the background # httpd.sh stop -- stops the web server # httpd.sh restart -- restarts the web server # # httpd.sh will return a status code if the wrapper detects an error, but # some errors, like bind exceptions or Java errors, are not detected. # # Customized arguments, e.g. -resin_home or -java_home or -pid. # # -pid <pidfile> -- use a non-default pid file # (useful for multiple servers) # -java_home <java_home> -- use a non-default Java home # -stdout <filename> -- stdout message log # -stderr <filename> -- stderr message log # -native -- force native threads # -green -- force green threads # -verbose -- prints Java arguments before starting. # -no-auto-restart -- disable automatic server restart # -- (this only appled to start and restart) # # This script can be used as a Linux boot script in init.d. You‘ll need to # configure JAVA_HOME and RESIN_HOME directly. # # chkconfig: 345 86 14 # description: Resin is a servlet web server. # processname: wrapper.pl # # To install, you‘ll need to configure JAVA_HOME and RESIN_HOME and # copy httpd.sh to /etc/rc.d/init.d as resin. Then # use "unix# /sbin/chkconfig resin on" # # # You can predefine JAVA_HOME and RESIN_HOME # # JAVA_HOME=/usr/java # export JAVA_HOME # # RESIN_HOME=/usr/local/resin # export RESIN_HOME # # Extra arguments to Java. If you‘re passing arguments to the JVM, you‘ll # need to use -Jxxx. For example, args="-J-ms48m". You can modify # the pid file with args="-pid server-a.pid" # args= # # class to start # class=com.caucho.server.resin.Resin # # name of the server # name=httpd # # location of perl executable # perl=perl # # On Linux, you may want to reduce the stack size per thread to allow # for more threads. The default 8192k stack per thread gives 255 threads. # Changing it to 2048k per thread gives 1023 threads # # ulimit -s 2048 # # trace script and simlinks to find thw wrapper # script=`/bin/ls -l $0 | awk ‘{ print $NF; }‘` #简单的排除文件名为链接文件,如果是多重链接则无法找到真实源路径 #比较健壮的代码可以仿照tomcat的startup.sh #while [ -h "$PRG" ] ; do # ls=`ls -ld "$PRG"` # link=`expr "$ls" : ‘.*-> \(.*\)$‘` # if expr "$link" : ‘/.*‘ > /dev/null; then # PRG="$link" # else # PRG=`dirname "$PRG"`/"$link" # fi # done #################################################################### #这次是使用循环进行剥离链接路径,找到真实源,和上段代码一曲同工 while test -h "$script" #test –h File 文件存在并且是一个符号链接(同-L) do script=`/bin/ls -l $script | awk ‘{ print $NF; }‘` done bin=`dirname $script` exec $perl $bin/wrapper.pl -chdir -name "$name" -class "$class" $args $* #将参数传递给perl脚本执行 #exec perl ./wrapper.pl -chdir -name httpd -class com.caucho.server.resin.Resin #一般后面参数为 -server a start|stop
总结
大家可以看出resin的httpd.sh脚本比较简单,甚至比tomcat的startup.sh和shutdown.sh还简单,这个脚本唯一做了3件事情:
定义一些变量
排除链接找到源路径
将参数全部传递给wrapper.pl这个perl脚本,以后所有的事情就交给它了
本文出自 “运维路上” 博客,请务必保留此出处http://vekergu.blog.51cto.com/9966832/1624046
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。