photoprism/internal/commands/commands.go

40 lines
929 B
Go
Raw Normal View History

/*
Package commands contains commands and flags used by the photoprism application.
2018-11-06 18:02:03 +00:00
Additional information concerning the command-line interface can be found in our Developer Guide:
https://github.com/photoprism/photoprism/wiki/Commands
*/
package commands
2019-07-03 17:56:47 +00:00
import (
"os"
"syscall"
"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/pkg/fs"
2019-07-03 17:56:47 +00:00
"github.com/sevlyar/go-daemon"
)
var log = event.Log
2019-07-03 17:56:47 +00:00
// childAlreadyRunning tests if a .pid file at filePath is a running proccess.
// it returns the pid value and the running status (true or false).
2019-07-03 17:56:47 +00:00
func childAlreadyRunning(filePath string) (pid int, running bool) {
if !fs.FileExists(filePath) {
2019-07-03 17:56:47 +00:00
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
}