| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #!/bin/bash
- type=$1
- filename=$2
- if [ -z "$type" ] || [ -z "$filename" ]; then
- echo "Usage: $0 <type> <filename>"
- exit 1
- fi
- dirpath=$(dirname "$filename")
- echo $type $filename $dirpath
- src_workspace="/userdata/workspace"
- dst_workspace="/home/forlinx/Desktop/workspace"
- network_dir="$src_workspace/TPMFM-A"
- monitor_dir="$src_workspace/monitor"
- compute_dir="$src_workspace/dataParsing"
- mkdir -p "$network_dir" "$monitor_dir" "$compute_dir"
- echo "stopping app..."
- systemctl stop monitor
- echo "Waiting for monitor to fully stop..."
- sleep 2 # 等待 2 秒
- while systemctl is-active --quiet monitor; do
- echo "monitor still running, waiting..."
- sleep 1
- done
- echo "monitor stopped."
- # 根据类型解压
- case "$type" in
- network)
- echo "Extracting network package..."
- tar --overwrite -zxvf "$filename" -C "$network_dir"
- ;;
- monitor)
- echo "Extracting monitor package..."
- tar --overwrite -zxvf "$filename" -C "$monitor_dir"
- if [ -f $monitor_dir/monitor.service ]; then
- cp "$monitor_dir/monitor.service" /etc/systemd/system/
- systemctl daemon-reload
- else
- echo "monitor.service not found in $monitor_dir"
- fi
- ;;
- compute)
- echo "Extracting compute package..."
- tar --overwrite -zxvf "$filename" -C "$compute_dir"
- ;;
- *)
- echo "Unsupported file type: $type"
- exit 1
- ;;
- esac
- echo "create a symbolic link..."
- rm -rf $dst_workspace
- ln -sf /userdata/workspace $dst_workspace
- chown -h forlinx:forlinx $dst_workspace
- echo "restarting app..."
- systemctl enable --now monitor
- echo "begin cleanup..."
- if [ -d "$dirpath" ]; then
- rm -rf "$dirpath"/*
- else
- echo "Directory $dirpath does not exist, skipping cleanup."
- fi
- echo "cleanup complete"
- # 再次检查 monitor 服务状态
- status=$(systemctl is-active monitor)
- echo "Monitor service status after restart: $status"
- sleep 3
- # 可选:显示详细状态
- # systemctl status monitor
- journalctl -u monitor.service -n 100
- echo ""
- echo "脚本执行完成!"
|