我要求 systemd 监督和控制一个进程,但由于某种原因,它失败了。检查问题末尾的输出
我有一个 bash 脚本,/usr/sbin/ros_diagnostics.sh
可以启动多个进程。当我在终端中执行脚本时,效果很好。
userk@histamine:~$ /usr/sbin/./ros_diagnostics.sh
[INFO] [launch]: All log files can be found below /home/userk/.ros/log/2023-03-09-11-55-58-140994-histamine-4737
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [aggregator_node-1]: process started with pid [4739]
[INFO] [diagnostics_updater-2]: process started with pid [4741]
[aggregator_node-1] [INFO] [1678362958.452807708] [AnalyzerGroup]: Retrieved 7 parameter(s) for analyzer group with prefix ''.
[aggregator_node-1] [INFO] [1678362958.452943046] [AnalyzerGroup]: Group '/Testrig', creating diagnostic_aggregator/AnalyzerGroup 'Create3' (breadcrumb: create3) ...
[aggregator_node-1] [INFO] [1678362958.454561926] [AnalyzerGroup]: Retrieved 5 parameter(s) for analyzer group with prefix 'create3'.
[aggregator_node-1] [INFO] [1678362958.454630094] [AnalyzerGroup]: Group '/Testrig/Create3', creating diagnostic_aggregator/GenericAnalyzer 'Propulsion' (breadcrumb: analyzers.propulsion) ...
[aggregator_node-1] [INFO] [1678362958.454962645] [GenericAnalyzerBase]: Initialized analyzer 'Propulsion' with path '/Testrig/Create3/Propulsion' and breadcrumb 'create3.analyzers.propulsion'.
[aggregator_node-1] [INFO] [1678362958.455007938] [AnalyzerGroup]: Adding analyzer 'Propulsion' to group '/Testrig/Create3'.
[aggregator_node-1] [INFO] [1678362958.455031856] [AnalyzerGroup]: Initialized analyzer group '/Testrig/Create3' with path '/Testrig/Create3' and breadcrumb 'create3'.
[aggregator_node-1] [INFO] [1678362958.455047106] [AnalyzerGroup]: Adding analyzer '/Testrig/Create3' to group '/Testrig'.
[aggregator_node-1] [INFO] [1678362958.455061398] [AnalyzerGroup]: Initialized analyzer group 'Testrig' with path '/Testrig' and breadcrumb ''.
[aggregator_node-1] [INFO] [1678362958.455081024] [GenericAnalyzerBase]: Initialized analyzer 'Other' with path '/Testrig/Other' and breadcrumb ''.
pstree
以下是从会话手动启动脚本时的输出tmux
。
├─tmux: server─┬─bash───pstree
│ ├─bash
│ └─bash───ros_diagnostics───ros2─┬─aggregator_node───10*[{aggregator_node}]
│ ├─diagnostics_upd───9*[{diagnostics_upd}]
│ └─2*[{ros2}]
我正在尝试配置一个服务单元以在启动时执行此脚本。这是服务单元文件
[Unit]
After=network-online.target
[Service]
Type=simple
User=userk
ExecStart=/usr/sbin/ros_diagnostics.sh
[Install]
WantedBy=multi-user.target
启用服务,重新加载守护进程,启动它......它就死了。这是的输出sudo systemctl status ros_diagnostics.service
userk@histamine:~$ sudo systemctl status ros_diagnostics.service
● ros_diagnostics.service
Loaded: loaded (/etc/systemd/system/ros_diagnostics.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Thu 2023-03-09 11:37:38 UTC; 9min ago
Process: 4519 ExecStart=/usr/sbin/ros_diagnostics.sh (code=exited, status=0/SUCCESS)
Main PID: 4519 (code=exited, status=0/SUCCESS)
Mar 09 11:37:36 histamine systemd[1]: Started ros_diagnostics.service.
Mar 09 11:37:38 histamine ros_diagnostics.sh[4577]: [INFO] [launch]: All log files can be found below /home/userk/.ros/log/2023-03-09-11-37-38-219143-histamine-4577
Mar 09 11:37:38 histamine ros_diagnostics.sh[4577]: [INFO] [launch]: Default logging verbosity is set to INFO
Mar 09 11:37:38 histamine ros_diagnostics.sh[4577]: [INFO] [aggregator_node-1]: process started with pid [4579]
Mar 09 11:37:38 histamine ros_diagnostics.sh[4577]: [INFO] [diagnostics_updater-2]: process started with pid [4581]
Mar 09 11:37:38 histamine ros_diagnostics.sh[4577]: [aggregator_node-1] /opt/ros/foxy/lib/diagnostic_aggregator/aggregator_node: >
Mar 09 11:37:38 histamine ros_diagnostics.sh[4577]: [ERROR] [aggregator_node-1]: process has died [pid 4579, exit code 127, cmd '/opt/ros/foxy/lib/diagnostic_aggregator/aggregator_node --ros-args --params-file /home/userk/development/ros2/galactic_ws/install/robot_diagnostics/share/robot_diagnostics/config/diagnostics.yaml -r /diagnostics:=diagnostics -r /diagnostics_agg:=diagnostics_agg -r /diagnostics_toplevel_state:=diagnostics_toplevel_state'].
Mar 09 11:37:38 histamine ros_diagnostics.sh[4577]: [INFO] [diagnostics_updater-2]: sending signal 'SIGINT' to process[diagnostic>
Mar 09 11:37:38 histamine ros_diagnostics.sh[4577]: [ERROR] [diagnostics_updater-2]: process has died [pid 4581, exit code -2, cmd '/home/userk/development/ros2/galactic_ws/install/robot_diagnostics/lib/robot_diagnostics/diagnostics_updater --ros-args -r /diagnostics:=diagnostics -r /diagnostics_agg:=diagnostics_agg -r /diagnostics_toplevel_state:=diagnostics_toplevel_state'].
Mar 09 11:37:38 histamine systemd[1]: ros_diagnostics.service: Succeeded.
注意 bash 脚本的输出不同。不确定这里是否正在使用脚本的旧(缓存?)版本而不是新版本。该脚本的先前版本存在缺陷并且无法启动。我当时创建了单元文件,然后修改了脚本并修复了它的问题。
是不是单位配置不正确,有什么建议吗?