bluepill 0.0.50 → 0.0.51
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +48 -18
- data/lib/bluepill/process_statistics.rb +2 -2
- data/lib/bluepill/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -9,7 +9,7 @@ It's hosted on [rubygems.org][rubygems].
|
|
9
9
|
In order to take advantage of logging with syslog, you also need to setup your syslog to log the local6 facility. Edit the appropriate config file for your syslogger (/etc/syslog.conf for syslog) and add a line for local6:
|
10
10
|
|
11
11
|
local6.* /var/log/bluepill.log
|
12
|
-
|
12
|
+
|
13
13
|
You'll also want to add _/var/log/bluepill.log_ to _/etc/logrotate.d/syslog_ so that it gets rotated.
|
14
14
|
|
15
15
|
Lastly, create the _/var/bluepill_ directory for bluepill to store its pid and sock files.
|
@@ -20,15 +20,18 @@ Bluepill organizes processes into 3 levels: application -> group -> process. Eac
|
|
20
20
|
|
21
21
|
The minimum config file looks something like this:
|
22
22
|
|
23
|
+
```ruby
|
23
24
|
Bluepill.application("app_name") do |app|
|
24
25
|
app.process("process_name") do |process|
|
25
26
|
process.start_command = "/usr/bin/some_start_command"
|
26
27
|
process.pid_file = "/tmp/some_pid_file.pid"
|
27
28
|
end
|
28
29
|
end
|
29
|
-
|
30
|
+
```
|
31
|
+
|
30
32
|
Note that since we specified a PID file and start command, bluepill assumes the process will daemonize itself. If we wanted bluepill to daemonize it for us, we can do (note we still need to specify a PID file):
|
31
33
|
|
34
|
+
```ruby
|
32
35
|
Bluepill.application("app_name") do |app|
|
33
36
|
app.process("process_name") do |process|
|
34
37
|
process.start_command = "/usr/bin/some_start_command"
|
@@ -36,11 +39,13 @@ Note that since we specified a PID file and start command, bluepill assumes the
|
|
36
39
|
process.daemonize = true
|
37
40
|
end
|
38
41
|
end
|
39
|
-
|
42
|
+
```
|
43
|
+
|
40
44
|
If you don't specify a stop command, a TERM signal will be sent by default. Similarly, the default restart action is to issue stop and then start.
|
41
45
|
|
42
46
|
Now if we want to do something more meaningful, like actually monitor the process, we do:
|
43
47
|
|
48
|
+
```ruby
|
44
49
|
Bluepill.application("app_name") do |app|
|
45
50
|
app.process("process_name") do |process|
|
46
51
|
process.start_command = "/usr/bin/some_start_command"
|
@@ -49,11 +54,13 @@ Now if we want to do something more meaningful, like actually monitor the proces
|
|
49
54
|
process.checks :cpu_usage, :every => 10.seconds, :below => 5, :times => 3
|
50
55
|
end
|
51
56
|
end
|
52
|
-
|
57
|
+
```
|
58
|
+
|
53
59
|
We added a line that checks every 10 seconds to make sure the cpu usage of this process is below 5 percent; 3 failed checks results in a restart. We can specify a two-element array for the _times_ option to say that it 3 out of 5 failed attempts results in a restart.
|
54
60
|
|
55
61
|
To watch memory usage, we just add one more line:
|
56
62
|
|
63
|
+
```ruby
|
57
64
|
Bluepill.application("app_name") do |app|
|
58
65
|
app.process("process_name") do |process|
|
59
66
|
process.start_command = "/usr/bin/some_start_command"
|
@@ -63,9 +70,11 @@ To watch memory usage, we just add one more line:
|
|
63
70
|
process.checks :mem_usage, :every => 10.seconds, :below => 100.megabytes, :times => [3,5]
|
64
71
|
end
|
65
72
|
end
|
66
|
-
|
73
|
+
```
|
74
|
+
|
67
75
|
We can tell bluepill to give a process some grace time to start/stop/restart before resuming monitoring:
|
68
76
|
|
77
|
+
```ruby
|
69
78
|
Bluepill.application("app_name") do |app|
|
70
79
|
app.process("process_name") do |process|
|
71
80
|
process.start_command = "/usr/bin/some_start_command"
|
@@ -78,9 +87,11 @@ We can tell bluepill to give a process some grace time to start/stop/restart bef
|
|
78
87
|
process.checks :mem_usage, :every => 10.seconds, :below => 100.megabytes, :times => [3,5]
|
79
88
|
end
|
80
89
|
end
|
90
|
+
```
|
81
91
|
|
82
92
|
We can group processes by name:
|
83
93
|
|
94
|
+
```ruby
|
84
95
|
Bluepill.application("app_name") do |app|
|
85
96
|
5.times do |i|
|
86
97
|
app.process("process_name_#{i}") do |process|
|
@@ -90,9 +101,11 @@ We can group processes by name:
|
|
90
101
|
end
|
91
102
|
end
|
92
103
|
end
|
104
|
+
```
|
93
105
|
|
94
106
|
If you want to run the process as someone other than root:
|
95
107
|
|
108
|
+
```ruby
|
96
109
|
Bluepill.application("app_name") do |app|
|
97
110
|
app.process("process_name") do |process|
|
98
111
|
process.start_command = "/usr/bin/some_start_command"
|
@@ -104,9 +117,11 @@ If you want to run the process as someone other than root:
|
|
104
117
|
process.checks :mem_usage, :every => 10.seconds, :below => 100.megabytes, :times => [3,5]
|
105
118
|
end
|
106
119
|
end
|
107
|
-
|
120
|
+
```
|
121
|
+
|
108
122
|
You can also set an app-wide uid/gid:
|
109
123
|
|
124
|
+
```ruby
|
110
125
|
Bluepill.application("app_name") do |app|
|
111
126
|
app.uid = "deploy"
|
112
127
|
app.gid = "deploy"
|
@@ -115,13 +130,17 @@ You can also set an app-wide uid/gid:
|
|
115
130
|
process.pid_file = "/tmp/some_pid_file.pid"
|
116
131
|
end
|
117
132
|
end
|
118
|
-
|
133
|
+
```
|
134
|
+
|
119
135
|
To check for flapping:
|
120
136
|
|
137
|
+
```ruby
|
121
138
|
process.checks :flapping, :times => 2, :within => 30.seconds, :retry_in => 7.seconds
|
122
|
-
|
139
|
+
```
|
140
|
+
|
123
141
|
To set the working directory to _cd_ into when starting the command:
|
124
142
|
|
143
|
+
```ruby
|
125
144
|
Bluepill.application("app_name") do |app|
|
126
145
|
app.process("process_name") do |process|
|
127
146
|
process.start_command = "/usr/bin/some_start_command"
|
@@ -129,10 +148,11 @@ To set the working directory to _cd_ into when starting the command:
|
|
129
148
|
process.working_dir = "/path/to/some_directory"
|
130
149
|
end
|
131
150
|
end
|
132
|
-
|
133
|
-
You can also have an app-wide working directory:
|
151
|
+
```
|
134
152
|
|
153
|
+
You can also have an app-wide working directory:
|
135
154
|
|
155
|
+
```ruby
|
136
156
|
Bluepill.application("app_name") do |app|
|
137
157
|
app.working_dir = "/path/to/some_directory"
|
138
158
|
app.process("process_name") do |process|
|
@@ -140,34 +160,39 @@ You can also have an app-wide working directory:
|
|
140
160
|
process.pid_file = "/tmp/some_pid_file.pid"
|
141
161
|
end
|
142
162
|
end
|
143
|
-
|
144
|
-
Note: We also set the PWD in the environment to the working dir you specify. This is useful for when the working dir is a symlink. Unicorn in particular will cd into the environment variable in PWD when it re-execs to deal with a change in the symlink.
|
163
|
+
```
|
145
164
|
|
165
|
+
Note: We also set the PWD in the environment to the working dir you specify. This is useful for when the working dir is a symlink. Unicorn in particular will cd into the environment variable in PWD when it re-execs to deal with a change in the symlink.
|
146
166
|
|
147
167
|
And lastly, to monitor child processes:
|
148
168
|
|
169
|
+
```ruby
|
149
170
|
process.monitor_children do |child_process|
|
150
171
|
child_process.checks :cpu_usage, :every => 10, :below => 5, :times => 3
|
151
172
|
child_process.checks :mem_usage, :every => 10, :below => 100.megabytes, :times => [3, 5]
|
152
173
|
|
153
174
|
child_process.stop_command = "kill -QUIT {{PID}}"
|
154
175
|
end
|
155
|
-
|
176
|
+
```
|
177
|
+
|
156
178
|
Note {{PID}} will be substituted for the pid of process in both the stop and restart commands.
|
157
179
|
|
158
180
|
### A Note About Output Redirection
|
159
181
|
|
160
182
|
While you can specify shell tricks like the following in the start_command of a process:
|
161
|
-
|
183
|
+
|
184
|
+
```ruby
|
162
185
|
Bluepill.application("app_name") do |app|
|
163
186
|
app.process("process_name") do |process|
|
164
187
|
process.start_command = "cd /tmp/some_dir && SOME_VAR=1 /usr/bin/some_start_command > /tmp/server.log 2>&1"
|
165
188
|
process.pid_file = "/tmp/some_pid_file.pid"
|
166
189
|
end
|
167
190
|
end
|
168
|
-
|
191
|
+
```
|
192
|
+
|
169
193
|
We recommend that you _not_ do that and instead use the config options to capture output from your daemons. Like so:
|
170
194
|
|
195
|
+
```ruby
|
171
196
|
Bluepill.application("app_name") do |app|
|
172
197
|
app.process("process_name") do |process|
|
173
198
|
process.start_command = "/usr/bin/env SOME_VAR=1 /usr/bin/some_start_command"
|
@@ -178,18 +203,19 @@ We recommend that you _not_ do that and instead use the config options to captur
|
|
178
203
|
process.pid_file = "/tmp/some_pid_file.pid"
|
179
204
|
end
|
180
205
|
end
|
181
|
-
|
206
|
+
```
|
207
|
+
|
182
208
|
The main benefit of using the config options is that Bluepill will be able to monitor the correct process instead of just watching the shell that spawned your actual server.
|
183
209
|
|
184
210
|
### CLI
|
185
211
|
To start a bluepill process and load a config:
|
186
212
|
|
187
213
|
sudo bluepill load /path/to/production.pill
|
188
|
-
|
214
|
+
|
189
215
|
To act on a process or group:
|
190
216
|
|
191
217
|
sudo bluepill <start|stop|restart|unmonitor> <process_or_group_name>
|
192
|
-
|
218
|
+
|
193
219
|
To view process statuses:
|
194
220
|
|
195
221
|
sudo bluepill status
|
@@ -205,18 +231,22 @@ To quit bluepill:
|
|
205
231
|
### Logging
|
206
232
|
By default, bluepill uses syslog local6 facility as described in the installation section. But if for any reason you don't want to use syslog, you can use a log file. You can do this by setting the :log\_file option in the config:
|
207
233
|
|
234
|
+
```ruby
|
208
235
|
Bluepill.application("app_name", :log_file => "/path/to/bluepill.log") do |app|
|
209
236
|
# ...
|
210
237
|
end
|
238
|
+
```
|
211
239
|
|
212
240
|
Keep in mind that you still need to set up log rotation (described in the installation section) to keep the log file from growing huge.
|
213
241
|
|
214
242
|
### Extra options
|
215
243
|
You can run bluepill in the foreground:
|
216
244
|
|
245
|
+
```ruby
|
217
246
|
Bluepill.application("app_name", :foreground => true) do |app|
|
218
247
|
# ...
|
219
248
|
end
|
249
|
+
```
|
220
250
|
|
221
251
|
Note that You must define only one application per config when using foreground mode.
|
222
252
|
|
@@ -13,8 +13,8 @@ module Bluepill
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def to_s
|
16
|
-
str = @events.reverse.
|
17
|
-
|
16
|
+
str = @events.reverse.map do |(event, reason, time)|
|
17
|
+
" #{event} at #{time.strftime(STRFTIME)} - #{reason || "unspecified"}"
|
18
18
|
end.join("\n")
|
19
19
|
|
20
20
|
"event history:\n#{str}"
|
data/lib/bluepill/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bluepill
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 121
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 51
|
10
|
+
version: 0.0.51
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Arya Asemanfar
|