refactor: use exit code 137 to signify a lock was unable to be retrieved when calling ps:retire
Closes #5432
This commit is contained in:
@@ -24,6 +24,28 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
// RetireLockFailed wraps error to distinguish between a normal error
|
||||
// and an error where the retire lock could not be fetched
|
||||
type RetireLockFailed struct {
|
||||
Err *error
|
||||
}
|
||||
|
||||
// ExitCode returns an exit code to use in case this error bubbles
|
||||
// up into an os.Exit() call
|
||||
func (err *RetireLockFailed) ExitCode() int {
|
||||
return 137
|
||||
}
|
||||
|
||||
// Error returns a standard non-existent app error
|
||||
func (err *RetireLockFailed) Error() string {
|
||||
if err.Err != nil {
|
||||
e := *err.Err
|
||||
return fmt.Sprintf("Failed to acquire ps:retire lock: %s", e.Error())
|
||||
}
|
||||
|
||||
return fmt.Sprintf("Failed to acquire ps:retire lock")
|
||||
}
|
||||
|
||||
// Formation contains scaling information for a given process type
|
||||
type Formation struct {
|
||||
ProcessType string `json:"process_type"`
|
||||
|
||||
@@ -111,12 +111,12 @@ func CommandRetire(appName string) error {
|
||||
fileLock := flock.New(lockFile)
|
||||
locked, err := fileLock.TryLock()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to acquire ps:retire lock: %s", err)
|
||||
return &RetireLockFailed{&err}
|
||||
}
|
||||
defer fileLock.Unlock()
|
||||
|
||||
if !locked {
|
||||
return fmt.Errorf("Failed to acquire ps:retire lock")
|
||||
return &RetireLockFailed{}
|
||||
}
|
||||
|
||||
common.LogInfo1("Retiring old containers and images")
|
||||
|
||||
@@ -27,6 +27,7 @@ After=docker.service
|
||||
Type=oneshot
|
||||
User=$DOKKU_SYSTEM_USER
|
||||
ExecStart=$DOKKU_PATH ps:retire
|
||||
SuccessExitStatus=137
|
||||
|
||||
[Install]
|
||||
WantedBy=docker.service
|
||||
|
||||
Reference in New Issue
Block a user