service¶
import "github.com/jbcom/radioactive-ralph/internal/service"
Package service manages platform service definitions for the durable repo-scoped radioactive_ralph runtime.
Platform dispatch:
macOS → launchd user agent
Linux/WSL → systemd user unit
Windows → native Service Control Manager entry
Service-context detection is used to distinguish durable service launches from operator-attached `radioactive_ralph run` sessions.
Index¶
Variables¶
ErrMissingRalphBin is returned when RalphBin is empty.
var ErrMissingRalphBin = errors.New("service: RalphBin required")
ErrMissingRepoPath is returned when RepoPath is empty.
var ErrMissingRepoPath = errors.New("service: RepoPath required")
ErrUnsupportedBackend is returned for platforms we don’t manage.
var ErrUnsupportedBackend = errors.New("service: unsupported platform")
func Install¶
func Install(opts InstallOptions) (path string, err error)
Install writes or registers the platform service definition for the given repo. On launchd/systemd this means writing the unit file; on Windows it also registers the SCM entry.
func IsServiceContext¶
func IsServiceContext() bool
IsServiceContext reports whether the current process looks like it’s running under the durable repo-service host rather than an operator-attached foreground invocation.
func MarshalWindowsServiceConfig¶
func MarshalWindowsServiceConfig(opts InstallOptions) ([]byte, error)
MarshalWindowsServiceConfig renders the Windows service config in the exact JSON form written to disk for the native service host.
func Uninstall¶
func Uninstall(opts InstallOptions) error
Uninstall removes the unit file. Returns nil if already absent.
func UnitName¶
func UnitName(b Backend, repoPath string) string
UnitName returns the canonical service definition name for a repo. launchd: “jbcom.radioactive-ralph.<slug>.<hash>” systemd: “radioactive_ralph-<slug>-<hash>” windows-scm: “radioactive_ralph-<slug>-<hash>”
func UnitPath¶
func UnitPath(b Backend, home, repoPath string) string
UnitPath returns the on-disk path where the unit file will be written. Callers pass the operator’s home dir (tests inject a tmpdir).
func WindowsServiceArgs¶
func WindowsServiceArgs(repoPath, serviceName, configPath string) []string
WindowsServiceArgs returns the radioactive_ralph argv used by the native Windows SCM service entry.
type Backend¶
Backend identifies which platform mechanism is in use.
type Backend string
const (
// BackendLaunchd is macOS per-user launchd agent.
BackendLaunchd Backend = "launchd"
// BackendSystemdUser is Linux/WSL systemd user unit.
BackendSystemdUser Backend = "systemd-user"
// BackendWindowsSCM is a native Windows service managed by the Service
// Control Manager.
BackendWindowsSCM Backend = "windows-scm"
// BackendUnsupported is returned for platforms we don't manage.
BackendUnsupported Backend = "unsupported"
)
func DetectBackend¶
func DetectBackend() Backend
DetectBackend returns the appropriate backend for the current OS.
type InstallOptions¶
InstallOptions configures an install.
type InstallOptions struct {
// Backend overrides the detected platform. Empty = detect.
Backend Backend
// HomeDir overrides os.UserHomeDir. Empty = use os.UserHomeDir().
HomeDir string
// RalphBin is the absolute path to the radioactive_ralph binary that
// the unit should exec. Required.
RalphBin string
// RepoPath is the operator's repo — written into the unit as the
// working directory for the durable runtime and used to derive the
// service unit name. Required.
RepoPath string
// ExtraEnv is merged into the unit's environment block. Callers use
// this for RALPH_SPEND_CAP_USD etc.
ExtraEnv map[string]string
}
type WindowsServiceConfig¶
WindowsServiceConfig is the persisted config payload used by the native Windows service host.
type WindowsServiceConfig struct {
RepoPath string `json:"repo_path"`
ExtraEnv map[string]string `json:"extra_env,omitempty"`
}
func BuildWindowsServiceConfig¶
func BuildWindowsServiceConfig(opts InstallOptions) WindowsServiceConfig
BuildWindowsServiceConfig produces the persisted config payload for a repo service instance.
func ParseWindowsServiceConfig¶
func ParseWindowsServiceConfig(raw []byte) (WindowsServiceConfig, error)
ParseWindowsServiceConfig parses the persisted Windows service config JSON.
Generated by gomarkdoc