func (s *sig) ResetCleanups() {
	s.cleanups = nil
}
ResetCleanups empties cleanup functions.
package sig
import (
	"fmt"
	"os"
	"os/signal"
	"sync/atomic"
	"syscall"
	"github.com/awnumar/memguard"
	bolt "go.etcd.io/bbolt"
)
var Signal = sig{}
type sig struct {
	interrupt chan os.Signal
	cleanups []func() error
	keepAlive int32
}
func (s *sig) AddCleanup(f func() error) {
	s.cleanups = append(s.cleanups, f)
}
func (s *sig) Interrupt() {
	atomic.StoreInt32(&s.keepAlive, 1)
	s.interrupt <- os.Interrupt
}
func (s *sig) KeepAlive() {
	atomic.StoreInt32(&s.keepAlive, 1)
}
func (s *sig) Kill() {
	atomic.StoreInt32(&s.keepAlive, 0)
	s.interrupt <- os.Kill
	block := make(chan struct{})
	<-block
}
func (s *sig) Listen(db *bolt.DB) {
	s.interrupt = make(chan os.Signal, 1)
	signal.Notify(s.interrupt, os.Interrupt, syscall.SIGHUP, syscall.SIGTERM)
	go func() {
		<-s.interrupt
		for _, f := range s.cleanups {
			if err := f(); err != nil {
				fmt.Fprintln(os.Stderr, "error:", err)
			}
		}
		if atomic.LoadInt32(&s.keepAlive) == 1 {
			atomic.StoreInt32(&s.keepAlive, 0)
			s.Listen(db)
			return
		}
		db.Close()
		fmt.Println("\nExiting...")
		memguard.SafeExit(0)
	}()
}