You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Debian下usmd服务异常诊断求助:进程缺失与代码报错问题

诊断:Python Web服务无法调用wdds/wddcs命令行工具的问题

我有一个基于Python的Web服务,通过包装器调用命令行工具。

正常情况下systemctl status usmd的服务状态:

# systemctl status usmd
usmd.service - Western Digital Resource Manager Web Application HTTP server
  Loaded: loaded (/etc/systemd/system/usmd.service; static; vendor preset: enabled)
  Active: active (running) since Thu 2020-12-31 11:28:26 IST; 1h 18min ago
Main PID: 35459 (python3)
   Tasks: 7 (limit: 7372)
  CGroup: /system.slice/usmd.service
          |-- 2650 /bin/sh -c wdds /dev/sg2 show handles
          |-- 2651 wddcs /dev/sg2 show handles
          |--19819 /usr/bin/python3 /opt/usm/inbandmgmt/middleware/main.py

安装后的服务状态:

# systemctl status usmd
● usmd.service - Western Digital Resource Manager Web Application HTTP server.
     Loaded: loaded (/etc/systemd/system/usmd.service; enabled; preset: enabled)
     Active: active (running) since Wed 2023-10-11 13:03:10 EDT; 7h ago
   Main PID: 1002 (python3)
      Tasks: 25 (limit: 38356)
     Memory: 172.5M
        CPU: 2h 37min 23.653s
     CGroup: /system.slice/usmd.service
             └─1002 /usr/bin/python3 /opt/usm/inbandmgmt/middleware/main.py

Oct 11 18:46:05 GA01WDRM-TST-SRV01 python3[1002]:     drive_handles = WDDCS.get_handles(serial, hba_index,True)
Oct 11 18:46:05 GA01WDRM-TST-SRV01 python3[1002]:                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Oct 11 18:46:05 GA01WDRM-TST-SRV01 python3[1002]:   File "/opt/usm/inbandmgmt/app/services/hal/wddcs_wrapper.py", line 557, in get_handles
Oct 11 18:46:05 GA01WDRM-TST-SRV01 python3[1002]:     slot_map = (list(map(get_slot_map,output)))
Oct 11 18:46:05 GA01WDRM-TST-SRV01 python3[1002]:                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Oct 11 18:46:05 GA01WDRM-TST-SRV01 python3[1002]:   File "/opt/usm/inbandmgmt/app/services/hal/wddcs_wrapper.py", line 447, in get_slot_map
Oct 11 18:46:05 GA01WDRM-TST-SRV01 python3[1002]:     if items[dev_index].startswith("/dev/") or items[dev_index].startswith("PD"):
Oct 11 18:46:05 GA01WDRM-TST-SRV01 python3[1002]:        ~~~~~^^^^^^^^^^^
Oct 11 18:46:05 GA01WDRM-TST-SRV01 python3[1002]: IndexError: list index out of range
Oct 11 18:46:05 GA01WDRM-TST-SRV01 python3[1002]: 10.168.101.99 - - [11/Oct/2023:18:46:04 -0400] "POST /storage/driveinfo?hba_index=1&serial=USWSJ01219EZ0023 HTTP/1.1" 500 265 "https://10.168.101.129/" "Mozilla/5.0 (Windows NT 10.0; W>

当前问题:预期的wdds、wddcs进程未运行,且代码出现IndexError;手动执行相关命令正常,但服务无法正常调用。


诊断步骤

  1. 对比环境变量差异

    • 手动执行命令时用env查看当前环境变量,用systemctl show usmd | grep Environment查看服务的环境变量。
    • systemd服务默认PATH可能不包含wdds/wddcs所在目录,可在/etc/systemd/system/usmd.service的[Service]段添加Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/path/to/wdds(替换为实际命令所在路径),重启服务测试。
  2. 验证权限一致性

    • 查看usmd.service文件中的User配置,确认服务运行用户。
    • 模拟服务用户执行命令:su - 服务用户名 -c "wdds /dev/sg2 show handles",测试是否能正常执行,是否有权限访问/dev/sg2设备或命令本身。
  3. 捕获命令执行的完整日志

    • 修改Python包装器代码,捕获命令执行的标准错误输出:
      import subprocess
      def run_wdds_command():
          try:
              proc = subprocess.run(
                  ["wdds", "/dev/sg2", "show", "handles"],
                  capture_output=True,
                  text=True,
                  check=True
              )
              return proc.stdout
          except subprocess.CalledProcessError as e:
              print(f"wdds命令执行失败: {e.stderr}")
              raise
      
    • 或在usmd.service的[Service]段添加StandardOutput=journal+console和StandardError=journal+console,用journalctl -u usmd -f实时查看服务日志,定位命令调用的具体错误。
  4. 确认命令路径正确性

    • 用which wdds和which wddcs获取命令的绝对路径,修改Python包装器中的命令调用,使用绝对路径而非相对路径,避免服务PATH缺失导致的命令找不到问题。
  5. 修复代码解析逻辑

    • IndexError说明命令输出的解析逻辑存在边界问题:
      • 先确认服务用户执行命令后的输出格式,和手动执行的输出对比,看是否为空或格式不一致。
      • 在wddcs_wrapper.py的get_slot_map函数中增加边界判断:
        if len(items) > dev_index and (items[dev_index].startswith("/dev/") or items[dev_index].startswith("PD")):
            # 原有业务逻辑
        else:
            print(f"无效的输出项: {items}, dev_index: {dev_index}")
            return None 或其他默认值
        

内容的提问来源于stack exchange,提问作者LB-SDS

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 17:34:53