197 lines
4.3 KiB
Plaintext
197 lines
4.3 KiB
Plaintext
"""
|
|
Service management configuration schema.
|
|
|
|
Supports systemd, launchd, runit, OpenRC with unified interface.
|
|
"""
|
|
|
|
schema TypesService:
|
|
InitSystem: "systemd" | "launchd" | "runit" | "openrc"
|
|
RestartPolicy: "always" | "on-failure" | "no"
|
|
|
|
schema ServiceUnit:
|
|
"""Service configuration"""
|
|
|
|
# Service name
|
|
name: str
|
|
|
|
# Service description
|
|
description: str
|
|
|
|
# Executable path
|
|
binary: str
|
|
|
|
# Arguments
|
|
args: [str] = []
|
|
|
|
# Working directory
|
|
working_dir: str = "/opt"
|
|
|
|
# Environment variables
|
|
env: {str: str} = {}
|
|
|
|
# Restart policy
|
|
restart_policy: TypesService.RestartPolicy = "on-failure"
|
|
|
|
# Restart delay in seconds
|
|
restart_delay_secs: int = 5
|
|
|
|
# Maximum restart attempts (-1 = unlimited)
|
|
max_retries: int = 5
|
|
|
|
# User to run as
|
|
user?: str
|
|
|
|
# Group to run as
|
|
group?: str
|
|
|
|
# Standard output target
|
|
stdout?: str
|
|
|
|
# Standard error target
|
|
stderr?: str
|
|
|
|
check:
|
|
len(name) > 0, "name must not be empty"
|
|
len(description) > 0, "description must not be empty"
|
|
len(binary) > 0, "binary must not be empty"
|
|
len(working_dir) > 0, "working_dir must not be empty"
|
|
restart_delay_secs > 0, "restart_delay_secs must be positive"
|
|
max_retries > -2, "max_retries must be >= -1"
|
|
|
|
schema ServiceTemplate:
|
|
"""Service template for code generation"""
|
|
|
|
# Target init system
|
|
init_system: TypesService.InitSystem
|
|
|
|
# Configuration
|
|
config: ServiceUnit
|
|
|
|
# Pre-install hook
|
|
pre_install_hook?: str
|
|
|
|
# Post-install hook
|
|
post_install_hook?: str
|
|
|
|
# Pre-start hook
|
|
pre_start_hook?: str
|
|
|
|
# Post-start hook
|
|
post_start_hook?: str
|
|
|
|
# Pre-stop hook
|
|
pre_stop_hook?: str
|
|
|
|
# Post-stop hook
|
|
post_stop_hook?: str
|
|
|
|
check:
|
|
len(config.name) > 0, "config.name must not be empty"
|
|
|
|
schema ServicePool:
|
|
"""Service pool configuration for managing multiple services"""
|
|
|
|
# Pool name
|
|
name: str
|
|
|
|
# Services in this pool
|
|
services: [ServiceUnit]
|
|
|
|
# Default init system
|
|
init_system: TypesService.InitSystem = "systemd"
|
|
|
|
# Enable service manager
|
|
enable_service_manager: bool = True
|
|
|
|
# Health check interval in seconds
|
|
health_check_interval_secs: int = 30
|
|
|
|
check:
|
|
len(name) > 0, "name must not be empty"
|
|
len(services) > 0, "services must not be empty"
|
|
health_check_interval_secs > 0, "health_check_interval_secs must be positive"
|
|
|
|
schema HealthCheckConfig:
|
|
"""Service health check configuration"""
|
|
|
|
# Check type
|
|
check_type: str = "command" # command, http, tcp
|
|
|
|
# Command to execute (for command type)
|
|
command?: str
|
|
|
|
# HTTP endpoint (for http type)
|
|
http_endpoint?: str
|
|
|
|
# TCP address (for tcp type)
|
|
tcp_address?: str
|
|
|
|
# Check interval in seconds
|
|
interval_secs: int = 30
|
|
|
|
# Timeout in seconds
|
|
timeout_secs: int = 5
|
|
|
|
# Unhealthy threshold
|
|
unhealthy_threshold: int = 3
|
|
|
|
# Healthy threshold
|
|
healthy_threshold: int = 2
|
|
|
|
check:
|
|
interval_secs > 0, "interval_secs must be positive"
|
|
timeout_secs > 0, "timeout_secs must be positive"
|
|
unhealthy_threshold > 0, "unhealthy_threshold must be positive"
|
|
healthy_threshold > 0, "healthy_threshold must be positive"
|
|
|
|
schema ServiceMonitoring:
|
|
"""Service monitoring configuration"""
|
|
|
|
# Enable monitoring
|
|
enabled: bool = True
|
|
|
|
# Health checks
|
|
health_checks: [HealthCheckConfig] = []
|
|
|
|
# Logging configuration
|
|
log_level: str = "info"
|
|
|
|
# Log retention days
|
|
log_retention_days: int = 7
|
|
|
|
# Metrics collection
|
|
collect_metrics: bool = True
|
|
|
|
check:
|
|
log_retention_days > 0, "log_retention_days must be positive"
|
|
|
|
schema ServiceConfig:
|
|
"""Global service configuration"""
|
|
|
|
# Service pools
|
|
pools: [ServicePool]
|
|
|
|
# Monitoring configuration
|
|
monitoring: ServiceMonitoring = {
|
|
enabled = True
|
|
health_checks = []
|
|
log_level = "info"
|
|
log_retention_days = 7
|
|
collect_metrics = True
|
|
}
|
|
|
|
check:
|
|
len(pools) >= 0, "pools must be a valid list"
|
|
|
|
# Global service configuration
|
|
service_config: ServiceConfig = {
|
|
pools = []
|
|
monitoring = {
|
|
enabled = True
|
|
health_checks = []
|
|
log_level = "info"
|
|
log_retention_days = 7
|
|
collect_metrics = True
|
|
}
|
|
}
|