Bash 스크립트를 시작하도록 서비스 단위를 구성합니다. 왜 실패했나요?

Bash 스크립트를 시작하도록 서비스 단위를 구성합니다. 왜 실패했나요?

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 스크립트의 출력이 다릅니다. 여기에서 새 스크립트 대신 이전(캐시된?) 버전의 스크립트가 사용되고 있는지 확실하지 않습니다. 이 스크립트의 이전 버전에는 결함이 있어 시작하지 못했습니다. 그런 다음 유닛 파일을 생성하고 스크립트를 수정하여 문제를 해결했습니다.

장치가 잘못 구성되었습니까? 제안 사항이 있습니까?

관련 정보