
kratos-supervisordrun
Go package to generate supervisord configuration with Kratos microservices integration.
CHINESE README
δΈζθ―΄ζ
Main Features
π― Fluent Configuration API: Chain methods to build supervisord config
β‘ Kratos Integration: Optimized configuration patterns to run Kratos microservices
π Group Management: Multi-program groups with centralized configuration
π Tested Configuration: Battle-tested templates that run high-performance services
π Strong Typing: Typed configuration with sensible defaults
Installation
go get github.com/yylego/kratos-supervisordrun/supervisordrunkratos
Usage
Single Program Configuration
package main
import (
"fmt"
"github.com/yylego/kratos-supervisordrun/supervisordrunkratos"
)
func main() {
// Create program config with required parameters
program := supervisordrunkratos.NewProgramConfig(
"myapp", // Program name
"/opt/myapp", // Program root DIR
"deploy", // User name
"/var/log/myapp", // Log DIR
).WithStartRetries(10).
WithEnvironment(map[string]string{
"APP_ENV": "production",
})
// Generate configuration
config := supervisordrunkratos.GenerateProgramConfig(program)
fmt.Println(config)
}
Group Configuration
// Create multiple programs
apiServer := supervisordrunkratos.NewProgramConfig(
"api-server", "/opt/api-server", "deploy", "/var/log/services",
).WithStartRetries(3)
worker := supervisordrunkratos.NewProgramConfig(
"worker", "/opt/worker", "deploy", "/var/log/services",
).WithAutoStart(false)
// Create group
group := supervisordrunkratos.NewGroupConfig("microservices").
AddProgram(apiServer).
AddProgram(worker)
config := supervisordrunkratos.GenerateGroupConfig(group)
Advanced Configuration
// High-performance service configuration
program := supervisordrunkratos.NewProgramConfig(
"high-perf", "/opt/high-perf", "performance", "/var/log/perf",
).WithStartRetries(100).
WithStopWaitSecs(60).
WithLogMaxBytes("500MB").
WithLogBackups(50).
WithPriority(1)
Multi-Instance Deployment
// Multi-instance web server
program := supervisordrunkratos.NewProgramConfig(
"web-server", "/opt/web-server", "deploy", "/var/log/cluster",
).WithNumProcs(3).
WithProcessName("%(program_name)s_%(process_num)02d").
WithEnvironment(map[string]string{
"PORT_BASE": "8080",
})
Configuration Options
Process Settings
WithAutoStart(bool) - Auto start on supervisord startup
WithAutoRestart(bool) - Auto restart on crash
WithAutoRestartMode(string) - Auto restart mode ("false"/"true"/"unexpected")
WithStartRetries(int) - Max start attempts count
WithStartSecs(int) - Wait time in seconds before start succeeds
Logging
WithLogMaxBytes(string) - Max log file size (e.g., "50MB", "1GB")
WithLogBackups(int) - Log backup files count
WithRedirectStderr(bool) - Redirect stderr to stdout
Process Execution
WithStopWaitSecs(int) - Clean stop timeout seconds
WithStopSignal(string) - Stop command name (TERM, INT, QUIT)
WithKillAsGroup(bool) - Terminate child processes as group
WithPriority(int) - Start rank (low ranks start first)
Multi-Instance
WithNumProcs(int) - Count of process instances
WithProcessName(string) - Process name template
Environment
WithEnvironment(map[string]string) - Environment setting
WithExitCodes([]int) - Expected exit codes
Recommended Workflow
# 1. Generate config file
go run main.go > /etc/supervisord/conf.d/myapp.conf
# 2. Reload supervisord
sudo supervisorctl reread
sudo supervisorctl update
# 3. Manage services
sudo supervisorctl start myapp
sudo supervisorctl status
π License
MIT License - see LICENSE.
Contributions are welcome! Report bugs, suggest features, and contribute code:
- π Mistake reports? Open an issue on GitHub with reproduction steps
- π‘ Fresh ideas? Create an issue to discuss
- π Documentation confusing? Report it so we can improve
- π Need new features? Share the use cases to help us understand requirements
- β‘ Performance issue? Help us optimize through reporting slow operations
- π§ Configuration problem? Ask questions about complex setups
- π’ Follow project progress? Watch the repo to get new releases and features
- π Success stories? Share how this package improved the workflow
- π¬ Feedback? We welcome suggestions and comments
π§ Development
New code contributions, follow this process:
- Fork: Fork the repo on GitHub (using the webpage UI).
- Clone: Clone the forked project (
git clone https://github.com/yourname/kratos-supervisordrun.git).
- Navigate: Navigate to the cloned project (
cd kratos-supervisordrun)
- Branch: Create a feature branch (
git checkout -b feature/xxx).
- Code: Implement the changes with comprehensive tests
- Testing: (Golang project) Ensure tests pass (
go test ./...) and follow Go code style conventions
- Documentation: Update documentation to support client-facing changes
- Stage: Stage changes (
git add .)
- Commit: Commit changes (
git commit -m "Add feature xxx") ensuring backward compatible code
- Push: Push to the branch (
git push origin feature/xxx).
- PR: Open a merge request on GitHub (on the GitHub webpage) with detailed description.
Please ensure tests pass and include relevant documentation updates.
π Support
Welcome to contribute to this project via submitting merge requests and reporting issues.
Project Support:
- β Give GitHub stars if this project helps you
- π€ Share with teammates and (golang) programming friends
- π Write tech blogs about development tools and workflows - we provide content writing support
- π Join the ecosystem - committed to supporting open source and the (golang) development scene
Have Fun Coding with this package! πππ
GitHub Stars
