Merge pull request #5489 from dokku/5432-lock-exit-code
Use exit code 137 to signify a lock was unable to be retrieved when calling ps:retire
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
|
// Formation contains scaling information for a given process type
|
||||||
type Formation struct {
|
type Formation struct {
|
||||||
ProcessType string `json:"process_type"`
|
ProcessType string `json:"process_type"`
|
||||||
|
|||||||
@@ -111,12 +111,12 @@ func CommandRetire(appName string) error {
|
|||||||
fileLock := flock.New(lockFile)
|
fileLock := flock.New(lockFile)
|
||||||
locked, err := fileLock.TryLock()
|
locked, err := fileLock.TryLock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to acquire ps:retire lock: %s", err)
|
return &RetireLockFailed{&err}
|
||||||
}
|
}
|
||||||
defer fileLock.Unlock()
|
defer fileLock.Unlock()
|
||||||
|
|
||||||
if !locked {
|
if !locked {
|
||||||
return fmt.Errorf("Failed to acquire ps:retire lock")
|
return &RetireLockFailed{}
|
||||||
}
|
}
|
||||||
|
|
||||||
common.LogInfo1("Retiring old containers and images")
|
common.LogInfo1("Retiring old containers and images")
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ After=docker.service
|
|||||||
Type=oneshot
|
Type=oneshot
|
||||||
User=$DOKKU_SYSTEM_USER
|
User=$DOKKU_SYSTEM_USER
|
||||||
ExecStart=$DOKKU_PATH ps:retire
|
ExecStart=$DOKKU_PATH ps:retire
|
||||||
|
SuccessExitStatus=137
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=docker.service
|
WantedBy=docker.service
|
||||||
|
|||||||
Reference in New Issue
Block a user