chore: systemd

This commit is contained in:
mzz2017 2023-02-27 14:07:36 +08:00
parent 01162f3d7e
commit 7783498c03
7 changed files with 44 additions and 6 deletions

View File

@ -26,4 +26,5 @@ func init() {
rootCmd.AddCommand(runCmd)
rootCmd.AddCommand(validateCmd)
rootCmd.AddCommand(exportCmd)
rootCmd.AddCommand(reloadCmd)
}

31
cmd/reload.go Normal file
View File

@ -0,0 +1,31 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (c) 2023, v2rayA Organization <team@v2raya.org>
*/
package cmd
import (
"github.com/spf13/cobra"
"os"
"strconv"
"syscall"
)
var (
reloadCmd = &cobra.Command{
Use: "reload pid",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
cmd.Help()
os.Exit(1)
}
pid, err := strconv.Atoi(args[0])
if err != nil {
cmd.Help()
os.Exit(1)
}
syscall.Kill(pid, syscall.SIGUSR1)
},
}
)

View File

@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"github.com/mohae/deepcopy"
"github.com/okzk/sdnotify"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/v2rayA/dae/cmd/internal"
@ -67,6 +68,7 @@ func Run(log *logrus.Logger, conf *config.Config) (err error) {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGKILL, syscall.SIGILL, syscall.SIGUSR1)
go func() {
sdnotify.Ready()
if listener, err = c.ListenAndServe(conf.Global.TproxyPort); err != nil {
log.Errorln("ListenAndServe:", err)
}
@ -80,6 +82,7 @@ loop:
if reloading {
reloading = false
log.Warnln("[Reload] Serve")
sdnotify.Ready()
go func() {
if err := c.Serve(listener); err != nil {
log.Errorln("ListenAndServe:", err)
@ -91,6 +94,7 @@ loop:
}
case syscall.SIGUSR1:
// Reload signal.
sdnotify.Reloading()
log.Warnln("[Reload] Received reload signal; prepare to reload")
obj := c.EjectBpf()
log.Warnln("[Reload] Load new control plane")
@ -99,6 +103,7 @@ loop:
log.WithFields(logrus.Fields{
"err": err,
}).Errorln("failed to reload")
sdnotify.Ready()
continue
}
log.Warnln("[Reload] Stopped old control plane")
@ -155,7 +160,6 @@ func newControlPlane(log *logrus.Logger, bpf interface{}, conf *config.Config) (
if err != nil {
return nil, err
}
// Call GC to release memory.
runtime.GC()

View File

@ -1378,8 +1378,6 @@ new_connection:
goto block;
}
control_plane_tproxy:
// Assign to control plane.
if (l4proto == IPPROTO_TCP) {

1
go.mod
View File

@ -10,6 +10,7 @@ require (
github.com/json-iterator/go v1.1.12
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/mzz2017/softwind v0.0.0-20230224125402-d460ce1c5b4b
github.com/okzk/sdnotify v0.0.0-20180710141335-d9becc38acbd
github.com/safchain/ethtool v0.0.0-20230116090318-67cc41908669
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.6.1

2
go.sum
View File

@ -71,6 +71,8 @@ github.com/mzz2017/softwind v0.0.0-20230224125402-d460ce1c5b4b/go.mod h1:V8GFOtd
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/okzk/sdnotify v0.0.0-20180710141335-d9becc38acbd h1:+iAPaTbi1gZpcpDwe/BW1fx7Xoesv69hLNGPheoyhBs=
github.com/okzk/sdnotify v0.0.0-20180710141335-d9becc38acbd/go.mod h1:4soZNh0zW0LtYGdQ416i0jO0EIqMGcbtaspRS4BDvRQ=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=

View File

@ -5,12 +5,13 @@ After=network-online.target docker.service
Wants=network-online.target
[Service]
Type=simple
Type=notify
User=root
LimitNPROC=500
LimitNOFILE=1000000
LimitNPROC=512
LimitNOFILE=1048576
ExecStartPre=/usr/bin/dae validate -c /etc/dae/config.dae
ExecStart=/usr/bin/dae run --disable-timestamp -c /etc/dae/config.dae
ExecReload=/usr/bin/dae reload $MAINPID
Restart=on-abnormal
[Install]