mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 05:04:03 +03:00
Setup rlimits for application
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
@@ -15,6 +16,7 @@ import (
|
|||||||
|
|
||||||
"github.com/9seconds/mtg/config"
|
"github.com/9seconds/mtg/config"
|
||||||
"github.com/9seconds/mtg/proxy"
|
"github.com/9seconds/mtg/proxy"
|
||||||
|
"github.com/juju/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -81,12 +83,20 @@ var (
|
|||||||
secret = app.Arg("secret", "Secret of this proxy.").Required().String()
|
secret = app.Arg("secret", "Secret of this proxy.").Required().String()
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func init() {
|
||||||
rand.Seed(time.Now().UTC().UnixNano())
|
rand.Seed(time.Now().UTC().UnixNano())
|
||||||
|
|
||||||
app.Version(version)
|
app.Version(version)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
kingpin.MustParse(app.Parse(os.Args[1:]))
|
kingpin.MustParse(app.Parse(os.Args[1:]))
|
||||||
|
|
||||||
|
err := setRLimit()
|
||||||
|
if err != nil {
|
||||||
|
usage(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
conf, err := config.NewConfig(*debug, *verbose,
|
conf, err := config.NewConfig(*debug, *verbose,
|
||||||
*bindIP, *bindPort,
|
*bindIP, *bindPort,
|
||||||
*publicIPv4, *publicIPv4Port,
|
*publicIPv4, *publicIPv4Port,
|
||||||
@@ -125,6 +135,23 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setRLimit() (err error) {
|
||||||
|
rLimit := syscall.Rlimit{}
|
||||||
|
err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
||||||
|
if err != nil {
|
||||||
|
err = errors.Annotate(err, "Cannot get rlimit")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rLimit.Cur = rLimit.Max
|
||||||
|
|
||||||
|
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
||||||
|
if err != nil {
|
||||||
|
err = errors.Annotate(err, "Cannot set rlimit")
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func printURLs(data interface{}) {
|
func printURLs(data interface{}) {
|
||||||
encoder := json.NewEncoder(os.Stdout)
|
encoder := json.NewEncoder(os.Stdout)
|
||||||
encoder.SetEscapeHTML(false)
|
encoder.SetEscapeHTML(false)
|
||||||
|
|||||||
Reference in New Issue
Block a user