mirror of https://github.com/EasyDarwin/EasyDarwin
parent
909ffa0f2b
commit
cde2d9b6fc
|
@ -11,3 +11,4 @@ node_modules
|
|||
/*.dev.ini
|
||||
/*.dev.db
|
||||
.idea
|
||||
easydarwin_debug.ini
|
||||
|
|
|
@ -7,3 +7,6 @@ default_password=admin
|
|||
port=554
|
||||
timeout=28800
|
||||
gop_cache_enable=1
|
||||
save_stream_to_mp4=0
|
||||
ffmpeg_path=
|
||||
mp4_dir_path=
|
50
main.go
50
main.go
|
@ -2,12 +2,15 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-ini/ini"
|
||||
|
||||
"github.com/EasyDarwin/EasyDarwin/models"
|
||||
"github.com/EasyDarwin/EasyDarwin/routers"
|
||||
"github.com/EasyDarwin/EasyDarwin/rtsp"
|
||||
|
@ -128,12 +131,29 @@ func (p *program) Stop(s service.Service) (err error) {
|
|||
}
|
||||
|
||||
func main() {
|
||||
configPath := flag.String("config", "", "configure file path")
|
||||
flag.Parse()
|
||||
tail := flag.Args()
|
||||
log.SetPrefix("[EasyDarwin] ")
|
||||
log.SetFlags(log.LstdFlags)
|
||||
if utils.Debug {
|
||||
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{
|
||||
Name: sec.Key("name").MustString("EasyDarwin_Service"),
|
||||
DisplayName: sec.Key("display_name").MustString("EasyDarwin_Service"),
|
||||
|
@ -147,22 +167,26 @@ func main() {
|
|||
rtspPort: rtspServer.TCPPort,
|
||||
rtspServer: rtspServer,
|
||||
}
|
||||
var s, err = service.New(p, svcConfig)
|
||||
s, err := service.New(p, svcConfig)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
utils.PauseExit()
|
||||
}
|
||||
if len(os.Args) > 1 {
|
||||
if os.Args[1] == "install" || os.Args[1] == "stop" {
|
||||
figure.NewFigure("EasyDarwin", "", false).Print()
|
||||
if len(tail) > 0 {
|
||||
cmd := tail[0]
|
||||
cmd = strings.ToLower(cmd)
|
||||
if cmd == "install" || cmd == "stop" || cmd == "start" || cmd == "uninstall" {
|
||||
if cmd == "install" || cmd == "stop" {
|
||||
figure.NewFigure("EasyDarwin", "", false).Print()
|
||||
}
|
||||
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], "...")
|
||||
if err = service.Control(s, os.Args[1]); err != nil {
|
||||
log.Println(err)
|
||||
utils.PauseExit()
|
||||
}
|
||||
log.Println(svcConfig.Name, os.Args[1], "ok")
|
||||
return
|
||||
}
|
||||
figure.NewFigure("EasyDarwin", "", false).Print()
|
||||
if err = s.Run(); err != nil {
|
||||
|
|
|
@ -24,15 +24,18 @@ type Server struct {
|
|||
removePusherCh chan *Pusher
|
||||
}
|
||||
|
||||
var Instance *Server = &Server{
|
||||
Stoped: true,
|
||||
TCPPort: utils.Conf().Section("rtsp").Key("port").MustInt(554),
|
||||
pushers: make(map[string]*Pusher),
|
||||
addPusherCh: make(chan *Pusher),
|
||||
removePusherCh: make(chan *Pusher),
|
||||
}
|
||||
var Instance *Server = nil
|
||||
|
||||
func GetServer() *Server {
|
||||
if Instance == nil {
|
||||
Instance = &Server{
|
||||
Stoped: true,
|
||||
TCPPort: utils.Conf().Section("rtsp").Key("port").MustInt(554),
|
||||
pushers: make(map[string]*Pusher),
|
||||
addPusherCh: make(chan *Pusher),
|
||||
removePusherCh: make(chan *Pusher),
|
||||
}
|
||||
}
|
||||
return Instance
|
||||
}
|
||||
|
||||
|
|
4
start.sh
4
start.sh
|
@ -1,4 +1,4 @@
|
|||
#!/bin/bash
|
||||
CWD=$(cd "$(dirname $0)";pwd)
|
||||
$CWD/easydarwin install
|
||||
$CWD/easydarwin start
|
||||
"$CWD"/easydarwin install
|
||||
"$CWD"/easydarwin start
|
4
stop.sh
4
stop.sh
|
@ -1,4 +1,4 @@
|
|||
#!/bin/bash
|
||||
CWD=$(cd "$(dirname $0)";pwd)
|
||||
$CWD/easydarwin stop
|
||||
$CWD/easydarwin uninstall
|
||||
"$CWD"/easydarwin stop
|
||||
"$CWD"/easydarwin uninstall
|
|
@ -134,6 +134,18 @@ func Conf() *ini.File {
|
|||
return conf
|
||||
}
|
||||
|
||||
func ConfByPath(path string) (*ini.File, error) {
|
||||
if conf != nil {
|
||||
return conf, nil
|
||||
}
|
||||
if _conf, err := ini.InsensitiveLoad(path); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
conf = _conf
|
||||
}
|
||||
return conf, nil
|
||||
}
|
||||
|
||||
func ReloadConf() *ini.File {
|
||||
if _conf, err := ini.InsensitiveLoad(ConfFile()); err != nil {
|
||||
_conf, _ = ini.LoadSources(ini.LoadOptions{Insensitive: true}, []byte(""))
|
||||
|
|
Loading…
Reference in New Issue