service

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package service provides cross-platform OS service management for Tela binaries (telad, telahubd). It handles install, uninstall, start, stop, and status operations using the native service manager on each OS (Windows SCM, systemd, launchd).

Each binary reads its runtime configuration from a YAML file in a well-known system directory. The service manager simply starts the binary with "service run", and the binary loads its config from the standard location. To reconfigure, edit the YAML and restart the service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BinaryConfigPath

func BinaryConfigPath(binaryName string) string

BinaryConfigPath returns the standard path to a binary's YAML config file in the system-wide service config directory. e.g. "telad" → C:\ProgramData\Tela\telad.yaml (Windows)

"telad" → /etc/tela/telad.yaml             (Linux/macOS)

func ConfigDir

func ConfigDir() string

ConfigDir returns the directory where service configs are stored. Windows: %ProgramData%\Tela Linux: /etc/tela macOS: /etc/tela

func ConfigDirPerm added in v0.2.61

func ConfigDirPerm() os.FileMode

ConfigDirPerm returns the permission mode for the service config directory. On Windows, directories under ProgramData must be accessible to the SYSTEM account (which runs services). On Unix, 0700 is fine since the service typically runs as root.

func ConfigFilePerm added in v0.2.61

func ConfigFilePerm() os.FileMode

ConfigFilePerm returns the permission mode for service config files. On Windows, files must be readable by the SYSTEM account. On Unix, 0600 restricts access to the owning user (typically root).

func ConfigPath

func ConfigPath(binaryName string) string

ConfigPath returns the full path to the service config JSON file.

func DecodeYAMLConfig added in v0.2.58

func DecodeYAMLConfig(encoded string) (string, error)

DecodeYAMLConfig decodes the base64-encoded YAML from Config.YAMLConfig.

func EncodeYAMLConfig added in v0.2.58

func EncodeYAMLConfig(yamlContent string) string

EncodeYAMLConfig encodes YAML content as base64 for storage in Config.YAMLConfig.

func Install

func Install(binaryName string, cfg *Config) error

Install creates a systemd unit file and enables the service.

func IsElevated

func IsElevated() bool

IsElevated returns true if the current process is running as root.

func IsWindowsService

func IsWindowsService() bool

IsWindowsService always returns false on Linux.

func LogPath added in v0.2.71

func LogPath(binaryName string) string

LogPath returns the path to the service log file. e.g. "telad" → C:\ProgramData\Tela\telad.log (Windows)

"telad" → /etc/tela/telad.log             (Linux/macOS)

func RunAsService

func RunAsService(binaryName string, handler *Handler) error

RunAsService is a no-op on Linux (systemd manages the process lifecycle).

func SaveConfig

func SaveConfig(binaryName string, cfg *Config) error

SaveConfig writes the service configuration to disk.

func SaveUserConfig added in v0.7.0

func SaveUserConfig(binaryName string, cfg *Config) error

SaveUserConfig writes the service configuration to the user dir.

func ServiceName

func ServiceName(binaryName string) string

ServiceName returns the OS service name for a given Tela binary. e.g., "telad" → "telad", "telahubd" → "telahubd"

func Start

func Start(binaryName string) error

Start starts the systemd service.

func Stop

func Stop(binaryName string) error

Stop stops the systemd service.

func Uninstall

func Uninstall(binaryName string) error

Uninstall stops, disables, and removes the systemd unit file.

func UserBinaryConfigPath added in v0.7.0

func UserBinaryConfigPath(binaryName string) string

UserBinaryConfigPath returns the path to the user-level binary YAML config (e.g., ~/.tela/tela.yaml).

func UserConfigDir added in v0.7.0

func UserConfigDir() string

UserConfigDir returns the user-level config directory for autostart tasks that do not require admin/root privileges. Windows: %APPDATA%\Tela Linux: ~/.tela macOS: ~/.tela

func UserConfigPath added in v0.7.0

func UserConfigPath(binaryName string) string

UserConfigPath returns the path to the user-level service config JSON.

func UserInstall added in v0.7.0

func UserInstall(binaryName string, cfg *Config) error

UserInstall creates a systemd user unit and enables it. No root required.

func UserLogPath added in v0.7.0

func UserLogPath(binaryName string) string

UserLogPath returns the path to the user-level log file.

func UserStart added in v0.7.0

func UserStart(binaryName string) error

UserStart starts the user service.

func UserStop added in v0.7.0

func UserStop(binaryName string) error

UserStop stops the user service.

func UserUninstall added in v0.7.0

func UserUninstall(binaryName string) error

UserUninstall stops, disables, and removes the user unit.

Types

type Config

type Config struct {
	// BinaryPath is the absolute path to the executable.
	BinaryPath string `json:"binaryPath"`

	// Description is a human-readable service description.
	Description string `json:"description,omitempty"`

	// WorkingDir is the working directory for the service process.
	WorkingDir string `json:"workingDir,omitempty"`

	// YAMLConfig optionally stores the binary's YAML config inline (base64-encoded).
	// If present, YAMLConfig takes precedence over the separate YAML file.
	// This avoids file permission issues on Windows (service runs as SYSTEM,
	// which may not have read access to user-created files).
	YAMLConfig string `json:"yamlConfig,omitempty"`
}

Config holds the minimal metadata needed by the OS service manager. The actual runtime configuration (hub URLs, ports, etc.) usually lives in a YAML file, but can optionally be stored inline in this JSON for better permission handling on Windows.

func LoadConfig

func LoadConfig(binaryName string) (*Config, error)

LoadConfig reads the service configuration from disk.

func LoadUserConfig added in v0.7.0

func LoadUserConfig(binaryName string) (*Config, error)

LoadUserConfig reads the service configuration from the user dir.

type Handler

type Handler struct {
	Run func(stopCh <-chan struct{})
}

Handler wraps a start/stop function pair (used on Windows; on Linux the process just runs normally and handles SIGTERM).

type Status

type Status struct {
	Installed bool
	Running   bool
	UserMode  bool   // true when installed as a user-level autostart task
	Info      string // platform-specific status detail
}

Status represents the current state of an installed service.

func QueryStatus

func QueryStatus(binaryName string) (*Status, error)

QueryStatus returns the current systemd service status.

func QueryUserStatus added in v0.7.0

func QueryUserStatus(binaryName string) (*Status, error)

QueryUserStatus returns the status of the user-level service.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL