sebhildebrandt / systeminformation

System Information Library for Node.JS
MIT License
2.65k stars 300 forks source link

Service status shows as false when the service name differs between systemctl and ps. #899

Open narmatha291289 opened 3 months ago

narmatha291289 commented 3 months ago

Description:

Currently, the service list is retrieved using the systemctl command, and for fetching the running status and pids of a service, ps command is used, but the service name need not to be similar in both systemctl and ps. In that case, the service status is showing as false. Therefore, it is recommended to fetch the status and PIDs directly from the systemctl command to ensure accuracy.

Proposed Solution:

To mitigate this issue, it's suggested to solely rely on systemctl for fetching service statuses and associated PIDs. This ensures consistency and accuracy in reporting service statuses. Below is an updated command to fetch the PID list of a service using systemctl:

mainPid=$(systemctl show -p MainPID --value nginx)
pgrep -P $mainPid

Steps to Reproduce:

  1. Run the current script/command for fetching service statuses and PIDs.
  2. Observe discrepancies in service status reporting due to differing service names between systemctl and ps.
  3. Implement the proposed solution and verify the consistency in service status reporting.