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