pyinfra icon indicating copy to clipboard operation
pyinfra copied to clipboard

Systemd service failure not detected correctly

Open ReggieMarr opened this issue 7 months ago • 0 comments

I'm having an issue where a systemd.service restart doesn't seem to detect that the service fails. I was trying to debug it but I'm getting the following error:

Traceback (most recent call last):
  File "/home/user/.local/lib/python3.10/site-packages/pyinfra_cli/util.py", line 65, in exec_file
    exec(PYTHON_CODES[filename], data)
  File "deploy.py", line 140, in <module>
    deploy(param)
  File "deploy.py", line 115, in deploy
    deploy_fsw(username, paramGen.fsw_bin_path)
  File "deploy.py", line 71, in deploy_fsw
    logger.info(response.stdout_lines)
  File "/home/user/.local/lib/python3.10/site-packages/pyinfra/api/operation.py", line 134, in stdout_lines
    self._raise_if_not_complete()
  File "/home/user/.local/lib/python3.10/site-packages/pyinfra/api/operation.py", line 88, in _raise_if_not_complete
    raise RuntimeError("Cannot evaluate operation result before execution")
RuntimeError: Cannot evaluate operation result before execution

Can someone point to an example of how to use the results?

Note this is how I'm currently doing it:

    response = systemd.service(
        name="Re-Start fsw service",
        service="fsw.service",
        running=True,
        restarted=True,
        user_mode=True,
        user_name=username
    )
    if (not response.is_complete):
        logger.info("Waiting for systemdservice to complete...")
        time.sleep(0.2)
    logger.info(response.stdout_lines)

And for completeness this is the underlying service with it's assocated output:


    [Unit]
    Description=FlightComputer Service
    After=network.target

    [Service]
    Type=simple
    EnvironmentFile=/home/rdx/.local/share/rdx/runtime/.env
    ExecStartPre=rm -f /home/rdx/.local/share/fsw_connected
    ExecStart=/home/rdx/.local/share/rdx/runtime/FlightComputer
    Restart=on-failure
    RestartSec=5s
    SuccessExitStatus=0
    RestartPreventExitStatus=2

    [Install]
    WantedBy=default.target
    
× fsw.service - FlightComputer Service
     Loaded: loaded (/home/rdx/.config/systemd/user/fsw.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Thu 2024-07-25 19:06:08 EDT; 25s ago
    Process: 33525 ExecStartPre=rm -f /home/rdx/.local/share/fsw_connected (code=exited, status=0/SUCCESS)
    Process: 33526 ExecStart=/home/rdx/.local/share/rdx/runtime/FlightComputer (code=exited, status=2)
   Main PID: 33526 (code=exited, status=2)
        CPU: 23ms

Jul 25 19:06:06 rdx-PX1-C441 FlightComputer[33526]: [ERROR] Failed to send framed data: 2
Jul 25 19:06:06 rdx-PX1-C441 FlightComputer[33526]: [WARNING] Failed to open port with status -4 and errno 111
Jul 25 19:06:06 rdx-PX1-C441 FlightComputer[33526]: EVENT: (512) (2:1721948766,872053) DIAGNOSTIC: (rateGroup1Comp) RateGroupStarted>Jul 25 19:06:06 rdx-PX1-C441 FlightComputer[33526]: EVENT: (768) (2:1721948766,872167) DIAGNOSTIC: (rateGroup2Comp) RateGroupStarted>Jul 25 19:06:06 rdx-PX1-C441 FlightComputer[33526]: Starting downlink UDP connection with ip 10.10.0.246 and port 50000nEVENT: (1024>Jul 25 19:06:06 rdx-PX1-C441 FlightComputer[33526]: Setup to send udp to 10.10.0.246:50000
Jul 25 19:06:08 rdx-PX1-C441 FlightComputer[33526]: Waiting for threads...
Jul 25 19:06:08 rdx-PX1-C441 FlightComputer[33526]: Exiting...
Jul 25 19:06:08 rdx-PX1-C441 systemd[843]: fsw.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Jul 25 19:06:08 rdx-PX1-C441 systemd[843]: fsw.service: Failed with result 'exit-code'.
lines 1-18/18 (END)Connection to 10.10.0.177 closed.

also here's the pyinfra info:

❯ pyinfra --support

    If you are having issues with pyinfra or wish to make feature requests, please
    check out the GitHub issues at https://github.com/Fizzadar/pyinfra/issues .
    When adding an issue, be sure to include the following:

    System: Linux
      Platform: Linux-5.15.0-116-generic-x86_64-with-glibc2.35
      Release: 5.15.0-116-generic
      Machine: x86_64
    pyinfra: v3.0b4
    Executable: /home/reggiemarr/.pyenv/versions/rdx-gds/bin/pyinfra
    Python: 3.10.12 (CPython, GCC 11.4.0)

ReggieMarr avatar Jul 25 '24 23:07 ReggieMarr