2019-06-20 01:11:03 +02:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
2020-05-03 18:00:50 +02:00
|
|
|
"github.com/photoprism/photoprism/pkg/txt"
|
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-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"},
|
2020-01-31 17:29:55 +01:00
|
|
|
Usage: "Stops web server (only in daemon mode)",
|
|
|
|
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 {
|
|
|
|
conf := config.NewConfig(ctx)
|
2019-06-30 05:38:39 +02:00
|
|
|
|
2020-05-03 18:00:50 +02:00
|
|
|
log.Infof("looking for pid in %s", txt.Quote(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
|
|
|
|
}
|