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