Skip to content

trading_agent.doctor.checks.service_check

Checks that trading-agent runs as a systemd user service, so it restarts after a crash and at every boot.

Typical usage example:

result = ServiceCheck().run()

ServiceCheck

Bases: DoctorCheck

Asks systemd whether the service is enabled and running.

run

run()

Asks systemctl --user is-enabled and is-active.

Returns:

Type Description
CheckResult

OK when enabled and active; failed otherwise, with the commands that install it.

Source code in src/trading_agent/doctor/checks/service_check.py
def run(self) -> doctor_check.CheckResult:
    """Asks systemctl --user is-enabled and is-active.

    Returns:
        doctor_check.CheckResult: OK when enabled and active; failed otherwise, with the commands that install it.
    """
    enabled = self._ask('is-enabled')
    active = self._ask('is-active')
    if enabled == 'enabled' and active == 'active':
        return doctor_check.CheckResult(
            doctor_check.CheckStatus.OK,
            f'{_UNIT} is enabled and running; it restarts after a crash and starts at boot.',
        )
    return doctor_check.CheckResult(
        doctor_check.CheckStatus.FAILED,
        f'{_UNIT} is {enabled} and {active}. Install it with: systemctl --user link $PWD/deploy/{_UNIT} && systemctl --user enable --now {_UNIT}',
    )