2020-10-08 18:21:27 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"log"
|
|
|
|
"os"
|
2020-10-22 15:22:36 +02:00
|
|
|
"syscall"
|
|
|
|
"time"
|
2020-10-16 19:12:53 +02:00
|
|
|
|
2021-01-26 23:13:46 +01:00
|
|
|
"github.com/mattermost/focalboard/server/model"
|
|
|
|
"github.com/mattermost/focalboard/server/server"
|
|
|
|
"github.com/mattermost/focalboard/server/services/config"
|
2020-10-08 18:21:27 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------------------
|
|
|
|
// WebSocket OnChange listener
|
|
|
|
|
2020-10-22 13:34:42 +02:00
|
|
|
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-22 15:22:36 +02:00
|
|
|
|
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-22 13:34:42 +02:00
|
|
|
|
2020-10-08 18:21:27 +02:00
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
if !isProcessRunning(pid) {
|
|
|
|
log.Printf("Monitored process not found, exiting.")
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2020-10-22 13:34:42 +02:00
|
|
|
|
|
|
|
time.Sleep(timeBetweenPidMonitoringChecks)
|
2020-10-08 18:21:27 +02:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2021-01-19 23:10:14 +01:00
|
|
|
// Log version
|
|
|
|
log.Println("Version: " + model.CurrentVersion)
|
|
|
|
log.Println("Edition: " + model.Edition)
|
|
|
|
log.Println("Build Number: " + model.BuildNumber)
|
|
|
|
log.Println("Build Date: " + model.BuildDate)
|
|
|
|
log.Println("Build Hash: " + model.BuildHash)
|
|
|
|
|
2020-10-08 18:21:27 +02:00
|
|
|
// config.json file
|
2020-10-16 19:12:53 +02:00
|
|
|
config, err := config.ReadConfigFile()
|
2020-10-09 10:27:20 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Unable to read the config file: ", err)
|
|
|
|
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")
|
2021-02-09 21:27:34 +01:00
|
|
|
pSingleUserToken := flag.String("single-user", "", "single user token")
|
2020-12-04 16:03:09 +01:00
|
|
|
flag.Parse()
|
|
|
|
|
2021-02-09 21:27:34 +01:00
|
|
|
singleUserToken := ""
|
|
|
|
if pSingleUserToken != nil {
|
|
|
|
singleUserToken = *pSingleUserToken
|
2020-12-04 11:28:35 +01:00
|
|
|
}
|
2020-10-08 18:21:27 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-02-09 21:27:34 +01:00
|
|
|
server, err := server.New(config, singleUserToken)
|
2020-10-09 10:08:38 +02:00
|
|
|
if err != nil {
|
2021-01-20 22:52:25 +01:00
|
|
|
log.Fatal("server.New ERROR: ", err)
|
2020-10-09 10:08:38 +02:00
|
|
|
}
|
2020-10-08 18:21:27 +02:00
|
|
|
|
2020-10-16 16:21:42 +02:00
|
|
|
if err := server.Start(); err != nil {
|
2021-01-20 22:52:25 +01:00
|
|
|
log.Fatal("server.Start ERROR: ", err)
|
2020-10-08 18:21:27 +02:00
|
|
|
}
|
|
|
|
}
|