2019-06-20 01:11:03 +02:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
|
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"
|
2021-09-22 19:33:41 +02:00
|
|
|
|
2022-04-15 09:42:07 +02:00
|
|
|
"github.com/photoprism/photoprism/pkg/clean"
|
2019-06-20 01:11:03 +02:00
|
|
|
)
|
|
|
|
|
2021-01-24 17:46:18 +01:00
|
|
|
// StopCommand registers the stop cli command.
|
2019-06-20 01:11:03 +02:00
|
|
|
var StopCommand = cli.Command{
|
2020-01-31 17:29:55 +01:00
|
|
|
Name: "stop",
|
2020-01-31 15:29:06 +01:00
|
|
|
Aliases: []string{"down"},
|
2022-10-19 05:09:09 +02:00
|
|
|
Usage: "Stops the Web server in daemon mode",
|
2020-01-31 17:29:55 +01:00
|
|
|
Action: stopAction,
|
2019-06-20 01:11:03 +02:00
|
|
|
}
|
|
|
|
|
2020-02-18 23:42:51 +01:00
|
|
|
// stopAction stops the daemon if it is running.
|
2019-06-20 01:11:03 +02:00
|
|
|
func stopAction(ctx *cli.Context) error {
|
2022-10-04 12:27:40 +02:00
|
|
|
conf, err := InitConfig(ctx)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-06-30 05:38:39 +02:00
|
|
|
|
2022-04-15 09:42:07 +02:00
|
|
|
log.Infof("looking for pid in %s", clean.Log(conf.PIDFilename()))
|
2019-06-30 05:38:39 +02:00
|
|
|
|
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
|
|
|
|
}
|