photoprism/internal/commands/stop.go
Michael Mayer 92e6c4fe1e Download: Add Disabled, Originals, MediaRaw & MediaSidecar Flags #2234
Extends DownloadSettings with 4 additional options:
- Name: File name pattern for downloaded files (existed)
- Disabled: Disables downloads
- Originals: Only download files stored in "originals" folder
- MediaRaw: Include RAW image files
- MediaSidecar: Include metadata sidecar files (JSON, XMP, YAML)
2022-04-15 09:42:07 +02:00

51 lines
1,009 B
Go

package commands
import (
"syscall"
"github.com/sevlyar/go-daemon"
"github.com/urfave/cli"
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/pkg/clean"
)
// StopCommand registers the stop cli command.
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 := config.NewConfig(ctx)
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
}