#!/bin/bash type=$1 filename=$2 if [ -z "$type" ] || [ -z "$filename" ]; then echo "Usage: $0 " 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 $src_workspace $dst_workspace chown -R forlinx:forlinx $src_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 "脚本执行完成!"