mirror of
https://github.com/daeuniverse/dae.git
synced 2025-01-19 00:38:18 +07:00
chore: systemd
This commit is contained in:
parent
01162f3d7e
commit
7783498c03
@ -26,4 +26,5 @@ func init() {
|
|||||||
rootCmd.AddCommand(runCmd)
|
rootCmd.AddCommand(runCmd)
|
||||||
rootCmd.AddCommand(validateCmd)
|
rootCmd.AddCommand(validateCmd)
|
||||||
rootCmd.AddCommand(exportCmd)
|
rootCmd.AddCommand(exportCmd)
|
||||||
|
rootCmd.AddCommand(reloadCmd)
|
||||||
}
|
}
|
||||||
|
31
cmd/reload.go
Normal file
31
cmd/reload.go
Normal 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)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
@ -3,6 +3,7 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mohae/deepcopy"
|
"github.com/mohae/deepcopy"
|
||||||
|
"github.com/okzk/sdnotify"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/v2rayA/dae/cmd/internal"
|
"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)
|
sigs := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGKILL, syscall.SIGILL, syscall.SIGUSR1)
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGKILL, syscall.SIGILL, syscall.SIGUSR1)
|
||||||
go func() {
|
go func() {
|
||||||
|
sdnotify.Ready()
|
||||||
if listener, err = c.ListenAndServe(conf.Global.TproxyPort); err != nil {
|
if listener, err = c.ListenAndServe(conf.Global.TproxyPort); err != nil {
|
||||||
log.Errorln("ListenAndServe:", err)
|
log.Errorln("ListenAndServe:", err)
|
||||||
}
|
}
|
||||||
@ -80,6 +82,7 @@ loop:
|
|||||||
if reloading {
|
if reloading {
|
||||||
reloading = false
|
reloading = false
|
||||||
log.Warnln("[Reload] Serve")
|
log.Warnln("[Reload] Serve")
|
||||||
|
sdnotify.Ready()
|
||||||
go func() {
|
go func() {
|
||||||
if err := c.Serve(listener); err != nil {
|
if err := c.Serve(listener); err != nil {
|
||||||
log.Errorln("ListenAndServe:", err)
|
log.Errorln("ListenAndServe:", err)
|
||||||
@ -91,6 +94,7 @@ loop:
|
|||||||
}
|
}
|
||||||
case syscall.SIGUSR1:
|
case syscall.SIGUSR1:
|
||||||
// Reload signal.
|
// Reload signal.
|
||||||
|
sdnotify.Reloading()
|
||||||
log.Warnln("[Reload] Received reload signal; prepare to reload")
|
log.Warnln("[Reload] Received reload signal; prepare to reload")
|
||||||
obj := c.EjectBpf()
|
obj := c.EjectBpf()
|
||||||
log.Warnln("[Reload] Load new control plane")
|
log.Warnln("[Reload] Load new control plane")
|
||||||
@ -99,6 +103,7 @@ loop:
|
|||||||
log.WithFields(logrus.Fields{
|
log.WithFields(logrus.Fields{
|
||||||
"err": err,
|
"err": err,
|
||||||
}).Errorln("failed to reload")
|
}).Errorln("failed to reload")
|
||||||
|
sdnotify.Ready()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Warnln("[Reload] Stopped old control plane")
|
log.Warnln("[Reload] Stopped old control plane")
|
||||||
@ -155,7 +160,6 @@ func newControlPlane(log *logrus.Logger, bpf interface{}, conf *config.Config) (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call GC to release memory.
|
// Call GC to release memory.
|
||||||
runtime.GC()
|
runtime.GC()
|
||||||
|
|
||||||
|
@ -1378,8 +1378,6 @@ new_connection:
|
|||||||
goto block;
|
goto block;
|
||||||
}
|
}
|
||||||
|
|
||||||
control_plane_tproxy:
|
|
||||||
|
|
||||||
// Assign to control plane.
|
// Assign to control plane.
|
||||||
|
|
||||||
if (l4proto == IPPROTO_TCP) {
|
if (l4proto == IPPROTO_TCP) {
|
||||||
|
1
go.mod
1
go.mod
@ -10,6 +10,7 @@ require (
|
|||||||
github.com/json-iterator/go v1.1.12
|
github.com/json-iterator/go v1.1.12
|
||||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
|
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
|
||||||
github.com/mzz2017/softwind v0.0.0-20230224125402-d460ce1c5b4b
|
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/safchain/ethtool v0.0.0-20230116090318-67cc41908669
|
||||||
github.com/sirupsen/logrus v1.9.0
|
github.com/sirupsen/logrus v1.9.0
|
||||||
github.com/spf13/cobra v1.6.1
|
github.com/spf13/cobra v1.6.1
|
||||||
|
2
go.sum
2
go.sum
@ -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.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||||
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
||||||
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
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.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.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
||||||
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
||||||
|
@ -5,12 +5,13 @@ After=network-online.target docker.service
|
|||||||
Wants=network-online.target
|
Wants=network-online.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=notify
|
||||||
User=root
|
User=root
|
||||||
LimitNPROC=500
|
LimitNPROC=512
|
||||||
LimitNOFILE=1000000
|
LimitNOFILE=1048576
|
||||||
ExecStartPre=/usr/bin/dae validate -c /etc/dae/config.dae
|
ExecStartPre=/usr/bin/dae validate -c /etc/dae/config.dae
|
||||||
ExecStart=/usr/bin/dae run --disable-timestamp -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
|
Restart=on-abnormal
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
|
Loading…
Reference in New Issue
Block a user