随笔 - 502  文章 - 1 评论 - 6 阅读 - 37万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

复制代码
项目jar包名wxo.jar

清理,打包,跳过测试(不测试) mvn clean package -Dmaven.test.skip=true 后台执行(默认环境) nohup java -jar wxo.jar ** 参数

-Dfile.encoding=utf-8 :UTF-8编码 解决乱码
--spring.profiles.active=test :test环境

比如编码utf-8, 环境为test.

nohup java -Dfile.encoding=utf-8 -jar wxo.jar --spring.profiles.active=test
后台执行 记录日志(文件名为a 默认值为nohup)
nohup java
-Dfile.encoding=utf-8 -jar wxo.jar --spring.profiles.active=test >a 2>&1 &

后台执行 不记录日志
nohup java
-Dfile.encoding=utf-8 -jar wxo.jar --spring.profiles.active=test >/dev/null 2>&1 &
复制代码

 

在这里nohup 命令使用了解一下

操作系统中有三个常用的流:
  0:标准输入流 stdin
  1:标准输出流 stdout
  2:标准错误流 stderr

  一般当我们用 > console.txt,实际是 1>console.txt的省略用法;< console.txt ,实际是 0 < console.txt的省略用法。
 
>nohup ./start-dishi.sh >output  2>&1 &
解释:
 1. 带&的命令行,即使terminal(终端)关闭,或者电脑死机程序依然运行(前提是你把程序递交到服务器上); 
 2. 2>&1的意思 
  这个意思是把标准错误(2)重定向到标准输出中(1),而标准输出又导入文件output里面,所以结果是标准错误和标准输出都导入文件output里面了。 至于为什么需要将标准错误重定向到标准输出的原因,那就归结为标准错误没有缓冲区,而stdout有。这就会导致 >output 2>output 文件output被两次打开,而stdout和stderr将会竞争覆盖,这肯定不是我门想要的. 
  这就是为什么有人会写成: nohup ./command.sh >output 2>output出错的原因了 
==================================================================================
>nohup ./XXX.sh >a  2>&1 & 的意思就是 2(标准错误流)输入到1(标准输出流)  1(标准输出流)输入到a (文件)
 
/dev/null文件的作用,这是一个无底洞,任何东西都可以定向到这里,但是却无法打开。 所以一般很大的stdou和stderr当你不关心的时候可以利用stdout和stderr定向到这里
>nohup ./XXX.sh >/dev/null 2>&1 &
 

 

 

 

start.sh

#!/bin/sh

#不记录日志
#nohup java -Dfile.encoding=utf-8 -jar wxo.jar --spring.profiles.active=test > /dev/null 2>&1 &
#记录日志
nohup java -Dfile.encoding=utf-8 -jar wxo.jar --spring.profiles.active=test &

echo Start Success!

stop.sh

复制代码
#!/bin/sh
APP_NAME=wxo

tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
    echo 'Stop Process...'
    kill -15 $tpid
fi
sleep 5
tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
    echo 'Kill Process!'
    kill -9 $tpid
else
    echo 'Stop Success!'
fi
复制代码

kill.sh

#!/bin/sh
APP_NAME=wxo

tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
    echo 'Kill Process!'
    kill -9 $tpid
fi

 

posted on   1161588342  阅读(385)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示