Atm,我需要随机开始和停止(因为我脑子里没有更好的词)工作。我通过键入java -jar foo.jar并停止它来启动它,找出它的 pid 并杀死它。杀死它不会导致任何数据丢失或损坏或任何事情,仅供参考。执行这两个步骤很乏味,因为第一个命令必须从特定目录执行,即/usr/share/jetty(kill 可以从任何地方执行)。
所以我在想一些事情
service foo start以及service foo stop启动和停止服务。这可能吗,更重要的是正确吗?还有其他解决方案吗?
谢谢。
Oli*_*Oli 13
是的,Upstart 是一个不错的选择。只需创建一个新文件:
sudoedit /etc/init/my-jetty-jar.conf
Run Code Online (Sandbox Code Playgroud)
您可以将文件名更改为您喜欢的任何名称,然后将其粘贴在其中:
description "Run my jetty jar"
# no start option as you might not want it to auto-start
# This might not be supported - you might need a: start on runlevel [3]
stop on runlevel [!2345]
# if you want it to automatically restart if it crashes, leave the next line in
respawn
script
cd /usr/share/jetty
su -c "/usb/bin/java -jar /path/to/foo.jar" nobody
end script
Run Code Online (Sandbox Code Playgroud)
关于这一点的一些说明,我不会su为了安全而向任何人求助。您可能需要将其su放入另一个帐户,但可能不建议将其作为root.
| 归档时间: |
|
| 查看次数: |
17221 次 |
| 最近记录: |