Starting and killing java app with shell script (Debian)(使用 shell 脚本启动和终止 java 应用程序(Debian))
问题描述
我是 UNIX 新手.我想用这样的脚本启动我的 java 应用程序:
I'm new to UNIX. I want to start my java app with a script like so:
#!/bin/sh
java -jar /usr/ScriptCheck.jar &
echo $! > /var/run/ScriptCheck.pid
这应该是有效的.它确实运行应用程序并且确实写入了 pid 文件.但是当我尝试使用包含以下内容的不同脚本停止该过程时:
This is supposedly working. It does run the app and it does write the pid file. But when I try to stop the process with a different script which contains this:
#!/bin/sh
kill -9 /var/run/ScriptCheck.pid
控制台给了我这个错误:
the console gives me this error:
bash: kill: /var/run/ScriptCheck.pid: arguments must be process or job IDs
我最好的猜测是我没有在停止脚本中编写正确的代码,可能没有给出正确的命令来打开 .pid 文件.任何帮助将不胜感激.
My best guess is that I'm not writing the right code in the stop script, maybe not giving the right command to open the .pid file. Any help will be very appreciated.
推荐答案
当 kill
需要一个 (proces id) 编号时,您将文件名作为参数传递给它,所以只需阅读来自该文件的进程 ID 并将其传递给 kill
:
You're passing a file name as an argument to kill
when it expects a (proces id) number, so just read the process id from that file and pass it to kill
:
#!/bin/sh
PID=$(cat /var/run/ScriptCheck.pid)
kill -9 $PID
这篇关于使用 shell 脚本启动和终止 java 应用程序(Debian)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 shell 脚本启动和终止 java 应用程序(Debian)


基础教程推荐
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01