* make edit and service argument subcommands * generate uuid if non-exist, use default report_delay or ip_report_period value if not specified
38 lines
501 B
Go
38 lines
501 B
Go
package commands
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/nezhahq/service"
|
|
)
|
|
|
|
type Program struct {
|
|
Exit chan struct{}
|
|
Service service.Service
|
|
Run func()
|
|
}
|
|
|
|
func (p *Program) Start(s service.Service) error {
|
|
go p.run()
|
|
return nil
|
|
}
|
|
|
|
func (p *Program) Stop(s service.Service) error {
|
|
close(p.Exit)
|
|
if service.Interactive() {
|
|
os.Exit(0)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *Program) run() {
|
|
defer func() {
|
|
if service.Interactive() {
|
|
p.Stop(p.Service)
|
|
} else {
|
|
p.Service.Stop()
|
|
}
|
|
}()
|
|
p.Run()
|
|
}
|