Capy-Bearer Documentation

service_status

lib call

Capy

function service_status(unit : string) any

Description

service_status() reads the supervisor's record of a service. state is stopped, starting, running, stopping, or crashed. pid is the worker process while one runs. started_at is the start time of the current worker. restarts counts crashes the supervisor recovered from. mailbox is the worker's count of messages it holds for delivery, including delayed ones, written at most once a second and only when it changed; it does not count frames still in the kernel queue, the handler running now, or timer and port events. For a service that is not running it is the number of spooled messages. stale is true when the unit's source changed after the running workspace was built; nothing restarts a service on its own, so an admin page can use it to offer a stop and start.

Status reports lifecycle state, not application health or job completion. A worker can be running after a START handler trap. started_at is Unix time in seconds, including a fractional part. A missing or never-started service has zero-valued counters.

Unit paths resolve relative to the calling unit, or from the site root with a leading /.

Parameters

unit : the unit path of the service

Return Values

a map with state, pid, started_at, restarts, mailbox, and stale

Errors

An unknown unit yields state missing. State-file read, decode, and lock failures trap instead of returning a status map.

Example

Capy

var status := service_status("/agents/pool.capy")
print(status.state, " restarts=", s64(status.restarts), " queued=", s64(status.mailbox))

Example

Capy

var status := service_status("/agents/pool.capy")
if status.stale
{
	print("<a href=\"/admin/pool/restart\">Restart the pool</a>")
}