问题描述
我正在使用 foreman export upstart/etc/init
来设置一个 tomcat 应用服务器,这样可以在 Ubuntu 中监控和维护可用性.
I'm using foreman export upstart /etc/init
to setup a tomcat app server, such that availability can be monitored and maintained in Ubuntu.
但有一些挑战我想请教一下:
But there are a few challenges that I would like some advice on:
1) 使用 sudo service tomcat start
启动我的实例后......如果我尝试使用 kill
终止进程......我可以看到它立即被 Upstart 实用程序重新生成......但是它太快了!所需的端口尚未发布.克服这个问题的解决方法是什么?
1) After starting my instance with sudo service tomcat start
... if i try to kill off the process using kill <pid>
... I can see that its instantly respawned by the Upstart utility ... BUT its too fast! The ports required have not been released yet. What would be a workaround to overcome this?
SEVERE: Failed to initialize end point associated with ProtocolHandler ["http-nio-8443"]
8 java.net.BindException: Address already in use
9 at sun.nio.ch.Net.bind0(Native Method)
43 Caused by: java.net.BindException: Address already in use
44 at sun.nio.ch.Net.bind0(Native Method)
2) 我使用 initctl list |grep tomcat
找出 pid
(在本例中为 3518)并终止进程:
2) I use initctl list | grep tomcat
to figure out the pid
(3518 in this case) and kill the process:
$ initctl list | grep tomcat
tomcat start/running
tomcat-web-1 start/running, process 3518
tomcat-web start/running
是否有可能杀死 tomcat-web-1 实际上是一种测试 Upstart 重生能力的错误方式?
Is it possible that killing tomcat-web-1 is actually an incorrect way to test Upstart's respawn capabilities?
3) 另一个挑战是,如果我只这样做一两次,我很快就会遇到内存问题:
3) Another challenge is that if I do this just once or twice, I quickly run into memory problems:
376 Error occurred during initialization of VM
377 Could not reserve enough space for object heap
4) 最后,默认脚本似乎只在错误的退出条件下处理重生.但是机器重启不算是其中之一,那么应该如何增强 foreman export upstart/etc/init
的导出来处理这种情况?
4) Lastly the default script seems to handle respawn only for exit conditions that are erroneous. But a machine reboot does not count as one of those so how should an export from foreman export upstart /etc/init
be enhanced to take care of this scenario?
我想知道是否还有其他人遇到过类似的挑战和/或有解决方法吗?
I wonder if anyone else has run into similar challenges before and/or has workarounds for them?
更新 #1(2013 年 3 月 4 日):
UPDATE # 1 (on Mar 4th 2013):
为了完成 (4),我只需要编辑 appname.conf 文件的 start on
语句以包含 start on (... OR runlevel [2345])
To accomplish (4), I just had to edit the appname.conf file's start on
statement to include start on (... OR runlevel [2345])
推荐答案
在 Step2 中,列出的所有三个结果实际上都是 unix 进程.它们都不是tomcat java webserver.因此,您正在杀死其中一个进程,这可以帮助您管理实际的 tomcat/java 进程,并且当它恢复时……它会尝试再次启动 tomcat.运行 tomcat 的端口从未被释放,内存仍在使用中,因为您从未关闭原始 tomcat!因此,您会体验到 (1) 和 (3).
In Step2, all three results listed are actually unix processes. None of them is the tomcat java webserver. So you are killing one of the processes, which helps you police the actual tomcat/java process and when it comes back up .. it tries to start tomcat again. The ports on which tomcat is running have never been released and the memory is still in use because you never shutdown the original tomcat! Therefore you experience (1) and (3).
识别 java 进程的更好/更简单的方法是查看它的实用程序,例如系统监视器.您将看到一个名为java"的进程,进程 ID 将列在那里.现在为该 pid 发出一个 kill 指令,这将向您展示 foreman+upstart respawn 工作正常.
A better/easier way to identify the java process is to look at it a utility such as System Monitor. You'll see a process with name 'java' and the process id will be listed there. Now issue a kill for that pid, which will demo to you that foreman+upstart respawn works just fine.
这篇关于Tomcat 的 Upstart 脚本在 Ubuntu 上重生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!