From 54f4baa1e1cea2d4356ddbd6487d45cc8c0f8f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=9C=E8=8F=AF?= Date: Thu, 13 Apr 2023 19:53:08 +0800 Subject: [PATCH] =?UTF-8?q?nohup=20=E5=9B=B0=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- update.sh | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/update.sh b/update.sh index ca9484e..e082ed1 100755 --- a/update.sh +++ b/update.sh @@ -1,24 +1,21 @@ #!/bin/bash -# 更新go.mod +# 更新 go mod, 然後靜態編譯 go mod tidy - -# 靜態編譯 go build -o data/main bin/main.go -# 上传到服务器 +# 上传到服务器, 然後刪除本地文件 scp ./data/main root@47.103.40.152:~/main_new - -# 刪除本地文件 rm ./data/main -# 查看 main_ 的進程 +# 查看 main_ 的進程, 然後使用 kill -9 强制关闭 ssh root@47.103.40.152 "ps -ef | grep -v grep | grep ./main" +ssh root@47.103.40.152 "kill -9 \`ps -ef | grep -v grep | grep ./main | awk '{print \$2}'\`" -# 重启服务, 保持服务不被关闭 -ssh root@47.103.40.152 "pkill './main test'; pkill './main server'; rm ./main; mv ./main_new ./main;" -ssh root@47.103.40.152 "nohup ./main test &" -ssh root@47.103.40.152 "nohup ./main server &" +# 重启服务, 保持服务不被关闭 (pkill ./main; 無效, 還需防止 nohup 不退出) +ssh root@47.103.40.152 "rm ./main; mv ./main_new ./main;" +ssh root@47.103.40.152 "nohup ./main test >> nohup.out 2>&1 &" +ssh root@47.103.40.152 "nohup ./main server >> nohup.out 2>&1 &" ssh root@47.103.40.152 "ps -ef | grep -v grep | grep ./main" # 查看日志