Add restart=always option to service files
This commit is contained in:
parent
92802825cc
commit
dc37ab7f7c
@ -37,7 +37,7 @@ type EnitService struct {
|
||||
StartCmd string `yaml:"start_cmd"`
|
||||
ExitMethod string `yaml:"exit_method"`
|
||||
StopCmd string `yaml:"stop_cmd,omitempty"`
|
||||
Restart bool `yaml:"restart,omitempty"`
|
||||
Restart string `yaml:"restart,omitempty"`
|
||||
ServiceRunPath string
|
||||
restartCount int
|
||||
stopChannel chan bool
|
||||
@ -146,7 +146,7 @@ func Init() {
|
||||
StartCmd: "",
|
||||
ExitMethod: "",
|
||||
StopCmd: "",
|
||||
Restart: false,
|
||||
Restart: "",
|
||||
ServiceRunPath: "",
|
||||
restartCount: 0,
|
||||
stopChannel: make(chan bool),
|
||||
@ -176,6 +176,12 @@ func Init() {
|
||||
continue
|
||||
}
|
||||
|
||||
switch service.Restart {
|
||||
case "true", "always":
|
||||
default:
|
||||
service.Restart = "false"
|
||||
}
|
||||
|
||||
service.ServiceRunPath = path.Join(runtimeServiceDir, service.Name)
|
||||
err = os.MkdirAll(path.Join(service.ServiceRunPath), 0755)
|
||||
if err != nil {
|
||||
@ -364,7 +370,9 @@ func (service *EnitService) StartService() error {
|
||||
logger.Printf("Service (%s) has crashed!\n", service.Name)
|
||||
_ = service.setCurrentState(EnitServiceCrashed)
|
||||
|
||||
if service.Restart && service.restartCount < 5 {
|
||||
if service.Restart == "always" {
|
||||
_ = service.StartService()
|
||||
} else if service.Restart == "true" && service.restartCount < 5 {
|
||||
service.restartCount++
|
||||
_ = service.StartService()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user