defuse
This commit is contained in:
@@ -6,15 +6,12 @@ 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/zfs"
|
||||
"github.com/debridmediamanager.com/zurg/pkg/chunk"
|
||||
"github.com/debridmediamanager.com/zurg/pkg/logutil"
|
||||
"github.com/hashicorp/golang-lru/v2/expirable"
|
||||
)
|
||||
@@ -38,27 +35,6 @@ func main() {
|
||||
addr := fmt.Sprintf(":%s", config.GetPort())
|
||||
server := &http.Server{Addr: addr, Handler: mux}
|
||||
|
||||
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(
|
||||
"",
|
||||
524288, // 512kb
|
||||
1, // 1 chunk - load ahead (1MB total)
|
||||
max(runtime.NumCPU()/2, 1), // check threads
|
||||
max(runtime.NumCPU()/2, 1), // load threads
|
||||
runtime.NumCPU()*2, // max chunks
|
||||
config)
|
||||
if nil != err {
|
||||
log.Panicf("Failed to initialize chunk manager: %v", err)
|
||||
}
|
||||
|
||||
shutdown := make(chan os.Signal, 1)
|
||||
signal.Notify(shutdown, os.Interrupt, syscall.SIGTERM)
|
||||
|
||||
@@ -74,19 +50,6 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
// Start the mount in a goroutine with panic recovery.
|
||||
go func() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.Errorf("Mount panic: %v\n", r)
|
||||
}
|
||||
}()
|
||||
log.Infof("Mounting on %s", mountPoint)
|
||||
if err := zfs.Mount(mountPoint, config, torrentMgr, chunkMgr); err != nil {
|
||||
log.Panicf("Failed to mount: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
<-shutdown
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
@@ -95,9 +58,6 @@ func main() {
|
||||
if err := server.Shutdown(ctx); err != nil {
|
||||
log.Errorf("Server shutdown error: %v\n", err)
|
||||
}
|
||||
if err := zfs.Unmount(mountPoint); err != nil {
|
||||
log.Errorf("Unmount error: %v\n", err)
|
||||
}
|
||||
|
||||
log.Info("BYE")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user