run.sh 2.0 KB

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