Jetty 9安装在EC2 linux服务器上,jetty.sh被复制到/etc/init.d并在/etc/rc1.d,/etc/rc2.d上生成了正确的链接。
我正在使用SSH连接到实例,并通过sudo service jetty start
运行jetty,即使在注销SSH会话后也能正确加载服务。
但是当我的实例上运行远程SSH命令ssh -t -i key.pem ec2-user@instance.domain.com 'sudo service jetty restart'
时,它会启动,但之后会立即停止。这是日志:
2013-11-14 18:03:01 main DispatcherServlet [INFO] FrameworkServlet 'restapi': initialization completed in 1376 ms
2013-11-14 18:03:01.824:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@67fc3482{/,file:/usr/share/jetty/jetty-distribution-9.0.6.v20130930/webapps/ROOT/,AVAILABLE}{/ROOT}
2013-11-14 18:03:01.941:INFO:oejs.ServerConnector:main: Started ServerConnector@10614f3d{HTTP/1.1}{0.0.0.0:8080}2013-11-14 18:03:02.226:INFO:oejs.ServerConnector:main: Started ServerConnector@666c1838{SSL-http/1.1}{0.0.0.0:8443}2013-11-14 18:03:05.670:INFO:oejs.ServerConnector:Thread-3: Stopped ServerConnector@10614f3d{HTTP/1.1}{0.0.0.0:8080}
2013-11-14 18:03:05.671:INFO:oejs.ServerConnector:Thread-3: Stopped ServerConnector@666c1838{SSL-http/1.1}{0.0.0.0:8443}
我尝试远程执行sudo nohup service jetty restart &
,结果相同。
如何远程重启(SSH)并继续运行?
答案 0 :(得分:2)
我在CentOS(基于RPM)上复制了你的问题,它就像一个魅力。我安装了jetty并在端口7070上配置了它。
停止码头:
# ssh -t -i key.pem ec2-user@ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com 'sudo service jetty stop'
Stopping Jetty: OK
Connection to ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com closed.
没有什么东西正在侦听端口7070:
# ssh -t -i key.pem ec2-user@ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com 'sudo netstat -anp | grep 7070'
Connection to ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com closed.
启动码头:
# ssh -t -i key.pem ec2-user@ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com 'sudo service jetty start'
Starting Jetty: . OK Thu Nov 14 08:57:19 EST 2013
Connection to ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com closed.
端口7070现在正在使用中:
# ssh -t -i key.pem ec2-user@ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com 'sudo netstat -anp | grep 7070'
tcp 0 0 :::7070 :::* LISTEN 2431/java
Connection to ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com closed.
以下是相应的日志:
2013-11-14 08:57:15.610:INFO:oejsh.ContextHandler:main: Started o.e.j.s.h.MovedContextHandler@1c9c8aa{/oldContextPath,null,AVAILABLE}
2013-11-14 08:57:16.283:INFO:oejs.ServerConnector:main: Started ServerConnector@176982e{HTTP/1.1}{0.0.0.0:7070}
2013-11-14 08:57:16.392:INFO:oejs.ServerConnector:main: Started ServerConnector@166320b{SSL-http/1.1}{0.0.0.0:8443}
以下是我使用的平台:
# ssh -t -i key.pem ec2-user@ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com 'sudo lsb_release -a'
LSB Version: :core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.3 (Final)
Release: 6.3
Codename: Final
Connection to ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com closed.
最后,这是hte restart
命令:
# ssh -t -i key.pem ec2-user@ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com 'sudo service jetty restart'
Stopping Jetty: OK
Starting Jetty: . OK Thu Nov 14 09:13:00 EST 2013
Connection to ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com closed.
我通过sudo
运行了上述所有命令,以确保sudo不是问题。
BTW,我不是一个java人,并遵循these指令来安装jetty 9。
答案 1 :(得分:1)
我认为在Jetty完全启动之前初始化脚本会终止,所以在脚本终止后的几秒钟内它仍然需要shell。 试试吧:
ssh -t -i key.pem ec2-user@instance.domain.com 'sh -c "sudo service jetty restart;sleep 8"'
同样,您可以尝试redirect input from your script
ssh -t -i key.pem ec2-user@instance.domain.com <<'FIN'
#commands to run on remote host
/bin/bash --login -i -s << FAIM
su -l -s /bin/bash << FEIN
your_password
nohup service jetty restart &
bg
disown -a
sleep 20
FEIN
sleep 5
FAIM
FIN
另一种选择是询问红帽支持,因为您使用亚马逊云服务付费。
答案 2 :(得分:1)
尝试使用以下命令重定向I / O:
ssh -t -i key.pem ec2-user@instance.domain.com 'sudo service jetty restart </dev/null >/dev/null 2>/dev/null'
如果有帮助,您只能尝试使用&gt; / dev / null。
答案 3 :(得分:1)
工作解决方案:
答案 4 :(得分:0)
试试这个,使用-f强制ssh进入后台:
ssh -f -t -i key.pem ec2-user@instance.domain.com 'sudo service jetty restart'
答案 5 :(得分:0)
根据我上面的评论,这是否有效:
ssh -t -i key.pem ec2-user@instance.example.com "sudo su - -c 'service jetty start'"