-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
stop.go
54 lines (39 loc) Β· 1006 Bytes
/
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
53
54
package commands
import (
"syscall"
"github.com/sevlyar/go-daemon"
"github.com/urfave/cli"
"github.com/photoprism/photoprism/pkg/clean"
)
// StopCommand configures the command name, flags, and action.
var StopCommand = cli.Command{
Name: "stop",
Aliases: []string{"down"},
Usage: "Stops the Web server in daemon mode",
Action: stopAction,
}
// stopAction stops the daemon if it is running.
func stopAction(ctx *cli.Context) error {
conf, err := InitConfig(ctx)
if err != nil {
return err
}
log.Infof("looking for pid in %s", clean.Log(conf.PIDFilename()))
dcxt := new(daemon.Context)
dcxt.PidFileName = conf.PIDFilename()
child, err := dcxt.Search()
if err != nil {
log.Fatal(err)
}
err = child.Signal(syscall.SIGTERM)
if err != nil {
log.Fatal(err)
}
st, err := child.Wait()
if err != nil {
log.Info("daemon exited successfully")
return nil
}
log.Infof("daemon[%v] exited[%v]? successfully[%v]?\n", st.Pid(), st.Exited(), st.Success())
return nil
}