2019-06-20 01:11:03 +02:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
2019-06-30 05:38:39 +02:00
|
|
|
"github.com/sevlyar/go-daemon"
|
2019-06-20 01:11:03 +02:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
2019-06-30 05:38:39 +02:00
|
|
|
// StopCommand stops the daemon if running.
|
2019-06-20 01:11:03 +02:00
|
|
|
var StopCommand = cli.Command{
|
|
|
|
Name: "stop",
|
|
|
|
Usage: "Stops daemon",
|
|
|
|
Action: stopAction,
|
|
|
|
}
|
|
|
|
|
|
|
|
func stopAction(ctx *cli.Context) error {
|
|
|
|
conf := config.NewConfig(ctx)
|
2019-06-30 05:38:39 +02:00
|
|
|
|
|
|
|
log.Infof("looking for pid in \"%s\"", conf.PIDFilename())
|
|
|
|
|
2019-06-20 01:11:03 +02:00
|
|
|
dcxt := new(daemon.Context)
|
2019-06-30 05:38:39 +02:00
|
|
|
dcxt.PidFileName = conf.PIDFilename()
|
2019-06-20 01:11:03 +02:00
|
|
|
child, err := dcxt.Search()
|
2019-06-30 05:38:39 +02:00
|
|
|
|
2019-06-20 01:11:03 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = child.Signal(syscall.SIGTERM)
|
2019-06-30 05:38:39 +02:00
|
|
|
|
2019-06-20 01:11:03 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
st, err := child.Wait()
|
2019-06-30 05:38:39 +02:00
|
|
|
|
2019-06-20 01:11:03 +02:00
|
|
|
if err != nil {
|
2019-06-30 05:38:39 +02:00
|
|
|
log.Info("daemon exited successfully")
|
2019-06-20 01:11:03 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-06-30 05:38:39 +02:00
|
|
|
log.Infof("daemon[%v] exited[%v]? successfully[%v]?\n", st.Pid(), st.Exited(), st.Success())
|
|
|
|
|
2019-06-20 01:11:03 +02:00
|
|
|
return nil
|
|
|
|
}
|