daemon_controller 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9dce68cae7ce8da028c91815950481313672404aeaa48a0b97e817263dbb5ff
4
- data.tar.gz: 921a96fe368c826fa881e2beecab2a298620249b4a76bf1934849a22ea5bb61c
3
+ metadata.gz: bd4f2d08b82c7340e6b00c8a97e63f66a6677fbc28e9b705ecb6c53d75701e00
4
+ data.tar.gz: 11bc6d68d7837db49c123b5e2b08fc932bf60c1b0c29742e7e891e66d8f4f82a
5
5
  SHA512:
6
- metadata.gz: 27a36b21d30836e901637ea07f538872fa306f9ce9bfacd6175b0b4858ac45ba825999d798e9e7740371148f47e93d212df9f16a326835385613730e69389c65
7
- data.tar.gz: 23acb3cee9eef3f771f42e8deb06c750ba8bb4aa04d58bfa6b24837a15ff928edbe97c56b4f2018aed142e600f5f26733afc7e01bc1b1941f127d5e9d068142e
6
+ metadata.gz: c29f7ea6b92d607774bef4f42dba2e03215f85078079fb3febd404cf87efff8f0536e03ba870234c72925f7404142dba2bf73217d7586175328d6611ba72e3d8
7
+ data.tar.gz: 1b5d67e7165fb4c2ba1c667c774e089a5a5029e57ba47dd1f91cbcd17e2dcdef7136947b0d115d71b7db9c154013043f9da01428d55659898eee198bd1ca3d3a
data/README.md CHANGED
@@ -31,12 +31,6 @@ It provides the following functionality:
31
31
  gem install daemon_controller
32
32
  ```
33
33
 
34
- ## Resources
35
-
36
- * [Website](https://github.com/FooBarWidget/daemon_controller)
37
- * [RDoc](http://rdoc.info/projects/FooBarWidget/daemon_controller)
38
- * [Git repository](git://github.com/FooBarWidget/daemon_controller.git)
39
-
40
34
 
41
35
  What is it for?
42
36
  ===============
@@ -87,13 +81,15 @@ daemon varies. We've observed that waiting a fixed amount of time is by far the
87
81
  most common way. For example, UltraSphinx's daemon starting code looks like
88
82
  this:
89
83
 
90
- system "searchd --config '#{Ultrasphinx::CONF_PATH}'"
91
- sleep(4) # give daemon a chance to write the pid file
92
- if ultrasphinx_daemon_running?
93
- say "started successfully"
94
- else
95
- say "failed to start"
96
- end
84
+ ```ruby
85
+ system "searchd --config '#{Ultrasphinx::CONF_PATH}'"
86
+ sleep(4) # give daemon a chance to write the pid file
87
+ if ultrasphinx_daemon_running?
88
+ say "started successfully"
89
+ else
90
+ say "failed to start"
91
+ end
92
+ ```
97
93
 
98
94
  This is in no way a slam against UltraSphinx. However, if the daemon starts in
99
95
  200 miliseconds, then the user who issued the start command will be waiting for
@@ -291,7 +287,7 @@ without having to start the daemons manually.
291
287
  Tutorial #1: controlling Apache
292
288
  ===============================
293
289
 
294
- Suppose that you're a [Phusion Passenger](http://www.modrails.com/) developer,
290
+ Suppose that you're a [Phusion Passenger](https://www.phusionpasseenger.com/) developer,
295
291
  and you need to write tests for the Apache module. In particular, you want to
296
292
  test whether the different Phusion Passenger configuration directives are
297
293
  working as expected. Obviously, to test the Apache module, the Apache web
@@ -306,29 +302,30 @@ server must be running. For every test, you will want the unit test suite to:
306
302
 
307
303
  That can be done with the following code:
308
304
 
309
- require 'daemon_controller'
310
-
311
- File.open("apache.conf", "w") do |f|
312
- f.write("PidFile apache.pid\n")
313
- f.write("LogFile apache.log\n")
314
- f.write("Listen 1234\n")
315
- f.write(... other relevant configuration options ...)
316
- end
317
-
318
- controller = DaemonController.new(
319
- :identifier => 'Apache web server',
320
- :start_command => 'apachectl -f apache.conf -k start',
321
- :ping_command => [:tcp, 'localhost', 1234],
322
- :pid_file => 'apache.pid',
323
- :log_file => 'apache.log',
324
- :start_timeout => 25
325
- )
326
- controller.start
327
-
328
- .... apache is now started ....
329
- .... some test code here ....
330
-
331
- controller.stop
305
+ ```ruby
306
+ require "daemon_controller"
307
+
308
+ File.open("apache.conf", "w") do |f|
309
+ f.write("PidFile apache.pid\n")
310
+ f.write("LogFile apache.log\n")
311
+ f.write("Listen 1234\n")
312
+ f.write(... other relevant configuration options ...)
313
+ end
314
+
315
+ controller = DaemonController.new(
316
+ identifier: "Apache web server",
317
+ start_command: "apachectl -f apache.conf -k start",
318
+ ping_command: [:tcp, "localhost", 1234],
319
+ pid_file: "apache.pid",
320
+ log_file: "apache.log"
321
+ )
322
+ controller.start
323
+
324
+ # .... apache is now started ....
325
+ # .... some test code here ....
326
+
327
+ controller.stop
328
+ ```
332
329
 
333
330
  The `File.open` line is obvious: it writes the relevant Apache configuration
334
331
  file.
@@ -336,8 +333,8 @@ file.
336
333
  The next line is for creating a new DaemonController object. We pass a
337
334
  human-readable identifier for this daemon ("Apache web server") to the
338
335
  constructor. This is used for generating friendlier error messages.
339
- We also tell it how Apache is supposed to be started (`:start_command`), how to
340
- check whether it can be connected to (`:ping_command`), and where its PID file
336
+ We also tell it how Apache is supposed to be started (`start_command:`), how to
337
+ check whether it can be connected to (`ping_command:`), and where its PID file
341
338
  and log file is. If Apache failed with an error during startup, then it will be
342
339
  reported. If Apache failed with an error after it has gone into the background,
343
340
  then that will be reported too: the given log file is monitored for new error
@@ -345,7 +342,8 @@ messages.
345
342
  Finally, a timeout of 25 seconds is given. If Apache doesn't start within 25
346
343
  seconds, then an exception will be raised.
347
344
 
348
- The ping command is just a `Proc` which returns true or false. If the Proc
345
+ The ping command specifies which socket to connect to in order to check whether
346
+ the daemon is ready. It can also be a `Proc` which returns true or false. If the Proc
349
347
  raises `Errno::ECONNREFUSED`, then that's also interpreted by DaemonController
350
348
  as meaning that the daemon isn't responding yet.
351
349
 
@@ -392,41 +390,43 @@ isn't running.
392
390
 
393
391
  This can be achieved with the following code:
394
392
 
395
- require 'daemon_controller'
396
-
397
- class SearchServer
398
- SEARCH_SERVER_PORT = 1234
399
-
400
- def initialize
401
- @controller = DaemonController.new(
402
- :identifier => 'Sphinx search server',
403
- :start_command => "searchd -c config/sphinx.conf",
404
- :before_start => method(:before_start),
405
- :ping_command => [:tcp, 'localhost', SEARCH_SERVER_PORT],
406
- :pid_file => 'tmp/pids/sphinx.pid',
407
- :log_file => 'log/sphinx.log')
408
- end
409
-
410
- def query(search_terms)
411
- socket = @controller.connect do
412
- TCPSocket.new('localhost', SEARCH_SERVER_PORT)
413
- end
414
- send_query(socket, search_terms)
415
- return retrieve_results(socket)
416
- end
417
-
418
- private
419
- def before_start
420
- generate_configuration_file
421
- if !index_exists?
422
- generate_index
423
- end
424
- end
425
-
426
- ...
393
+ ```ruby
394
+ require "daemon_controller"
395
+
396
+ class SearchServer
397
+ SEARCH_SERVER_PORT = 1234
398
+
399
+ def initialize
400
+ @controller = DaemonController.new(
401
+ identifier: "Sphinx search server",
402
+ start_command: "searchd -c config/sphinx.conf",
403
+ before_start: method(:before_start),
404
+ ping_command: [:tcp, "localhost", SEARCH_SERVER_PORT],
405
+ pid_file: "tmp/pids/sphinx.pid",
406
+ log_file: "log/sphinx.log")
407
+ end
408
+
409
+ def query(search_terms)
410
+ socket = @controller.connect do
411
+ TCPSocket.new("localhost", SEARCH_SERVER_PORT)
427
412
  end
413
+ send_query(socket, search_terms)
414
+ retrieve_results(socket)
415
+ end
416
+
417
+ private
418
+ def before_start
419
+ generate_configuration_file
420
+ if !index_exists?
421
+ generate_index
422
+ end
423
+ end
424
+
425
+ # ...
426
+ end
427
+ ```
428
428
 
429
- Notice the `:before_start` option. We pass a block of code which is to be run,
429
+ Notice the `before_start:` option. We pass a block of code which is to be run,
430
430
  just before the daemon is started. This block, along with starting the daemon,
431
431
  is completely serialized. That is, if you're inside the block, then it's
432
432
  guaranteed that no other process is running this block at the same time as well.
@@ -498,5 +498,7 @@ synchronization. This has a few implications:
498
498
  API documentation
499
499
  =================
500
500
 
501
- Detailed API documentation is available in the form of inline comments in
502
- `lib/daemon_controller.rb`.
501
+ Detailed API documentation is available here:
502
+ - [Configuration options](doc/OPTIONS.md)
503
+ - [Stop flow](doc/STOP_FLOW.md)
504
+ - Inline comments in `lib/daemon_controller.rb`.
@@ -22,7 +22,7 @@
22
22
  # THE SOFTWARE.
23
23
 
24
24
  class DaemonController
25
- MAJOR = 2
25
+ MAJOR = 3
26
26
  MINOR = 0
27
27
  TINY = 0
28
28
  VERSION_STRING = "#{MAJOR}.#{MINOR}.#{TINY}"