Open clh021 opened 2 years ago
使用脚本管理会有问题 脚本正常退出时 在部分系统(kylinV10)上每次都会有 root 进程残留 在 debian(KDE) 上 root 进程,每次都会被清理
#!/usr/bin/env bash # leehom Chen clh021@gmail.com # 本脚本旨在启动整个检测套件服务,实现一键启动 SCRIPT_PATH=$(realpath "$0") if [[ ${UID} == 0 ]] ; then sudo -E -H -u "${SUDO_USER}" "${SCRIPT_PATH}" exit fi ProjectPath="$(dirname "$SCRIPT_PATH")" pushd "$ProjectPath" > /dev/null || return # sudo kill -9 $(pgrep -f "${ProjectPath}/child.python" ) || : # sudo kill -9 $(pgrep -f "${ProjectPath}/kit" ) || : set -e APP_DOMAIN="http://127.0.0.1:8001" LITHIUM_BIN="$ProjectPath/lithium/lithium" export LANG=en_US.UTF-8 sudo rm -rf ~/.cache/lithium_runtimes sudo rm -rf ~/.cache/lithium_runtimes.xc-detection-kit/ sudo rm -rf ~/.cache/lnks.com sudo rm -rf ~/.lnks.com sudo "$ProjectPath/child.python" & PID_P1=$! "$ProjectPath/detect" & PID_P2=$! "$ProjectPath/main" & PID_P3=$! sudo "$ProjectPath/kit" & PID_P4=$! on_exit() { echo "clean on_exit, kill $PID_P1 $PID_P2 $PID_P3 $PID_P4" # kill -9 ${PID_P4} || : kill -9 ${PID_P3} || : kill -9 ${PID_P2} || : # kill -9 ${PID_P1} || : } trap on_exit EXIT SIGTERM SIGINT BUS_ADDR=unix:path=/run/user/${SUDO_UID}/bus # 启动桌面应用 export HARDINFO_BIN="$ProjectPath/hardinfo/build/hardinfo" export LITHIUM_ENABLE_XPC_URLS="resource://;http://127;http://192" export LITHIUM_VENDOR=".xc-detection-kit" export LITHIUM_NAME=".xc-detection-kit" DBUS_SESSION_BUS_ADDRESS=${BUS_ADDR} \ ${LITHIUM_BIN} \ "-debug" \ "-title=检测套件" \ "-width=1420" \ "-height=936" \ "-style=background:rgba(0,0,0,0); -moz-appearance: none;" \ "-hideChrome" \ "-winMode=normal" \ "-positionX=250" \ "-positionY=52" \ "${APP_DOMAIN}" function getcpid() { cpids=`pgrep -P $1|xargs` # echo "cpids=$cpids" for cpid in $cpids; do echo -n " $cpid" getcpid $cpid done } echo sudo kill -9"$(getcpid $PID_P4)" echo sudo kill -9"$(getcpid $PID_P1)" sudo kill -9"$(getcpid $PID_P4)" || : sudo kill -9"$(getcpid $PID_P1)" || : popd > /dev/null || return
还有 sudo 会超时的问题 夏老板听完所有问题后说:"看看 systemd-run 能不能用" https://manpages.debian.org/unstable/systemd/systemd-run.1.en.html
使用脚本管理会有问题 脚本正常退出时 在部分系统(kylinV10)上每次都会有 root 进程残留 在 debian(KDE) 上 root 进程,每次都会被清理