Skip to content

Commit

Permalink
Add command to check lockfile (closes #67)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeemster committed Sep 9, 2016
1 parent 5137ef0 commit 8f3e0bf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 15 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func main() {

lockFile, lockErr := LockFileFromOptions(options)
if lockErr != nil {
log.Printf("Could not get LockFile: %s", lockErr.Error())
log.Printf("Error: %s", lockErr.Error())
os.Exit(3)
}

Expand Down Expand Up @@ -106,6 +106,17 @@ func processFlags() Options {
os.Exit(0)
}

if options.checkLock != "" {
lockFile, lockErr := LockFileFromOptions(options)
if lockErr != nil {
log.Printf("Error: %s found, previous run failed or is ongoing", lockFile.Path)
os.Exit(3)
} else {
log.Printf("Success: %s does not exist", lockFile.Path)
os.Exit(0)
}
}

if options.playbook == "" {
fmt.Println("required flag not defined: -playbook")
os.Exit(2)
Expand Down Expand Up @@ -161,6 +172,9 @@ func LockFileFromOptions(options Options) (*LockFile, error) {
} else if options.softLock != "" {
lockPath = options.softLock
isSoftLock = true
} else if options.checkLock != "" {
lockPath = options.checkLock
isSoftLock = false
} else {
// no-op
return nil, nil
Expand Down
2 changes: 2 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Options struct {
consul string
lock string
softLock string
checkLock string
variables CLIVariables
}

Expand All @@ -65,6 +66,7 @@ func (o *Options) GetFlagSet() *flag.FlagSet {
fs.StringVar(&(o.consul), "consul", "", "The address of a consul server with playbooks and SQL files stored in KV pairs")
fs.StringVar(&(o.lock), "lock", "", "Optional argument which checks and sets a lockfile to ensure this run is a singleton. Deletes lock on run completing successfully")
fs.StringVar(&(o.softLock), "softLock", "", "Optional argument, like '-lock' but the lockfile will be deleted even if the run fails")
fs.StringVar(&(o.checkLock), "checkLock", "", "Checks whether the lockfile already exists")
// TODO: add format flag if/when we support TOML

return fs
Expand Down

0 comments on commit 8f3e0bf

Please sign in to comment.