Big refactor
This commit is contained in:
@@ -6,24 +6,35 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/debridmediamanager.com/zurg/internal/config"
|
||||
"github.com/debridmediamanager.com/zurg/internal/net"
|
||||
"github.com/debridmediamanager.com/zurg/internal/torrent"
|
||||
"github.com/debridmediamanager.com/zurg/internal/version"
|
||||
"github.com/debridmediamanager.com/zurg/internal/zfs"
|
||||
"github.com/debridmediamanager.com/zurg/pkg/chunk"
|
||||
"github.com/debridmediamanager.com/zurg/pkg/logutil"
|
||||
"github.com/debridmediamanager.com/zurg/pkg/realdebrid"
|
||||
"github.com/hashicorp/golang-lru/v2/expirable"
|
||||
"github.com/winfsp/cgofuse/fuse"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) > 1 && os.Args[1] == "networktest" {
|
||||
realdebrid.RunTest()
|
||||
return
|
||||
// special commands
|
||||
if len(os.Args) > 1 {
|
||||
switch os.Args[1] {
|
||||
case "version":
|
||||
version.Show()
|
||||
case "networktest":
|
||||
realdebrid.RunTest()
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// normal startup
|
||||
log := logutil.NewLogger().Named("zurg")
|
||||
|
||||
config, configErr := config.LoadZurgConfig("./config.yml")
|
||||
@@ -53,16 +64,26 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
// Start the mount in a goroutine with panic recovery.
|
||||
mountPoint := config.GetMountPoint()
|
||||
if _, err := os.Stat(mountPoint); os.IsNotExist(err) {
|
||||
if err := os.Mkdir(mountPoint, 0755); err != nil {
|
||||
log.Panicf("Failed to create mount point: %v", err)
|
||||
}
|
||||
log.Debugf("Initializing chunk manager, cores: %d", runtime.NumCPU())
|
||||
// 64kb request size
|
||||
chunkMgr, err := chunk.NewManager(
|
||||
"",
|
||||
1048576, // 1MB
|
||||
1, // 1 chunk - load ahead (1MB total)
|
||||
max(runtime.NumCPU()/2, 1), // check threads
|
||||
max(runtime.NumCPU()/2, 1), // load threads
|
||||
runtime.NumCPU()*2,
|
||||
torrentMgr, // max chunks
|
||||
config)
|
||||
if nil != err {
|
||||
log.Panicf("Failed to initialize chunk manager: %v", err)
|
||||
}
|
||||
|
||||
fs := zfs.NewZurgFS(torrentMgr, config, chunkMgr, logutil.NewLogger().Named("zfs"))
|
||||
host := fuse.NewFileSystemHost(fs)
|
||||
go func() {
|
||||
log.Infof("Mounting on %s", mountPoint)
|
||||
if err := zfs.Mount(mountPoint, config, torrentMgr); err != nil {
|
||||
log.Infof("Mounting on %s", config.GetMountPoint())
|
||||
if err := zfs.Mount(host, config); err != nil {
|
||||
log.Panicf("Failed to mount: %v", err)
|
||||
}
|
||||
}()
|
||||
@@ -75,7 +96,7 @@ func main() {
|
||||
if err := server.Shutdown(ctx); err != nil {
|
||||
log.Errorf("Server shutdown error: %v\n", err)
|
||||
}
|
||||
if err := zfs.Unmount(mountPoint); err != nil {
|
||||
if err := zfs.Unmount(host); err != nil {
|
||||
log.Errorf("Unmount error: %v\n", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user