embarkmobile/foreman_god — pull request #3 by steakknife (2014-02-26 02:31:36+00:00)
Title: [Feature] tmp/stop.txt

## Install (for testing)

```ruby
# Gemfile
gem 'god', github: 'steakknife/god', branch: 'feature__down_state'
gem 'foreman_god', github: 'steakknife/foreman_god', branch: 'feature__stop.txt'
```

## Usage

### To down the process

`touch tmp/stop.txt`

### To restart the process

`rm -f tmp/stop.txt`

## Proof or it didn't happen -v

Specs seem busted, so the stupid monkey workaround.

### Config

#### Procfile.foreman_god
```ruby
#!/usr/bin/env bundle exec god -D -c
# vim: set filetype=ruby:
# mostly just for standalone production and dev
require 'foreman_god'

ForemanGod.watch File.dirname(__FILE__) do |w|
w.name = 'foreman'
w.start = 'bundle exec foreman start'
w.keepalive
end
```

#### Procfile
`web: bundle exec puma -p $PORT`

#### (Insert your magical, world-denting app here)

### Proof

#### Stopping

```
I [2014-02-25 18:02:08] INFO: RubyClipper-web-1 [ok] (ForemanRestartFileTouched)
I [2014-02-25 18:02:12] INFO: RubyClipper-web-1 [ok] (ForemanStopFileExists)
I [2014-02-25 18:02:13] INFO: RubyClipper-web-1 [ok] (ForemanRestartFileTouched)
I [2014-02-25 18:02:17] INFO: RubyClipper-web-1 [trigger] (ForemanStopFileExists) <<< touch tmp/stop.txt
I [2014-02-25 18:02:17] INFO: RubyClipper-web-1 move 'up' to 'stop'
I [2014-02-25 18:02:17] INFO: RubyClipper-web-1 stop: default lambda killer
I [2014-02-25 18:02:17] INFO: RubyClipper-web-1 sent SIGTERM
I [2014-02-25 18:02:18] INFO: RubyClipper-web-1 process stopped
I [2014-02-25 18:02:18] INFO: RubyClipper-web-1 moved 'up' to 'stop'
I [2014-02-25 18:02:18] INFO: RubyClipper-web-1 [ok] (ForemanStopFileDoesntExist)
I [2014-02-25 18:02:23] INFO: RubyClipper-web-1 [ok] (ForemanStopFileDoesntExist)
```

#### Starting

```
I [2014-02-25 18:05:34] INFO: RubyClipper-web-1 [ok] (ForemanStopFileDoesntExist)
I [2014-02-25 18:05:39] INFO: RubyClipper-web-1 [trigger] (ForemanStopFileDoesntExist) <<< rm -f tmp/stop.txt
I [2014-02-25 18:05:39] INFO: RubyClipper-web-1 move 'stop' to 'restart'
I [2014-02-25 18:05:39] INFO: RubyClipper-web-1 stop: default lambda killer
I [2014-02-25 18:05:39] INFO: RubyClipper-web-1 sent SIGTERM
I [2014-02-25 18:05:39] INFO: RubyClipper-web-1 process stopped
I [2014-02-25 18:05:39] INFO: RubyClipper-web-1 start: bundle exec puma -p 5000
I [2014-02-25 18:05:39] INFO: RubyClipper-web-1 moved 'stop' to 'restart'
I [2014-02-25 18:05:39] INFO: RubyClipper-web-1 [trigger] process is running (ProcessRunning)
I [2014-02-25 18:05:39] INFO: RubyClipper-web-1 move 'restart' to 'up'
I [2014-02-25 18:05:39] INFO: RubyClipper-web-1 moved 'restart' to 'up'
I [2014-02-25 18:05:39] INFO: RubyClipper-web-1 [ok] (ForemanStopFileExists)
```

#### Note: [ok] means the watch condition is false, [trigger] means it's true.