service

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: Apache-2.0, BSD-3-Clause, MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckTorConnection

func CheckTorConnection(socksAddr string) bool

CheckTorConnection tests if Tor is accessible

func DropPrivileges

func DropPrivileges(userName string) error

DropPrivileges drops from root to the specified user Per AI.md PART 8: Step 8g - DROP PRIVILEGES to search user This uses syscall.Setgid and syscall.Setuid to drop privileges

func FindAvailableSystemID

func FindAvailableSystemID() (int, error)

FindAvailableSystemID finds an available UID/GID in the system range Per AI.md PART 24: UID/GID 100-999 for system accounts

func GetServiceGroup

func GetServiceGroup(serviceName string) string

GetServiceGroup returns the appropriate service group name for the current OS

func GetServiceStatus

func GetServiceStatus() string

GetServiceStatus returns formatted service status information

func GetServiceUser

func GetServiceUser(serviceName string) string

GetServiceUser returns the appropriate service user name for the current OS Per AI.md PART 24: OS-specific user naming

func IsRunningAsRoot

func IsRunningAsRoot() bool

IsRunningAsRoot returns true if the process is running as root

func UserExists

func UserExists(name string) bool

UserExists checks if a system user exists

func VerifyPrivilegesDropped

func VerifyPrivilegesDropped() error

VerifyPrivilegesDropped verifies that privileges have been dropped Per AI.md PART 8: Step 8h - Verify privilege drop succeeded

Types

type GracefulDegradation

type GracefulDegradation struct {
	// contains filtered or unexported fields
}

GracefulDegradation provides fallback behavior when services are unavailable Per AI.md PART 6: Graceful degradation

func NewGracefulDegradation

func NewGracefulDegradation() *GracefulDegradation

NewGracefulDegradation creates a new graceful degradation handler

func (*GracefulDegradation) Execute

func (g *GracefulDegradation) Execute(feature string, fn func() (interface{}, error)) (interface{}, error)

Execute executes a function with graceful degradation

func (*GracefulDegradation) GetDegradedFeatures

func (g *GracefulDegradation) GetDegradedFeatures() []string

GetDegradedFeatures returns a list of currently degraded features

func (*GracefulDegradation) GetFallback

func (g *GracefulDegradation) GetFallback(feature string) interface{}

GetFallback returns the fallback value for a degraded feature

func (*GracefulDegradation) IsDegraded

func (g *GracefulDegradation) IsDegraded(feature string) bool

IsDegraded checks if a feature is degraded

func (*GracefulDegradation) MarkDegraded

func (g *GracefulDegradation) MarkDegraded(feature string)

MarkDegraded marks a feature as degraded

func (*GracefulDegradation) MarkHealthy

func (g *GracefulDegradation) MarkHealthy(feature string)

MarkHealthy marks a feature as healthy

func (*GracefulDegradation) RegisterFallback

func (g *GracefulDegradation) RegisterFallback(feature string, fallback func() interface{})

RegisterFallback registers a fallback function for a feature

type HealthStatus

type HealthStatus struct {
	Component   string    `json:"component"`
	Healthy     bool      `json:"healthy"`
	Message     string    `json:"message,omitempty"`
	LastCheck   time.Time `json:"last_check"`
	LastHealthy time.Time `json:"last_healthy,omitempty"`
	ErrorCount  int       `json:"error_count"`
}

HealthStatus represents the health of a system component

type MaintenanceMode

type MaintenanceMode int

MaintenanceMode represents the current maintenance state Per AI.md PART 6: Maintenance Mode (NON-NEGOTIABLE)

const (
	// ModeNormal is normal operation
	ModeNormal MaintenanceMode = iota
	// ModeDegraded is reduced functionality (some services unavailable)
	ModeDegraded
	// ModeMaintenance is full maintenance mode (read-only, limited access)
	ModeMaintenance
	// ModeRecovery is recovery mode (attempting to repair)
	ModeRecovery
	// ModeEmergency is emergency mode (critical failure, minimal functionality)
	ModeEmergency
)

func (MaintenanceMode) String

func (m MaintenanceMode) String() string

String returns the string representation of the maintenance mode

type MaintenanceService

type MaintenanceService struct {
	// contains filtered or unexported fields
}

MaintenanceService manages maintenance mode and self-healing Per AI.md PART 6: Maintenance Mode (NON-NEGOTIABLE)

func NewMaintenanceService

func NewMaintenanceService(cfg *config.Config) *MaintenanceService

NewMaintenanceService creates a new maintenance service

func (*MaintenanceService) BackupDatabase

func (m *MaintenanceService) BackupDatabase(dbPath, backupDir string) (string, error)

BackupDatabase creates a backup of the database

func (*MaintenanceService) CheckDatabaseIntegrity

func (m *MaintenanceService) CheckDatabaseIntegrity(db *sql.DB) error

CheckDatabaseIntegrity checks database integrity and attempts repair if needed Per AI.md PART 6: Database corruption handling

func (*MaintenanceService) DisableMaintenance

func (m *MaintenanceService) DisableMaintenance()

DisableMaintenance disables maintenance mode

func (*MaintenanceService) EnableMaintenance

func (m *MaintenanceService) EnableMaintenance(message string, duration time.Duration)

EnableMaintenance enables maintenance mode

func (*MaintenanceService) GetHealthStatus

func (m *MaintenanceService) GetHealthStatus() map[string]*HealthStatus

GetHealthStatus returns the health status of all components

func (*MaintenanceService) GetMessage

func (m *MaintenanceService) GetMessage() string

GetMessage returns the current maintenance message

func (*MaintenanceService) GetMode

func (m *MaintenanceService) GetMode() MaintenanceMode

GetMode returns the current maintenance mode

func (*MaintenanceService) GetScheduledEnd

func (m *MaintenanceService) GetScheduledEnd() time.Time

GetScheduledEnd returns when maintenance is scheduled to end

func (*MaintenanceService) GetStatus

func (m *MaintenanceService) GetStatus() map[string]interface{}

GetStatus returns the full maintenance status

func (*MaintenanceService) IsDegraded

func (m *MaintenanceService) IsDegraded() bool

IsDegraded returns true if system is in degraded mode

func (*MaintenanceService) IsInMaintenance

func (m *MaintenanceService) IsInMaintenance() bool

IsInMaintenance returns true if system is in maintenance mode

func (*MaintenanceService) IsNormal

func (m *MaintenanceService) IsNormal() bool

IsNormal returns true if system is in normal mode

func (*MaintenanceService) RegisterCallback

func (m *MaintenanceService) RegisterCallback(cb func(MaintenanceMode))

RegisterCallback registers a callback for mode changes

func (*MaintenanceService) RegisterRecoveryFunc

func (m *MaintenanceService) RegisterRecoveryFunc(component string, fn func(ctx context.Context) error)

RegisterRecoveryFunc registers a recovery function for a component

func (*MaintenanceService) RepairDatabase

func (m *MaintenanceService) RepairDatabase(dbPath string) error

RepairDatabase attempts to repair a corrupted database Per AI.md PART 6: Database corruption handling

func (*MaintenanceService) RestoreDatabase

func (m *MaintenanceService) RestoreDatabase(backupPath, dbPath string) error

RestoreDatabase restores a database from backup

func (*MaintenanceService) SetDatabaseChecks

func (m *MaintenanceService) SetDatabaseChecks(serverCheck, usersCheck func(ctx context.Context) error)

SetDatabaseChecks sets the database check functions

func (*MaintenanceService) SetMode

func (m *MaintenanceService) SetMode(mode MaintenanceMode, message string)

SetMode sets the maintenance mode

func (*MaintenanceService) Start

func (m *MaintenanceService) Start() error

Start starts the maintenance service monitoring

func (*MaintenanceService) Stop

func (m *MaintenanceService) Stop()

Stop stops the maintenance service

type PrivilegeEscalator

type PrivilegeEscalator struct {
	// contains filtered or unexported fields
}

PrivilegeEscalator handles privilege escalation for service installation Per AI.md PART 24: Privilege Escalation (NON-NEGOTIABLE)

func NewPrivilegeEscalator

func NewPrivilegeEscalator() *PrivilegeEscalator

NewPrivilegeEscalator creates a new privilege escalator Per AI.md PART 24: Auto-detect available privilege escalation method

func (*PrivilegeEscalator) EscalateCommand

func (p *PrivilegeEscalator) EscalateCommand(cmd string, args ...string) *exec.Cmd

EscalateCommand wraps a command with privilege escalation Per AI.md PART 24: Wrap commands appropriately for each method

func (*PrivilegeEscalator) IsAvailable

func (p *PrivilegeEscalator) IsAvailable() bool

IsAvailable returns true if privilege escalation is available

func (*PrivilegeEscalator) Method

func (p *PrivilegeEscalator) Method() string

Method returns the detected privilege escalation method

type ServiceManager

type ServiceManager struct {
	// contains filtered or unexported fields
}

ServiceManager handles system service installation

func NewServiceManager

func NewServiceManager(cfg *config.Config) *ServiceManager

NewServiceManager creates a new service manager

func (*ServiceManager) Disable

func (sm *ServiceManager) Disable() error

Disable disables the service from starting on boot

func (*ServiceManager) Enable

func (sm *ServiceManager) Enable() error

Enable enables the service to start on boot

func (*ServiceManager) Install

func (sm *ServiceManager) Install() error

Install installs the system service

func (*ServiceManager) Reload

func (sm *ServiceManager) Reload() error

Reload reloads the service configuration (sends SIGHUP)

func (*ServiceManager) Restart

func (sm *ServiceManager) Restart() error

Restart restarts the service

func (*ServiceManager) Start

func (sm *ServiceManager) Start() error

Start starts the service

func (*ServiceManager) Status

func (sm *ServiceManager) Status() (string, error)

Status returns the service status

func (*ServiceManager) Stop

func (sm *ServiceManager) Stop() error

Stop stops the service

func (*ServiceManager) Uninstall

func (sm *ServiceManager) Uninstall() error

Uninstall removes the system service

type SystemUser

type SystemUser struct {
	Name  string
	UID   int
	GID   int
	Home  string
	Shell string
}

SystemUser represents a system service user Per AI.md PART 24: System user creation logic

func CreateSystemUser

func CreateSystemUser(name string) (*SystemUser, error)

CreateSystemUser creates a system user for the service Per AI.md PART 24: System user creation logic

type TorService

type TorService struct {
	// contains filtered or unexported fields
}

TorService manages Tor hidden service using github.com/cretz/bine per AI.md PART 32: TOR HIDDEN SERVICE (NON-NEGOTIABLE) Server binary fully owns and controls the Tor process lifecycle.

func NewTorService

func NewTorService(cfg *config.Config) *TorService

NewTorService creates a new Tor service manager

func (*TorService) ApplyVanityAddress

func (t *TorService) ApplyVanityAddress() (string, error)

ApplyVanityAddress applies a generated vanity address

func (*TorService) CancelVanity

func (t *TorService) CancelVanity()

CancelVanity cancels any running vanity generation

func (*TorService) ExportKeys

func (t *TorService) ExportKeys() ([]byte, error)

ExportKeys exports the current Tor hidden service keys Per AI.md PART 32: Key import/export for external vanity addresses

func (*TorService) GenerateVanity

func (t *TorService) GenerateVanity(prefix string) error

GenerateVanity starts background vanity address generation Per AI.md PART 32: Built-in generation supports max 6 character prefixes

func (*TorService) GetHTTPClient

func (t *TorService) GetHTTPClient(useTor bool) *http.Client

GetHTTPClient returns an HTTP client, optionally routed through Tor Per AI.md PART 32: useTor: true = route through Tor, false = direct

func (*TorService) GetOnionAddress

func (t *TorService) GetOnionAddress() string

GetOnionAddress returns the .onion address

func (*TorService) GetTorStatus

func (t *TorService) GetTorStatus() map[string]interface{}

GetTorStatus returns detailed Tor status information

func (*TorService) GetVanityProgress

func (t *TorService) GetVanityProgress() *VanityProgress

GetVanityProgress returns the current vanity generation progress

func (*TorService) ImportKeys

func (t *TorService) ImportKeys(privateKey []byte) (string, error)

ImportKeys imports external Tor hidden service keys Per AI.md PART 32: Key import/export for external vanity addresses

func (*TorService) IsRunning

func (t *TorService) IsRunning() bool

IsRunning returns whether Tor is running

func (*TorService) OutboundEnabled

func (t *TorService) OutboundEnabled() bool

OutboundEnabled returns true if Tor outbound connections are available

func (*TorService) RegenerateAddress

func (t *TorService) RegenerateAddress() (string, error)

RegenerateAddress creates a new random .onion address

func (*TorService) Restart

func (t *TorService) Restart() error

Restart stops and starts Tor (used for config changes, recovery)

func (*TorService) SetEnabled

func (t *TorService) SetEnabled(enabled bool) error

SetEnabled enables or disables Tor

func (*TorService) Shutdown

func (t *TorService) Shutdown()

Shutdown gracefully shuts down the Tor service

func (*TorService) Start

func (t *TorService) Start() error

Start starts the Tor hidden service using bine Per AI.md PART 32: "Auto-enabled if tor binary is installed - no enable flag needed"

func (*TorService) Stop

func (t *TorService) Stop() error

Stop stops the Tor hidden service

type VanityProgress

type VanityProgress struct {
	Prefix    string
	Attempts  int64
	StartTime time.Time
	Running   bool
	Found     bool
	Address   string
	Error     string
}

VanityProgress represents the progress of vanity address generation Per AI.md PART 32: Vanity address generation (built-in, max 6 chars)

Jump to

Keyboard shortcuts

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