Skip to main content

Adding IPC Actions

When adding a new daemon IPC action, three files need to be updated.

Step 1: Define the Action (protocol.go)​

Add a constant and payload type to internal/daemon/protocol.go:

const ActionMyAction = "myaction"

type MyActionPayload struct {
Target string `json:"target"`
Custom string `json:"custom,omitempty"`
}

Step 2: Add the Handler (server.go)​

Add a case to the action switch in internal/daemon/server.go:

case ActionMyAction:
var payload MyActionPayload
if err := json.Unmarshal(req.Payload, &payload); err != nil {
return Response{Success: false, Error: "invalid payload"}
}

// Implement the action using the supervisor
result, err := s.supervisor.MyAction(payload.Target, payload.Custom)
if err != nil {
return Response{Success: false, Error: err.Error()}
}

data, _ := json.Marshal(result)
return Response{Success: true, Data: data}

Step 3: Use from CLI (cmd/runix/*.go)​

The CLI uses sendIPC() generically — no client.go changes needed:

resp, err := sendIPC(daemon.ActionMyAction, daemon.MyActionPayload{
Target: target,
Custom: "value",
})
if err != nil {
// Handle IPC failure
} else if !resp.Success {
return fmt.Errorf("daemon error: %s", resp.Error)
}
// Use resp.Data

Existing Actions Reference​

ActionPayloadHandler
startStartPayloadCreates and starts a process
stopStopPayloadStops a process
restartStopPayloadRestarts a process
reloadStopPayloadReloads a process
deleteStopPayloadStops and removes a process
listnilLists all processes
statusStopPayloadGets process status
logsLogsPayloadGets process logs
inspectStopPayloadGets detailed process info
savenilSaves process state
resurrectnilRestores saved processes
rolling_reloadRollingReloadPayloadRolling reload
cron_listnilLists cron jobs
cron_startCronPayloadEnables a cron job
cron_stopCronPayloadDisables a cron job
cron_runCronPayloadTriggers a cron job
config_reloadnilReloads configuration
alivenilHealth check ping

Conventions​

  • All actions are POST / with JSON body
  • Payload structs use json tags
  • Responses always have Success, Data, and Error fields
  • Handlers should validate payloads before processing
  • Use the supervisor as the single source of truth

What's Next​