1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-12-21 13:38:56 +02:00
focalboard/server/main/main.go

80 lines
1.5 KiB
Go
Raw Normal View History

2020-10-08 18:21:27 +02:00
package main
import (
"flag"
"log"
"os"
"syscall"
"time"
"github.com/mattermost/mattermost-octo-tasks/server/server"
"github.com/mattermost/mattermost-octo-tasks/server/services/config"
2020-10-08 18:21:27 +02:00
)
// ----------------------------------------------------------------------------------------------------
// WebSocket OnChange listener
const (
timeBetweenPidMonitoringChecks = 2 * time.Second
)
2020-10-08 18:21:27 +02:00
func isProcessRunning(pid int) bool {
process, err := os.FindProcess(pid)
if err != nil {
return false
}
err = process.Signal(syscall.Signal(0))
2020-10-18 02:07:35 +02:00
return err == nil
2020-10-08 18:21:27 +02:00
}
func monitorPid(pid int) {
log.Printf("Monitoring PID: %d", pid)
2020-10-08 18:21:27 +02:00
go func() {
for {
if !isProcessRunning(pid) {
log.Printf("Monitored process not found, exiting.")
os.Exit(1)
}
time.Sleep(timeBetweenPidMonitoringChecks)
2020-10-08 18:21:27 +02:00
}
}()
}
func main() {
// config.json file
config, err := config.ReadConfigFile()
2020-10-09 10:27:20 +02:00
if err != nil {
log.Fatal("Unable to read the config file: ", err)
2020-10-09 10:27:20 +02:00
return
}
2020-10-08 18:21:27 +02:00
// Command line args
pMonitorPid := flag.Int("monitorpid", -1, "a process ID")
pPort := flag.Int("port", config.Port, "the port number")
flag.Parse()
if pMonitorPid != nil && *pMonitorPid > 0 {
monitorPid(*pMonitorPid)
}
if pPort != nil && *pPort > 0 && *pPort != config.Port {
// Override port
log.Printf("Port from commandline: %d", *pPort)
config.Port = *pPort
}
server, err := server.New(config)
if err != nil {
2020-10-16 16:21:42 +02:00
log.Fatal("ListenAndServeTLS: ", err)
}
2020-10-08 18:21:27 +02:00
2020-10-16 16:21:42 +02:00
if err := server.Start(); err != nil {
2020-10-16 11:41:56 +02:00
log.Fatal("ListenAndServeTLS: ", err)
2020-10-08 18:21:27 +02:00
}
}