Answers:
感谢Mark提供的指向该脚本的链接;这是我的CentOS工作示例:
#!/bin/bash
# Source: https://confluence.atlassian.com/plugins/viewsource/viewpagesrc.action?pageId=252348917
function shutdown()
{
date
echo "Shutting down Tomcat"
unset CATALINA_PID # Necessary in some cases
unset LD_LIBRARY_PATH # Necessary in some cases
unset JAVA_OPTS # Necessary in some cases
$TOMCAT_HOME/bin/catalina.sh stop
}
date
echo "Starting Tomcat"
export CATALINA_PID=/tmp/$$
export JAVA_HOME=/usr/local/java
export LD_LIBRARY_PATH=/usr/local/apr/lib
export JAVA_OPTS="-Dcom.sun.management.jmxremote.port=8999 -Dcom.sun.management.jmxremote.password.file=/etc/tomcat.jmx.pwd -Dcom.sun.management.jmxremote.access.file=/etc/tomcat.jmxremote.access -Dcom.sun.management.jmxremote.ssl=false -Xms128m -Xmx3072m -XX:MaxPermSize=256m"
# Uncomment to increase Tomcat's maximum heap allocation
# export JAVA_OPTS=-Xmx512M $JAVA_OPTS
. $TOMCAT_HOME/bin/catalina.sh start
# Allow any signal which would kill a process to stop Tomcat
trap shutdown HUP INT QUIT ABRT KILL ALRM TERM TSTP
echo "Waiting for `cat $CATALINA_PID`"
wait `cat $CATALINA_PID`
这是我在/etc/supervisord.conf中使用的:
[program:tomcat]
directory=/usr/local/tomcat
command=/usr/local/tomcat/bin/supervisord_wrapper.sh
stdout_logfile=syslog
stderr_logfile=syslog
user=apache
运行,看起来像这样:
[root@qa1.qa:~]# supervisorctl start tomcat
tomcat: started
[root@qa1.qa:~]# supervisorctl status
tomcat RUNNING pid 9611, uptime 0:00:03
[root@qa1.qa:~]# ps -ef|grep t[o]mcat
apache 9611 9581 0 13:09 ? 00:00:00 /bin/bash /usr/local/tomcat/bin/supervisord_wrapper.sh start
apache 9623 9611 99 13:09 ? 00:00:10 /usr/local/java/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Dcom.sun.management.jmxremote.port=8999 -Dcom.sun.management.jmxremote.password.file=/etc/tomcat.jmx.pwd -Dcom.sun.management.jmxremote.access.file=/etc/tomcat.jmxremote.access -Dcom.sun.management.jmxremote.ssl=false -Xms128m -Xmx3072m -XX:MaxPermSize=256m -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/local/tomcat/endorsed -classpath /usr/local/tomcat/bin/bootstrap.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
最初,我尝试通过environment
指令将这些环境变量添加到/etc/supervisord.conf中,但遇到JAVA_OPTS的麻烦,因为所有空格和等号都相同。将其放在包装脚本中就可以了。
希望这有助于节省其他人的时间!
在catalina.sh中有一个“运行”命令。与主管完美配合:
[program:tomcat]
command=/path/to/tomcat/bin/catalina.sh run
process_name=%(program_name)s
startsecs=5
stopsignal=INT
user=tomcat
redirect_stderr=true
stdout_logfile=/var/log/tomcat.log
tomcat运行为“ catalina.sh运行”在前台工作,具有正确的pid并接受信号。与主管一起工作正常。
主管似乎没有办法指定关闭“命令”,仅使用信号即可。
您尝试过使用stopsignal=QUIT
吗?
[program:tomcat]
command=java ...
process_name=tomcat
priority=150
startsecs=10
directory=./
stopsignal=QUIT
stdout_logfile=./logs/tomcat.log
stderr_logfile=./logs/tomcat.err
start
中的Tomcat7 。请注意,在/etc/supervisord.conf中命令的末尾是不必要的参数,因为脚本对此不起作用。