Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alist-org
GitHub Repository: alist-org/alist
Path: blob/main/cmd/kill.go
1541 views
1
package cmd
2
3
import (
4
log "github.com/sirupsen/logrus"
5
"github.com/spf13/cobra"
6
"os"
7
)
8
9
// KillCmd represents the kill command
10
var KillCmd = &cobra.Command{
11
Use: "kill",
12
Short: "Force kill alist server process by daemon/pid file",
13
Run: func(cmd *cobra.Command, args []string) {
14
kill()
15
},
16
}
17
18
func kill() {
19
initDaemon()
20
if pid == -1 {
21
log.Info("Seems not have been started. Try use `alist start` to start server.")
22
return
23
}
24
process, err := os.FindProcess(pid)
25
if err != nil {
26
log.Errorf("failed to find process by pid: %d, reason: %v", pid, process)
27
return
28
}
29
err = process.Kill()
30
if err != nil {
31
log.Errorf("failed to kill process %d: %v", pid, err)
32
} else {
33
log.Info("killed process: ", pid)
34
}
35
err = os.Remove(pidFile)
36
if err != nil {
37
log.Errorf("failed to remove pid file")
38
}
39
pid = -1
40
}
41
42
func init() {
43
RootCmd.AddCommand(KillCmd)
44
45
// Here you will define your flags and configuration settings.
46
47
// Cobra supports Persistent Flags which will work for this command
48
// and all subcommands, e.g.:
49
// stopCmd.PersistentFlags().String("foo", "", "A help for foo")
50
51
// Cobra supports local flags which will only run when this command
52
// is called directly, e.g.:
53
// stopCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
54
}
55
56