This commit is contained in:
2023-11-11 05:34:56 +08:00
parent a369b43478
commit adc2ceac55
2 changed files with 13 additions and 9 deletions

View File

@@ -1,22 +1,25 @@
#!/bin/bash
host="root@main"
# 更新 go mod, 然後靜態編譯
go mod tidy
go build -o data/main bin/main.go
go build -o dist/main bin/main.go
# 上传到服务器, 然後刪除本地文件
scp ./data/main root@47.103.40.152:~/main_new
rm ./data/main
scp dist/main $host:~/webp/main
rm -rf dist
# pm2 start /root/webp/main --name webp --watch
# 查看 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 $host "ps -ef | grep -v grep | grep ./main"
# ssh $host "kill -9 \`ps -ef | grep -v grep | grep ./main | awk '{print \$2}'\`"
# 重启服务, 保持服务不被关闭 (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"
#ssh $host "rm ./main; mv ./main_new ./main;"
#ssh $host "nohup ./main test >> nohup.out 2>&1 &"
#ssh $host "nohup ./main server >> nohup.out 2>&1 &"
#ssh $host "ps -ef | grep -v grep | grep ./main"
# 查看日志
# ssh root@47.103.40.152 "tail -fn 50 nohup.out"