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 ¶
- func BinaryConfigPath(binaryName string) string
- func ConfigDir() string
- func ConfigDirPerm() os.FileMode
- func ConfigFilePerm() os.FileMode
- func ConfigPath(binaryName string) string
- func DecodeYAMLConfig(encoded string) (string, error)
- func EncodeYAMLConfig(yamlContent string) string
- func Install(binaryName string, cfg *Config) error
- func IsElevated() bool
- func IsWindowsService() bool
- func LogPath(binaryName string) string
- func RunAsService(binaryName string, handler *Handler) error
- func SaveConfig(binaryName string, cfg *Config) error
- func SaveUserConfig(binaryName string, cfg *Config) error
- func ServiceName(binaryName string) string
- func Start(binaryName string) error
- func Stop(binaryName string) error
- func Uninstall(binaryName string) error
- func UserBinaryConfigPath(binaryName string) string
- func UserConfigDir() string
- func UserConfigPath(binaryName string) string
- func UserInstall(binaryName string, cfg *Config) error
- func UserLogPath(binaryName string) string
- func UserStart(binaryName string) error
- func UserStop(binaryName string) error
- func UserUninstall(binaryName string) error
- type Config
- type Handler
- type Status
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BinaryConfigPath ¶
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
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
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 ¶
ConfigPath returns the full path to the service config JSON file.
func DecodeYAMLConfig ¶ added in v0.2.58
DecodeYAMLConfig decodes the base64-encoded YAML from Config.YAMLConfig.
func EncodeYAMLConfig ¶ added in v0.2.58
EncodeYAMLConfig encodes YAML content as base64 for storage in Config.YAMLConfig.
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
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 ¶
RunAsService is a no-op on Linux (systemd manages the process lifecycle).
func SaveConfig ¶
SaveConfig writes the service configuration to disk.
func SaveUserConfig ¶ added in v0.7.0
SaveUserConfig writes the service configuration to the user dir.
func ServiceName ¶
ServiceName returns the OS service name for a given Tela binary. e.g., "telad" → "telad", "telahubd" → "telahubd"
func UserBinaryConfigPath ¶ added in v0.7.0
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
UserConfigPath returns the path to the user-level service config JSON.
func UserInstall ¶ added in v0.7.0
UserInstall creates a systemd user unit and enables it. No root required.
func UserLogPath ¶ added in v0.7.0
UserLogPath returns the path to the user-level log file.
func UserUninstall ¶ added in v0.7.0
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 ¶
LoadConfig reads the service configuration from disk.
func LoadUserConfig ¶ added in v0.7.0
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 ¶
QueryStatus returns the current systemd service status.
func QueryUserStatus ¶ added in v0.7.0
QueryUserStatus returns the status of the user-level service.