73f77f1624
This makes systemd not put unit into fail mode when stopping INFO: * make sure to use signals.RegisterCloser for everything that should be closed on interrupt * for any net.Listeners created make sure to wrap them with network.WrapListener and register with signals.RegisterCloser
26 lignes
389 o
Go
26 lignes
389 o
Go
package signals
|
|
|
|
import (
|
|
"io"
|
|
"sync"
|
|
)
|
|
|
|
var (
|
|
closeAccess sync.Mutex
|
|
closers []io.Closer
|
|
)
|
|
|
|
// RegisterCloser adds an io.Closer to close on interrupt
|
|
func RegisterCloser(c io.Closer) {
|
|
closeAccess.Lock()
|
|
closers = append(closers, c)
|
|
closeAccess.Unlock()
|
|
}
|
|
|
|
func closeClosers() {
|
|
closeAccess.Lock()
|
|
for idx := range closers {
|
|
closers[idx].Close()
|
|
}
|
|
closeAccess.Unlock()
|
|
}
|