|
|
@ -2,12 +2,15 @@ package main
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/go-ini/ini"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/EasyDarwin/EasyDarwin/models"
|
|
|
|
"github.com/EasyDarwin/EasyDarwin/models"
|
|
|
|
"github.com/EasyDarwin/EasyDarwin/routers"
|
|
|
|
"github.com/EasyDarwin/EasyDarwin/routers"
|
|
|
|
"github.com/EasyDarwin/EasyDarwin/rtsp"
|
|
|
|
"github.com/EasyDarwin/EasyDarwin/rtsp"
|
|
|
@ -128,12 +131,29 @@ func (p *program) Stop(s service.Service) (err error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
configPath := flag.String("config", "", "configure file path")
|
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
tail := flag.Args()
|
|
|
|
log.SetPrefix("[EasyDarwin] ")
|
|
|
|
log.SetPrefix("[EasyDarwin] ")
|
|
|
|
log.SetFlags(log.LstdFlags)
|
|
|
|
log.SetFlags(log.LstdFlags)
|
|
|
|
if utils.Debug {
|
|
|
|
if utils.Debug {
|
|
|
|
log.SetFlags(log.Lshortfile | log.LstdFlags)
|
|
|
|
log.SetFlags(log.Lshortfile | log.LstdFlags)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sec := utils.Conf().Section("service")
|
|
|
|
var conf *ini.File
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
if len(*configPath) != 0 {
|
|
|
|
|
|
|
|
log.Printf("use config file[%s]", *configPath)
|
|
|
|
|
|
|
|
conf, err = utils.ConfByPath(*configPath)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
conf = utils.Conf()
|
|
|
|
|
|
|
|
err = nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Print(err)
|
|
|
|
|
|
|
|
log.Printf("EasyDarwin terminate due to config not found.")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sec := conf.Section("service")
|
|
|
|
svcConfig := &service.Config{
|
|
|
|
svcConfig := &service.Config{
|
|
|
|
Name: sec.Key("name").MustString("EasyDarwin_Service"),
|
|
|
|
Name: sec.Key("name").MustString("EasyDarwin_Service"),
|
|
|
|
DisplayName: sec.Key("display_name").MustString("EasyDarwin_Service"),
|
|
|
|
DisplayName: sec.Key("display_name").MustString("EasyDarwin_Service"),
|
|
|
@ -147,22 +167,26 @@ func main() {
|
|
|
|
rtspPort: rtspServer.TCPPort,
|
|
|
|
rtspPort: rtspServer.TCPPort,
|
|
|
|
rtspServer: rtspServer,
|
|
|
|
rtspServer: rtspServer,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var s, err = service.New(p, svcConfig)
|
|
|
|
s, err := service.New(p, svcConfig)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
log.Println(err)
|
|
|
|
utils.PauseExit()
|
|
|
|
utils.PauseExit()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(os.Args) > 1 {
|
|
|
|
if len(tail) > 0 {
|
|
|
|
if os.Args[1] == "install" || os.Args[1] == "stop" {
|
|
|
|
cmd := tail[0]
|
|
|
|
figure.NewFigure("EasyDarwin", "", false).Print()
|
|
|
|
cmd = strings.ToLower(cmd)
|
|
|
|
}
|
|
|
|
if cmd == "install" || cmd == "stop" || cmd == "start" || cmd == "uninstall" {
|
|
|
|
log.Println(svcConfig.Name, os.Args[1], "...")
|
|
|
|
if cmd == "install" || cmd == "stop" {
|
|
|
|
if err = service.Control(s, os.Args[1]); err != nil {
|
|
|
|
figure.NewFigure("EasyDarwin", "", false).Print()
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
utils.PauseExit()
|
|
|
|
log.Println(svcConfig.Name, cmd, "...")
|
|
|
|
|
|
|
|
if err = service.Control(s, cmd); err != nil {
|
|
|
|
|
|
|
|
log.Println(err)
|
|
|
|
|
|
|
|
utils.PauseExit()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Println(svcConfig.Name, cmd, "ok")
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Println(svcConfig.Name, os.Args[1], "ok")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
figure.NewFigure("EasyDarwin", "", false).Print()
|
|
|
|
figure.NewFigure("EasyDarwin", "", false).Print()
|
|
|
|
if err = s.Run(); err != nil {
|
|
|
|
if err = s.Run(); err != nil {
|
|
|
|