1. Background
我们的netty application是在windows 7下的Eclipse Luna开发的,用到了spring 4和hibernate 4,JDK是1.7
2. Packaging
打包是直接在Eclipse里面export -> jar -> executable jar,然后选择main class和包路径,easy!
3. Deployment
3.1 java -jar xxx.jar
刚开始,直接用SSH Secure Shell登陆我们的linux服务器,把包传到对应的位置,然后运行java -jar xxx.jar。
这样可以跑起来,日志也正常输出到指定的路径,用自己写的client连接也正常,数据推送正常。
只是,过不了多久,再连接就只能拿到初始化的数据了,不再有推送,查看服务器日志,有这样的错误:
Force-closing a channel whose registration task was not accepted by an event loop:
Failed to submit a listener notification task. Event loop shut down?
java.util.concurrent.RejectedExecutionException: event executor terminated
然后发现应用中的@Predestroy注解的方法被调用了,我就奇了怪了,为什么会莫名其妙被调用@Predestroy方法呢?
最后才发现,这些异常情况都是和linux的机制相关的,当我在SSH Secure Shell的session expired时,linux就会去kill我启动的那个process,于是程序的@Predestroy被调用,@Predestroy被调用后把netty的eventgroup shutdowngracefully了,所以就不能更新数据了。
知道了原因,就开始了解怎么run process in background了。
3.2 nohup java -jar xxx.jar &
这样可以跑起来,logback日志却没有输出到我之前预想的路径,发现居然跑到/根目录下了,而nohup.out则在/root下面。
关闭session后再测试客户端连接,可以正常接受推送的数据。
奇怪的是,跑了一晚上再来看,又出现只能拿到初始化数据的情况了,郁闷。从日志看也没有看到@Predestroy被调用。
加了些日志,再观察下吧。
Reference:
[1] http://www.thegeekstuff.com/2010/12/5-ways-to-execute-linux-command/
[2] http://www.tecmint.com/screen-command-examples-to-manage-linux-terminals/
[3] http://examples.javacodegeeks.com/enterprise-java/logback/logback-syslog-example/