mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
add shutdown
This commit is contained in:
@@ -18,7 +18,7 @@ type args struct {
|
|||||||
Path string `arg:"-d" help:"database path"`
|
Path string `arg:"-d" help:"database path"`
|
||||||
Add string `arg:"-a" help:"add torrent link and exit"`
|
Add string `arg:"-a" help:"add torrent link and exit"`
|
||||||
RDB bool `arg:"-r" help:"start in read-only DB mode"`
|
RDB bool `arg:"-r" help:"start in read-only DB mode"`
|
||||||
Kill bool `arg:"-k" help:"dont kill program on signal"`
|
DontKill bool `arg:"-k" help:"dont kill program on signal"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (args) Version() string {
|
func (args) Version() string {
|
||||||
@@ -42,7 +42,7 @@ func main() {
|
|||||||
add()
|
add()
|
||||||
}
|
}
|
||||||
|
|
||||||
Preconfig(params.Kill)
|
Preconfig(params.DontKill)
|
||||||
|
|
||||||
server.Start(params.Path, params.Port, params.RDB)
|
server.Start(params.Path, params.Port, params.RDB)
|
||||||
fmt.Println(server.WaitServer())
|
fmt.Println(server.WaitServer())
|
||||||
|
|||||||
@@ -3,15 +3,14 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Preconfig(kill bool) {
|
func Preconfig(dkill bool) {
|
||||||
|
if dkill {
|
||||||
sigc := make(chan os.Signal, 1)
|
sigc := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigc,
|
signal.Notify(sigc,
|
||||||
syscall.SIGHUP,
|
syscall.SIGHUP,
|
||||||
@@ -22,28 +21,29 @@ func Preconfig(kill bool) {
|
|||||||
syscall.SIGQUIT)
|
syscall.SIGQUIT)
|
||||||
go func() {
|
go func() {
|
||||||
for s := range sigc {
|
for s := range sigc {
|
||||||
if kill {
|
if dkill {
|
||||||
fmt.Println("Signal catched:", s)
|
fmt.Println("Signal catched:", s)
|
||||||
fmt.Println("For stop server, close in web")
|
fmt.Println("For stop server, close in api")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
//dns resover
|
|
||||||
addrs, err := net.LookupHost("www.themoviedb.org")
|
|
||||||
if len(addrs) == 0 {
|
|
||||||
fmt.Println("Check dns", addrs, err)
|
|
||||||
|
|
||||||
fn := func(ctx context.Context, network, address string) (net.Conn, error) {
|
|
||||||
d := net.Dialer{}
|
|
||||||
return d.DialContext(ctx, "udp", "1.1.1.1:53")
|
|
||||||
}
|
|
||||||
|
|
||||||
net.DefaultResolver = &net.Resolver{
|
|
||||||
Dial: fn,
|
|
||||||
}
|
|
||||||
|
|
||||||
addrs, err = net.LookupHost("www.themoviedb.org")
|
|
||||||
fmt.Println("Check new dns", addrs, err)
|
|
||||||
}
|
}
|
||||||
|
//
|
||||||
|
// //dns resover
|
||||||
|
// addrs, err := net.LookupHost("www.themoviedb.org")
|
||||||
|
// if len(addrs) == 0 {
|
||||||
|
// fmt.Println("Check dns", addrs, err)
|
||||||
|
//
|
||||||
|
// fn := func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||||
|
// d := net.Dialer{}
|
||||||
|
// return d.DialContext(ctx, "udp", "1.1.1.1:53")
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// net.DefaultResolver = &net.Resolver{
|
||||||
|
// Dial: fn,
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// addrs, err = net.LookupHost("www.themoviedb.org")
|
||||||
|
// fmt.Println("Check new dns", addrs, err)
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,3 +14,10 @@ func InitSets(path string, readOnly bool) {
|
|||||||
func CloseDB() {
|
func CloseDB() {
|
||||||
tdb.CloseDB()
|
tdb.CloseDB()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsReadOnly() bool {
|
||||||
|
if tdb == nil || tdb.ReadOnly {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package torr
|
package torr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"server/log"
|
"server/log"
|
||||||
@@ -104,3 +105,9 @@ func SetSettings(set *sets.BTSets) {
|
|||||||
sets.SetBTSets(set)
|
sets.SetBTSets(set)
|
||||||
bts.Connect()
|
bts.Connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Shutdown() {
|
||||||
|
bts.Disconnect()
|
||||||
|
sets.CloseDB()
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
sets "server/settings"
|
||||||
|
"server/torr"
|
||||||
"server/version"
|
"server/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -11,6 +16,7 @@ type requestI struct {
|
|||||||
|
|
||||||
func SetupRoute(route *gin.Engine) {
|
func SetupRoute(route *gin.Engine) {
|
||||||
route.GET("/echo", echo)
|
route.GET("/echo", echo)
|
||||||
|
route.GET("/shutdown", shutdown)
|
||||||
|
|
||||||
route.POST("/settings", settings)
|
route.POST("/settings", settings)
|
||||||
|
|
||||||
@@ -29,3 +35,15 @@ func SetupRoute(route *gin.Engine) {
|
|||||||
func echo(c *gin.Context) {
|
func echo(c *gin.Context) {
|
||||||
c.String(200, "%v", version.Version)
|
c.String(200, "%v", version.Version)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func shutdown(c *gin.Context) {
|
||||||
|
if sets.IsReadOnly() {
|
||||||
|
c.Status(http.StatusForbidden)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Status(200)
|
||||||
|
go func() {
|
||||||
|
time.Sleep(1000)
|
||||||
|
torr.Shutdown()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user