Add crash_on_safe_exit option to service files
This commit is contained in:
parent
dc37ab7f7c
commit
a7a8322f13
@ -36,6 +36,7 @@ type EnitService struct {
|
|||||||
Type string `yaml:"type"`
|
Type string `yaml:"type"`
|
||||||
StartCmd string `yaml:"start_cmd"`
|
StartCmd string `yaml:"start_cmd"`
|
||||||
ExitMethod string `yaml:"exit_method"`
|
ExitMethod string `yaml:"exit_method"`
|
||||||
|
CrashOnSafeExit bool `yaml:"crash_on_safe_exit"`
|
||||||
StopCmd string `yaml:"stop_cmd,omitempty"`
|
StopCmd string `yaml:"stop_cmd,omitempty"`
|
||||||
Restart string `yaml:"restart,omitempty"`
|
Restart string `yaml:"restart,omitempty"`
|
||||||
ServiceRunPath string
|
ServiceRunPath string
|
||||||
@ -147,6 +148,7 @@ func Init() {
|
|||||||
ExitMethod: "",
|
ExitMethod: "",
|
||||||
StopCmd: "",
|
StopCmd: "",
|
||||||
Restart: "",
|
Restart: "",
|
||||||
|
CrashOnSafeExit: true,
|
||||||
ServiceRunPath: "",
|
ServiceRunPath: "",
|
||||||
restartCount: 0,
|
restartCount: 0,
|
||||||
stopChannel: make(chan bool),
|
stopChannel: make(chan bool),
|
||||||
@ -367,8 +369,13 @@ func (service *EnitService) StartService() error {
|
|||||||
_ = service.setCurrentState(EnitServiceCompleted)
|
_ = service.setCurrentState(EnitServiceCompleted)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if !service.CrashOnSafeExit {
|
||||||
|
logger.Printf("Service (%s) has exited\n", service.Name)
|
||||||
|
_ = service.setCurrentState(EnitServiceStopped)
|
||||||
|
} else {
|
||||||
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 == "always" {
|
if service.Restart == "always" {
|
||||||
_ = service.StartService()
|
_ = service.StartService()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user