add shutdown

This commit is contained in:
YouROK
2020-11-19 10:26:29 +03:00
parent 469c145938
commit c9b2e0938d
5 changed files with 73 additions and 41 deletions

View File

@@ -14,11 +14,11 @@ import (
)
type args struct {
Port string `arg:"-p" help:"web server port"`
Path string `arg:"-d" help:"database path"`
Add string `arg:"-a" help:"add torrent link and exit"`
RDB bool `arg:"-r" help:"start in read-only DB mode"`
Kill bool `arg:"-k" help:"dont kill program on signal"`
Port string `arg:"-p" help:"web server port"`
Path string `arg:"-d" help:"database path"`
Add string `arg:"-a" help:"add torrent link and exit"`
RDB bool `arg:"-r" help:"start in read-only DB mode"`
DontKill bool `arg:"-k" help:"dont kill program on signal"`
}
func (args) Version() string {
@@ -42,7 +42,7 @@ func main() {
add()
}
Preconfig(params.Kill)
Preconfig(params.DontKill)
server.Start(params.Path, params.Port, params.RDB)
fmt.Println(server.WaitServer())

View File

@@ -3,47 +3,47 @@
package main
import (
"context"
"fmt"
"net"
"os"
"os/signal"
"syscall"
)
func Preconfig(kill bool) {
sigc := make(chan os.Signal, 1)
signal.Notify(sigc,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGSTOP,
syscall.SIGPIPE,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
for s := range sigc {
if kill {
fmt.Println("Signal catched:", s)
fmt.Println("For stop server, close in web")
func Preconfig(dkill bool) {
if dkill {
sigc := make(chan os.Signal, 1)
signal.Notify(sigc,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGSTOP,
syscall.SIGPIPE,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
for s := range sigc {
if dkill {
fmt.Println("Signal catched:", s)
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)
// }
}