nohup java -jar app.jar > /dev/null 2>&1 &
时间: 2023-10-26 18:38:53 浏览: 283
&1 &
This command starts a Java application in the background, redirects standard output to /dev/null (which discards it), redirects standard error to standard output, and detaches the process from the terminal by using nohup and &. This allows the application to continue running even if the terminal is closed, and prevents it from being terminated by the HANGUP (SIGHUP) signal.
相关问题
nohup java -jar app.jar > /dev/null 2>&1 & 解释一下这个命令
&1 &
This command runs a Java application in the background using the nohup command. The output of the application is redirected to /dev/null, which discards it. The 2> redirects any error messages to the same location as the output. The &1 & at the end of the command puts the process in the background and detaches it from the terminal, allowing it to continue running even if the terminal is closed.
写一个shell脚本判断curl -o /dev/null -s -w %{http_code} http://192.168.0.173/riskWeb/secureBaseApp/tenant/tenantByUser的返回值是否等于200,等于的话,输出$(date "+%Y-%m-%d_%H:%M:%S"), cyb-secureBase" is running",如果不等于去判断pid=`ps -ef | grep /app/service/cyb-secureBase/app.jar | grep -v grep | awk '{print $2}'是否有值输出,有的话echo $(date "+%Y-%m-%d_%H:%M:%S"), cyb-secureBase" is running",没有执行nohup java -Xms256m -Xmx1024m -Xmn256m -Dfile.encoding=utf-8 -jar /app/service/cyb-secureBase/app.jar > app.log 2>&1 &
可以参考下面的Shell脚本来实现你的需求:
```shell
#!/bin/bash
# 发送GET请求,并获取返回状态码
response_code=$(curl -o /dev/null -s -w "%{http_code}" http://192.168.0.173/riskWeb/secureBaseApp/tenant/tenantByUser)
# 判断返回状态码是否等于200
if [ $response_code -eq 200 ]; then
echo "$(date "+%Y-%m-%d_%H:%M:%S"), cyb-secureBase is running"
else
# 判断进程是否存在
pid=$(ps -ef | grep /app/service/cyb-secureBase/app.jar | grep -v grep | awk '{print $2}')
if [ -n "$pid" ]; then
echo "$(date "+%Y-%m-%d_%H:%M:%S"), cyb-secureBase is running"
else
nohup java -Xms256m -Xmx1024m -Xmn256m -Dfile.encoding=utf-8 -jar /app/service/cyb-secureBase/app.jar > app.log 2>&1 &
fi
fi
```
将以上代码保存为脚本文件(比如`check_service.sh`),然后通过`chmod +x check_service.sh`添加执行权限。运行脚本`./check_service.sh`即可完成判断和执行操作。
阅读全文
相关推荐















