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