Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/crawshaw/littleboss
littleboss: supervisor construction kit
https://github.com/crawshaw/littleboss
golang supervisor
Last synced: about 11 hours ago
JSON representation
littleboss: supervisor construction kit
- Host: GitHub
- URL: https://github.com/crawshaw/littleboss
- Owner: crawshaw
- License: isc
- Created: 2018-05-14T14:01:52.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-17T18:56:09.000Z (almost 6 years ago)
- Last Synced: 2025-01-04T04:09:57.957Z (7 days ago)
- Topics: golang, supervisor
- Language: Go
- Homepage:
- Size: 67.4 KB
- Stars: 639
- Watchers: 16
- Forks: 17
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - littleboss - littleboss: supervisor construction kit (Go)
README
# littleboss: self-supervising Go binaries
A Go package, littleboss lets you turn your program into a
a self-supervising binary.
It starts itself as a child process, monitors its life cycle,
reloads it if it exits, and can be instructed to replace it with
a new binary.The supervisor can open sockets for you and share them across
reloads of your program, ensuring no connections are dropped.You can install it with:
```
go get crawshaw.io/littleboss
```Make a program use littleboss by modifying the main function:
```go
func main() {
lb := littleboss.New("service-name")
lb.Run(func(ctx context.Context) {
// main goes here, exit when <-ctx.Done()
})
}
```The service name is used to identify which program the supervisor will control.
## Usage
By default the supervisor is bypassed and the program executes directly.
A flag, -littleboss, is added to the binary.
It can be used to start a supervised binary and manage it:```
$ mybin & # binary runs directly, no child process
$ mybin -littleboss=start & # supervisor is created
$ mybin2 -littleboss=reload # child is replaced by new mybin2 process
$ mybin -littleboss=stop # supervisor and child are shut down
```## Configuration
Supervisor options are baked into the binary.
The littleboss struct type contains fields that can be set before calling
the Run method to configure the supervisor.
Options include reloading the previous binary if a reload fails,
controlling how long an exiting program has to turn down its connections,
and specifying exactly what flags control and are passed by littleboss.## An HTTP server example
```go
func main() {
lb := littleboss.New("myblog")
flagHTTPS := lb.Listener("https", "tcp", ":443", "address")
lb.Run(func(ctx context.Context) {
httpMain(ctx, flagHTTPS.Listener())
})
}func httpMain(ctx context.Context, ln net.Listener) {
srv := &http.Server{
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 60 * time.Second,
Handler: blogHandler,
}
go func() {
if err := srv.ServeTLS(ln, "certfile", "keyfile"); err != nil {
if err == http.ErrServerClosed {
return
}
log.Fatal(err)
}
}()<-ctx.Done()
srv.Shutdown(ctx)
}
```