mirror of https://github.com/mindoc-org/mindoc.git
添加对 mindoc-daemon 的支持
parent
f7bc9bdb70
commit
91f3e897bf
|
@ -94,6 +94,9 @@ go build -v -o mindoc_linux_musl_amd64 -ldflags="-linkmode external -extldflags
|
||||||
./mindoc_linux_musl_amd64 version
|
./mindoc_linux_musl_amd64 version
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Windows 上后台运行
|
||||||
|
使用 [mindoc-daemon](https://github.com/mindoc-org/mindoc-daemon)
|
||||||
|
|
||||||
|
|
||||||
```ini
|
```ini
|
||||||
#邮件配置-示例
|
#邮件配置-示例
|
||||||
|
|
24
main.go
24
main.go
|
@ -2,8 +2,12 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
_ "github.com/beego/beego/v2/server/web/session/memcache"
|
_ "github.com/beego/beego/v2/server/web/session/memcache"
|
||||||
_ "github.com/beego/beego/v2/server/web/session/mysql"
|
_ "github.com/beego/beego/v2/server/web/session/mysql"
|
||||||
|
@ -15,6 +19,21 @@ import (
|
||||||
_ "github.com/mindoc-org/mindoc/routers"
|
_ "github.com/mindoc-org/mindoc/routers"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func isViaDaemonUnix() bool {
|
||||||
|
parentPid := os.Getppid()
|
||||||
|
|
||||||
|
cmdLineBytes, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/cmdline", parentPid))
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
cmdLine := string(cmdLineBytes)
|
||||||
|
executable := strings.Split(cmdLine, " ")[0]
|
||||||
|
fmt.Printf("Parent executable: %s\n", executable)
|
||||||
|
filename := filepath.Base(executable)
|
||||||
|
return strings.Contains(filename, "mindoc-daemon")
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
if len(os.Args) >= 3 && os.Args[1] == "service" {
|
if len(os.Args) >= 3 && os.Args[1] == "service" {
|
||||||
|
@ -30,6 +49,7 @@ func main() {
|
||||||
|
|
||||||
d := daemon.NewDaemon()
|
d := daemon.NewDaemon()
|
||||||
|
|
||||||
|
if runtime.GOOS != "windows" && !isViaDaemonUnix() {
|
||||||
s, err := service.New(d, d.Config())
|
s, err := service.New(d, d.Config())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -40,4 +60,8 @@ func main() {
|
||||||
if err := s.Run(); err != nil {
|
if err := s.Run(); err != nil {
|
||||||
log.Fatal("启动程序失败 ->", err)
|
log.Fatal("启动程序失败 ->", err)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
d.Run()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue