This repository has been archived by the owner on Aug 31, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from steakknife/fix__prevent_init_to_up_on_stop…
….txt prevent init->up->stop when stop.txt exists
- Loading branch information
Showing
4 changed files
with
98 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'foreman_god/conditions/foreman_stop_file_exists' | ||
require 'foreman_god/conditions/foreman_restart_file_touched' |
37 changes: 37 additions & 0 deletions
37
lib/foreman_god/conditions/foreman_restart_file_touched.rb
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,37 @@ | ||
require 'god' | ||
|
||
module God | ||
module Conditions | ||
# Adapted from https://gist.github.com/571095 | ||
class ForemanRestartFileTouched < PollCondition | ||
attr_accessor :restart_file | ||
|
||
def initialize | ||
super | ||
end | ||
|
||
def process_start_time | ||
Time.parse(`ps -o lstart= -p #{self.watch.pid}`) rescue nil | ||
end | ||
|
||
def restart_file_modification_time | ||
File.mtime(self.restart_file) rescue Time.at(0) | ||
end | ||
|
||
def valid? | ||
valid = true | ||
valid &= complain("Attribute 'restart_file' must be specified", self) if self.restart_file.nil? | ||
valid | ||
end | ||
|
||
def test | ||
ptime = process_start_time | ||
if ptime | ||
ptime < restart_file_modification_time | ||
else | ||
false | ||
end | ||
end | ||
end | ||
end | ||
end |
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,34 @@ | ||
require 'god' | ||
|
||
module God | ||
module Conditions | ||
class ForemanStopFileExists < PollCondition | ||
attr_accessor :stop_file | ||
# invert file test result | ||
# --------------------------- | ||
# false exists true | ||
# false absent false | ||
# true exists false | ||
# true absent true | ||
# | ||
# default: false | ||
attr_accessor :invert | ||
|
||
def initialize | ||
super | ||
@invert = false | ||
end | ||
|
||
def valid? | ||
valid = true | ||
valid &= complain("Attribute 'invert' must be true or fails", self) unless self.invert === true || self.invert === false | ||
valid &= complain("Attribute 'stop_file' must be specified", self) if self.stop_file.nil? | ||
valid | ||
end | ||
|
||
def test | ||
File.exist?(stop_file) ^ invert | ||
end | ||
end | ||
end | ||
end |
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