Add crash_on_safe_exit option to service files
This commit is contained in:
parent
dc37ab7f7c
commit
a7a8322f13
@ -30,17 +30,18 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type EnitService struct {
|
type EnitService struct {
|
||||||
Name string `yaml:"name"`
|
Name string `yaml:"name"`
|
||||||
Description string `yaml:"description,omitempty"`
|
Description string `yaml:"description,omitempty"`
|
||||||
Dependencies []string `yaml:"dependencies,omitempty"`
|
Dependencies []string `yaml:"dependencies,omitempty"`
|
||||||
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"`
|
||||||
StopCmd string `yaml:"stop_cmd,omitempty"`
|
CrashOnSafeExit bool `yaml:"crash_on_safe_exit"`
|
||||||
Restart string `yaml:"restart,omitempty"`
|
StopCmd string `yaml:"stop_cmd,omitempty"`
|
||||||
ServiceRunPath string
|
Restart string `yaml:"restart,omitempty"`
|
||||||
restartCount int
|
ServiceRunPath string
|
||||||
stopChannel chan bool
|
restartCount int
|
||||||
|
stopChannel chan bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build-time variables
|
// Build-time variables
|
||||||
@ -139,17 +140,18 @@ func Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
service := EnitService{
|
service := EnitService{
|
||||||
Name: "",
|
Name: "",
|
||||||
Description: "",
|
Description: "",
|
||||||
Dependencies: make([]string, 0),
|
Dependencies: make([]string, 0),
|
||||||
Type: "",
|
Type: "",
|
||||||
StartCmd: "",
|
StartCmd: "",
|
||||||
ExitMethod: "",
|
ExitMethod: "",
|
||||||
StopCmd: "",
|
StopCmd: "",
|
||||||
Restart: "",
|
Restart: "",
|
||||||
ServiceRunPath: "",
|
CrashOnSafeExit: true,
|
||||||
restartCount: 0,
|
ServiceRunPath: "",
|
||||||
stopChannel: make(chan bool),
|
restartCount: 0,
|
||||||
|
stopChannel: make(chan bool),
|
||||||
}
|
}
|
||||||
if err := yaml.Unmarshal(bytes, &service); err != nil {
|
if err := yaml.Unmarshal(bytes, &service); err != nil {
|
||||||
logger.Printf("Could not read service file at %s!\n", path.Join(serviceConfigDir, "services", entry.Name()))
|
logger.Printf("Could not read service file at %s!\n", path.Join(serviceConfigDir, "services", entry.Name()))
|
||||||
@ -367,8 +369,13 @@ func (service *EnitService) StartService() error {
|
|||||||
_ = service.setCurrentState(EnitServiceCompleted)
|
_ = service.setCurrentState(EnitServiceCompleted)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logger.Printf("Service (%s) has crashed!\n", service.Name)
|
if !service.CrashOnSafeExit {
|
||||||
_ = service.setCurrentState(EnitServiceCrashed)
|
logger.Printf("Service (%s) has exited\n", service.Name)
|
||||||
|
_ = service.setCurrentState(EnitServiceStopped)
|
||||||
|
} else {
|
||||||
|
logger.Printf("Service (%s) has crashed!\n", service.Name)
|
||||||
|
_ = service.setCurrentState(EnitServiceCrashed)
|
||||||
|
}
|
||||||
|
|
||||||
if service.Restart == "always" {
|
if service.Restart == "always" {
|
||||||
_ = service.StartService()
|
_ = service.StartService()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user