run.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. type=$1
  3. filename=$2
  4. if [ -z "$type" ] || [ -z "$filename" ]; then
  5. echo "Usage: $0 <type> <filename>"
  6. exit 1
  7. fi
  8. dirpath=$(dirname "$filename")
  9. echo $type $filename $dirpath
  10. network_dest_dir="/home/forlinx/Desktop/workspace/TPMFM-A"
  11. monitor_dest_dir="/home/forlinx/monitor"
  12. compute_dest_dir="/home/forlinx/Desktop/workspace/dataParsing"
  13. mkdir -p "$network_dest_dir" "$monitor_dest_dir" "$compute_dest_dir"
  14. echo "stopping app..."
  15. systemctl stop monitor
  16. echo "Waiting for monitor to fully stop..."
  17. sleep 2 # 等待 2 秒
  18. while systemctl is-active --quiet monitor; do
  19. echo "monitor still running, waiting..."
  20. sleep 1
  21. done
  22. echo "monitor stopped."
  23. # 根据类型解压
  24. case "$type" in
  25. network)
  26. echo "Extracting network package..."
  27. tar --overwrite -zxvf "$filename" -C "$network_dest_dir"
  28. ;;
  29. monitor)
  30. echo "Extracting monitor package..."
  31. tar --overwrite -zxvf "$filename" -C "$monitor_dest_dir"
  32. if [ -f $monitor_dest_dir/monitor.service ]; then
  33. cp "$monitor_dest_dir/monitor.service" /etc/systemd/system/
  34. systemctl daemon-reload
  35. else
  36. echo "monitor.service not found in $monitor_dest_dir"
  37. fi
  38. ;;
  39. compute)
  40. echo "Extracting compute package..."
  41. tar --overwrite -zxvf "$filename" -C "$compute_dest_dir"
  42. ;;
  43. *)
  44. echo "Unsupported file type: $type"
  45. exit 1
  46. ;;
  47. esac
  48. echo "restarting app..."
  49. systemctl enable --now monitor
  50. echo "begin cleanup..."
  51. if [ -d "$dirpath" ]; then
  52. rm -rf "$dirpath"/*
  53. else
  54. echo "Directory $dirpath does not exist, skipping cleanup."
  55. fi
  56. echo "cleanup complete"
  57. # 再次检查 monitor 服务状态
  58. status=$(systemctl is-active monitor)
  59. echo "Monitor service status after restart: $status"
  60. sleep 3
  61. # 可选:显示详细状态
  62. # systemctl status monitor
  63. journalctl -u monitor.service -n 100
  64. echo ""
  65. echo "脚本执行完成!"