blob: cd5fba3125f9d2ff9cb2e2df45fe032457f12e36 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
// Copyright (C) 2021-2021 The Whirlsplash Collective
// SPDX-License-Identifier: GPL-3.0-only
package utilities
import (
"github.com/Whirlsplash/munch/pkg/discord"
"log"
"os"
"os/signal"
"syscall"
)
func SetupSignalHandler() {
// https://stackoverflow.com/a/18158859/14452787
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
log.Println("SignalHandler: Killing Munch")
log.Println("Cleaning up Discord bot")
discord.CleanupCommands()
discord.CleanupBot()
os.Exit(1)
}()
}
|