check instance is running
This commit is contained in:
parent
04d106230e
commit
2074b58399
16
kvas2.go
16
kvas2.go
@ -15,6 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
ErrAlreadyRunning = errors.New("already running")
|
||||||
ErrGroupIDConflict = errors.New("group id conflict")
|
ErrGroupIDConflict = errors.New("group id conflict")
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -32,9 +33,17 @@ type App struct {
|
|||||||
DNSOverrider *iptablesHelper.DNSOverrider
|
DNSOverrider *iptablesHelper.DNSOverrider
|
||||||
Records *Records
|
Records *Records
|
||||||
Groups map[int]*Group
|
Groups map[int]*Group
|
||||||
|
|
||||||
|
isRunning bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) Listen(ctx context.Context) []error {
|
func (a *App) Listen(ctx context.Context) []error {
|
||||||
|
if a.isRunning {
|
||||||
|
return []error{ErrAlreadyRunning}
|
||||||
|
}
|
||||||
|
a.isRunning = true
|
||||||
|
defer func() { a.isRunning = false }()
|
||||||
|
|
||||||
errs := make([]error, 0)
|
errs := make([]error, 0)
|
||||||
isError := make(chan struct{})
|
isError := make(chan struct{})
|
||||||
|
|
||||||
@ -158,6 +167,13 @@ func (a *App) AppendGroup(group *models.Group) error {
|
|||||||
Group: group,
|
Group: group,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if a.isRunning {
|
||||||
|
err := a.Groups[group.ID].Enable()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to enable appended group: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user