forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Windows: retry jobs that fail to start
If a job fails to start, attempt to restart it up to 5 times. Previously the job supervisor did not check for errors during start and failing jobs where automatically re-started by the service wrapper/service control manager. We now check for errors during start, so to replicate the previous logic while still being able to return a useful error we retry jobs that failed to start and only return the error if none of the retries succeeded. [#150233685](https://www.pivotaltracker.com/story/show/150233685)
- Loading branch information
1 parent
dc9a5b4
commit c0e256a
Showing
7 changed files
with
292 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"flag" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
const HardTimeout = 5 * time.Minute | ||
|
||
var FlapFile string | ||
|
||
func init() { | ||
flag.StringVar(&FlapFile, "file", "", "File to record the current flap count") | ||
flag.StringVar(&FlapFile, "f", "Hello", "File to record the current flap count (shorthand)") | ||
} | ||
|
||
func realMain() error { | ||
flag.Parse() | ||
|
||
f, err := os.OpenFile(FlapFile, os.O_RDWR, 0644) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
|
||
b, err := ioutil.ReadAll(f) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
b = bytes.TrimSpace(b) | ||
if len(b) == 0 { | ||
return fmt.Errorf("Error: empty flap count file:", FlapFile) | ||
} | ||
|
||
n, err := strconv.Atoi(string(b)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if n > 0 { | ||
if err := f.Truncate(0); err != nil { | ||
return err | ||
} | ||
if _, err := f.Seek(0, 0); err != nil { | ||
return err | ||
} | ||
if _, err := f.WriteString(strconv.Itoa(n - 1)); err != nil { | ||
return err | ||
} | ||
} | ||
f.Close() | ||
|
||
// Flap then exit | ||
if n > 0 { | ||
return fmt.Errorf("Exiting count: %d", n) | ||
} | ||
|
||
t := time.Now() | ||
for time.Since(t) < HardTimeout { | ||
time.Sleep(time.Second * 30) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func main() { | ||
if err := realMain(); err != nil { | ||
fmt.Fprintf(os.Stderr, "error: %s\n", err) | ||
os.Exit(5) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.