From 10269c6f6c7659f7c45bf695f5926b66f4f22691 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Wed, 3 Jul 2019 19:56:47 +0200 Subject: [PATCH] Code clean-up in commands --- internal/commands/commands.go | 27 ++++++++++++++++++++++++++- internal/commands/start.go | 19 +------------------ 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/internal/commands/commands.go b/internal/commands/commands.go index 5e2db716f..d4c9ee14c 100644 --- a/internal/commands/commands.go +++ b/internal/commands/commands.go @@ -7,10 +7,35 @@ https://github.com/photoprism/photoprism/wiki/Commands */ package commands -import "github.com/sirupsen/logrus" +import ( + "os" + "syscall" + + "github.com/photoprism/photoprism/internal/util" + "github.com/sevlyar/go-daemon" + "github.com/sirupsen/logrus" +) var log *logrus.Logger func init() { log = logrus.StandardLogger() } + +func childAlreadyRunning(filePath string) (pid int, running bool) { + if !util.Exists(filePath) { + return pid, false + } + + pid, err := daemon.ReadPidFile(filePath) + if err != nil { + return pid, false + } + + process, err := os.FindProcess(int(pid)) + if err != nil { + return pid, false + } + + return pid, process.Signal(syscall.Signal(0)) == nil +} diff --git a/internal/commands/start.go b/internal/commands/start.go index cd797a3eb..67ef961a1 100644 --- a/internal/commands/start.go +++ b/internal/commands/start.go @@ -73,6 +73,7 @@ func startAction(ctx *cli.Context) error { if err := conf.Init(cctx); err != nil { log.Fatal(err) } + conf.MigrateDb() dctx := new(daemon.Context) @@ -129,21 +130,3 @@ func startAction(ctx *cli.Context) error { return nil } - -func childAlreadyRunning(filePath string) (pid int, running bool) { - if !util.Exists(filePath) { - return pid, false - } - - pid, err := daemon.ReadPidFile(filePath) - if err != nil { - return pid, false - } - - process, err := os.FindProcess(int(pid)) - if err != nil { - return pid, false - } - - return pid, process.Signal(syscall.Signal(0)) == nil -}