-
Notifications
You must be signed in to change notification settings - Fork 0
/
stop.go
52 lines (43 loc) · 1.09 KB
/
stop.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package cmd
import (
"fmt"
"github.com/lucasnevespereira/lembra/internal/utils/logger"
"github.com/sevlyar/go-daemon"
"github.com/spf13/cobra"
"os"
)
func init() {
rootCmd.AddCommand(stopCmd)
}
var stopCmd = &cobra.Command{
Use: "stop",
Short: "Stops the reminder listener daemon",
Run: stopDaemon,
}
func stopDaemon(cmd *cobra.Command, args []string) {
daemonContext := &daemon.Context{
PidFileName: "lembra.pid",
PidFilePerm: 0644,
LogFileName: "lembra.log",
LogFilePerm: 0640,
WorkDir: "./",
Umask: 027,
}
daemonPid, err := daemonContext.Search()
if err != nil {
logger.Log.Fatalf("failed to search for daemon process: %v", err)
}
err = daemonPid.Signal(os.Interrupt)
if err != nil {
logger.Log.Fatalf("failed to send termination signal to the daemon: %v", err)
}
err = daemonContext.Release()
if err != nil {
logger.Log.Fatalf("failed to release daemon resources: %v", err)
}
err = os.Remove(daemonContext.LogFileName)
if err != nil {
logger.Log.Fatalf("failed to delete lembra process logs: %v", err)
}
fmt.Println("Lembra Daemon stopped")
}