项目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 2018-01-27 10:14  1161588342  阅读(371)  评论(0编辑  收藏  举报