1、自己將項目(比如用springboot框架寫的項目)打包成jar包,然後我們需要將它用軟件傳輸到linux版本的服務器上(服務器提前安裝好JDK>=1.8)。
2、自己編寫sh命令,用於啓動和關閉項目,並打印日誌信息到服務器本地。
1)、start_項目名.sh文件
#For shutting down the 你的項目名.jar
pid=$(ps -ef | grep 你的項目名.jar| grep -v "grep" | awk '{print $2}')
kill -9 $pid
echo "The 你的項目名.jar now has been shut down!"
#For starting the 你的項目名.jar
nohup java -jar 你的項目名.jar >你的項目日誌名.output 2>&1 &
echo "The 你的項目名.jar now is running!"
tailf 你的項目日誌名.output
2)、shutdown_項目名.sh文件
#For shutting down the 你的項目名.jar
pid=$(ps -ef | grep 你的項目名.jar| grep -v "grep" | awk '{print $2}')
kill -9 $pid
echo "The 你的項目名.jar now has been shut down!"
3、將你的項目jar包、start_項目名.sh、shutdown_項目名.sh放在服務器的某一個文件夾下(他三個處於同一個目錄),此時,可以用控制檯啓動和關閉項目了。