daemons 1.1.9 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +1 -1
  3. data/README.md +207 -0
  4. data/Releases +85 -24
  5. data/examples/call/call.rb +13 -16
  6. data/examples/call/call_monitor.rb +13 -17
  7. data/examples/daemonize/daemonize.rb +4 -8
  8. data/examples/run/ctrl_crash.rb +0 -1
  9. data/examples/run/ctrl_custom_logfiles.rb +18 -0
  10. data/examples/run/ctrl_exec.rb +0 -1
  11. data/examples/run/ctrl_exit.rb +0 -1
  12. data/examples/run/ctrl_keep_pid_files.rb +1 -3
  13. data/examples/run/ctrl_monitor.rb +0 -1
  14. data/examples/run/ctrl_monitor_multiple.rb +17 -0
  15. data/examples/run/ctrl_monitor_nocrash.rb +15 -0
  16. data/examples/run/ctrl_multiple.rb +0 -1
  17. data/examples/run/ctrl_ontop.rb +0 -1
  18. data/examples/run/ctrl_optionparser.rb +5 -7
  19. data/examples/run/ctrl_proc.rb +8 -9
  20. data/examples/run/ctrl_proc_multiple.rb +4 -6
  21. data/examples/run/ctrl_proc_rand.rb +2 -4
  22. data/examples/run/ctrl_proc_simple.rb +0 -1
  23. data/examples/run/myserver.rb +0 -1
  24. data/examples/run/myserver_crashing.rb +5 -5
  25. data/examples/run/myserver_exiting.rb +2 -2
  26. data/examples/run/myserver_hanging.rb +4 -5
  27. data/examples/run/myserver_slowstop.rb +5 -6
  28. data/lib/daemons/application.rb +235 -229
  29. data/lib/daemons/application_group.rb +115 -100
  30. data/lib/daemons/change_privilege.rb +2 -4
  31. data/lib/daemons/cmdline.rb +75 -62
  32. data/lib/daemons/controller.rb +36 -54
  33. data/lib/daemons/daemonize.rb +74 -75
  34. data/lib/daemons/etc_extension.rb +3 -4
  35. data/lib/daemons/exceptions.rb +11 -13
  36. data/lib/daemons/monitor.rb +57 -77
  37. data/lib/daemons/pid.rb +26 -56
  38. data/lib/daemons/pidfile.rb +49 -44
  39. data/lib/daemons/pidmem.rb +5 -9
  40. data/lib/daemons/reporter.rb +54 -0
  41. data/lib/daemons/syslogio.rb +240 -0
  42. data/lib/daemons/version.rb +3 -0
  43. data/lib/daemons.rb +87 -77
  44. metadata +111 -46
  45. data/README +0 -214
  46. data/Rakefile +0 -90
  47. data/TODO +0 -2
  48. data/setup.rb +0 -1360
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cb08e3c11dd04ba70fdfa9a27e41d004839a48318b77bf7edb5e93976de129f7
4
+ data.tar.gz: 683d0ed93f6a41378a3ed585035b773f4008a147542ab6f29281374aa746ccf9
5
+ SHA512:
6
+ metadata.gz: 9a8743b8307c977149bcfbb1d6b6b36897a1c750ef63a25f7225d7b1774eaffd128843a1d92d626c3062ff680066831214eed8dc3523216b61f15b355701f4d5
7
+ data.tar.gz: de074de7aa4ba81a507d9b06f900c2eb044628ceb3a02b5cf4abb717dfdbf6df52c56f709caa85b223d8a18b9da2c0057017074089832412a231499ef050dcde
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2005-2012 Thomas Uehlinger
1
+ Copyright (c) 2005-2021 Thomas Uehlinger, 2014-2016 Aaron Stone
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person
4
4
  obtaining a copy of this software and associated documentation
data/README.md ADDED
@@ -0,0 +1,207 @@
1
+ # Ruby Daemons
2
+
3
+ [![Build Status](https://travis-ci.org/thuehlinger/daemons.svg?branch=master)](https://travis-ci.org/thuehlinger/daemons)[![Code Climate](https://codeclimate.com/github/acuppy/daemons/badges/gpa.svg)](https://codeclimate.com/github/acuppy/daemons)[![Test Coverage](https://circleci.com/gh/acuppy/daemons.svg?style=shield&circle-token=a4f96fd41f7682661d6543e30207427ac8870c0d)](https://circleci.com/gh/acuppy/daemons)
4
+
5
+ Daemons provides an easy way to wrap existing ruby scripts (for example a self-written server)
6
+ to be _run as a daemon_ and to be _controlled by simple start/stop/restart commands_.
7
+
8
+ If you want, you can also use daemons to _run blocks of ruby code in a daemon process_ and to control
9
+ these processes from the main application.
10
+
11
+ Besides this basic functionality, daemons offers many advanced features like _exception backtracing_
12
+ and logging (in case your ruby script crashes) and _monitoring_ and automatic restarting of your processes
13
+ if they crash.
14
+
15
+ ## Basic Usage
16
+
17
+ You can use Daemons in four different ways:
18
+
19
+ ### 1. Create wrapper scripts for your server scripts or applications
20
+
21
+ Layout: suppose you have your self-written server `myserver.rb`:
22
+
23
+ ``` ruby
24
+ # this is myserver.rb
25
+ # it does nothing really useful at the moment
26
+
27
+ loop do
28
+ sleep(5)
29
+ end
30
+ ```
31
+
32
+ To use `myserver.rb` in a production environment, you need to be able to
33
+ run `myserver.rb` in the _background_ (this means detach it from the console, fork it
34
+ in the background, release all directories and file descriptors).
35
+
36
+ Just create `myserver_control.rb` like this:
37
+
38
+ ``` ruby
39
+ # this is myserver_control.rb
40
+ require 'daemons'
41
+
42
+ Daemons.run('myserver.rb')
43
+ ```
44
+
45
+ And use it like this from the console:
46
+
47
+ ``` sh
48
+ $ ruby myserver_control.rb start
49
+ (myserver.rb is now running in the background)
50
+ $ ruby myserver_control.rb restart
51
+ (...)
52
+ $ ruby myserver_control.rb stop
53
+ ```
54
+
55
+ For testing purposes you can even run `myserver.rb` _without forking_ in the background:
56
+
57
+ ``` sh
58
+ $ ruby myserver_control.rb run
59
+ ```
60
+
61
+ An additional nice feature of Daemons is that you can pass _additional arguments_ to the script that
62
+ should be daemonized by seperating them by two _hyphens_:
63
+
64
+ ``` sh
65
+ $ ruby myserver_control.rb start -- --file=anyfile --a_switch another_argument
66
+ ```
67
+
68
+ ### 2. Create wrapper scripts that include your server procs
69
+
70
+ Layout: suppose you have some code you want to run in the background and control that background process
71
+ from a script:
72
+
73
+ ``` ruby
74
+ # this is your code
75
+ # it does nothing really useful at the moment
76
+
77
+ loop do
78
+ sleep(5)
79
+ end
80
+ ```
81
+
82
+ To run this code as a daemon create `myproc_control.rb` like this and include your code:
83
+
84
+ ``` ruby
85
+ # this is myproc_control.rb
86
+ require 'daemons'
87
+
88
+ Daemons.run_proc('myproc.rb') do
89
+ loop do
90
+ sleep(5)
91
+ end
92
+ end
93
+ ```
94
+
95
+ And use it like this from the console:
96
+
97
+ ``` sh
98
+ $ ruby myproc_control.rb start
99
+ (myproc.rb is now running in the background)
100
+ $ ruby myproc_control.rb restart
101
+ (...)
102
+ $ ruby myproc_control.rb stop
103
+ ```
104
+
105
+ For testing purposes you can even run `myproc.rb` _without forking_ in the background:
106
+
107
+ ``` sh
108
+ $ ruby myproc_control.rb run
109
+ ```
110
+
111
+ ### 3. Control a bunch of daemons from another application
112
+
113
+ Layout: you have an application `my_app.rb` that wants to run a bunch of
114
+ server tasks as daemon processes.
115
+
116
+ ``` ruby
117
+ # this is my_app.rb
118
+ require 'daemons'
119
+
120
+ task1 = Daemons.call(:multiple => true) do
121
+ # first server task
122
+
123
+ loop do
124
+ conn = accept_conn()
125
+ serve(conn)
126
+ end
127
+ end
128
+
129
+ task2 = Daemons.call do
130
+ # second server task
131
+
132
+ loop do
133
+ something_different()
134
+ end
135
+ end
136
+
137
+ # the parent process continues to run
138
+
139
+ # we can even control our tasks, for example stop them
140
+ task1.stop
141
+ task2.stop
142
+
143
+ exit
144
+ ```
145
+
146
+ ### 4. Daemonize the currently running process
147
+
148
+ Layout: you have an application `my_daemon.rb` that wants to run as a daemon
149
+ (but without the ability to be controlled by daemons via start/stop commands)
150
+
151
+ ``` ruby
152
+ # this is my_daemons.rb
153
+ require 'daemons'
154
+
155
+ # Initialize the app while we're not a daemon
156
+ init()
157
+
158
+ # Become a daemon
159
+ Daemons.daemonize
160
+
161
+ # The server loop
162
+ loop do
163
+ conn = accept_conn()
164
+ serve(conn)
165
+ end
166
+ ```
167
+
168
+ For further documentation, refer to the module documentation of Daemons.
169
+
170
+ ## Displaying daemon status
171
+
172
+ When daemonizing a process using a wrapper script, as examples 1 and 2 above,
173
+ the status can be shown using
174
+
175
+ ``` sh
176
+ $ ruby myproc_control.rb status
177
+ ```
178
+
179
+ By default this will display whether or not the daemon is running and, if it
180
+ is, its PID.
181
+
182
+ A custom message can be shown with
183
+
184
+ ``` ruby
185
+ def custom_show_status(app)
186
+ # Display the default status information
187
+ app.default_show_status
188
+
189
+ puts
190
+ puts "PS information"
191
+ system("ps -p #{app.pid.pid.to_s}")
192
+
193
+ puts
194
+ puts "Size of log files"
195
+ system("du -hs /path/to/logs")
196
+ end
197
+
198
+ Daemons.run('myserver.rb', { show_status_callback: :custom_show_status })
199
+ ```
200
+
201
+ ## Documentation
202
+
203
+ Documentation can be found at <http://www.rubydoc.info/gems/daemons>.
204
+
205
+ ## Author
206
+
207
+ Written 2005-2021 by Thomas Uehlinger, 2014-2016 by Aaron Stone.
data/Releases CHANGED
@@ -1,13 +1,74 @@
1
1
  = Daemons Release History
2
2
 
3
+ == Release 1.4.1: August 26, 2021
4
+
5
+ * Fix :proc mode (pass &block explicitly) (thanks to Graham Rogers)
6
+ * Fix style of REAMDE.md
7
+
8
+ == Release 1.4.0: May 1, 2021
9
+
10
+ * Allow for customization which signals are sent to stop process (thanks to philister)
11
+ * Resolves mismatched indentations (thanks to Luis M Rodriguez)
12
+ * Allow to use pry-byebug 3.8.0 (thanks to kamipo)
13
+
14
+ == Release 1.3.1: December 14, 2018
15
+
16
+ * Fix undefined local variable or method `pid_delimiter'
17
+
18
+ == Release 1.3.0: December 10, 2018
19
+
20
+ * Make logging more configurable.
21
+ * Add configuration options for pid file delimters, force_kill_waittime
22
+ * All status callback to be anything callable.
23
+
24
+ == Release 1.2.6: December 24, 2017
25
+
26
+ * Add links to rubydoc.info documentation.
27
+
28
+ == Release 1.2.5: October 22, 2017
29
+
30
+ * In Application#stop, call zap, not cleanup on the pidfile (thanks to wevanscfi)
31
+ * Use File.expand_path on and output and log files (thanks to Dave Harris)
32
+
33
+ == Release 1.2.4: August 1, 2016
34
+
35
+ * add :shush option
36
+ * add :monitor_interval option
37
+ * add :log_output_syslog option
38
+
39
+ == Release 1.2.3: June 25, 2015
40
+
41
+ * fix: ApplicationGroup now waits on subprocesses in start_all (thanks to tobithiel)
42
+
43
+ == Release 1.2.2: March 17, 2015
44
+
45
+ * fix 100% CPU usage bug when using monitor mode.
46
+
47
+ == Release 1.2.1: March 10, 2015
48
+
49
+ * increase version number to be able to re-push to rubygems
50
+
51
+ == Release 1.2.0: March 8, 2015
52
+
53
+ * add options for custum log file names.
54
+ * change pid file name scheme to "#progname_num#{number}.pid" for multiple instances.
55
+ * fix call_as_daemon not saving the PID (thanks Roberto Plancarte)
56
+ * allow for custom statis messages (thanks to Joseph Haig)
57
+ * fix Pid.running? rescuing timeout exceptions (thanks to Geraud Boyer)
58
+ * monitor.rb/application.rb/application_group.rb: handle :monitor and :multiple in combination correctly
59
+ (thanks to Prakash Murthy).
60
+ * pidfile.rb: Handle invalid or empty pid files instead of returning pid 0 (thanks to Aaron Stone)
61
+ * run the whole gem through Rubocop (thanks to Aaron Stone)
62
+ * gem cleanup (thanks to Aaron Stone)
63
+
3
64
  == Release 1.1.9: August 10, 2012
4
65
 
5
- * daemonize.rb: do srand in the forked child process both in daemonize and call_as_daemon
66
+ * daemonize.rb: do srand in the forked child process both in daemonize and call_as_daemon
6
67
  (thanks to Andrew Havens).
7
68
 
8
69
  == Release 1.1.8: February 7, 2012
9
70
 
10
- * rename to daemonization.rb to daemonize.rb (and Daemonization to Daemonize) to
71
+ * rename to daemonization.rb to daemonize.rb (and Daemonization to Daemonize) to
11
72
  ensure compatibility.
12
73
 
13
74
  == Release 1.1.7: February 6, 2012
@@ -21,57 +82,57 @@
21
82
 
22
83
  == Release 1.1.5: December 19, 2011
23
84
 
24
- * Catch the case where the pidfile is empty but not deleted
85
+ * Catch the case where the pidfile is empty but not deleted
25
86
  and restart the app (thanks to Rich Healey)
26
87
 
27
88
  == Release 1.1.4: June 17, 2011
28
89
 
29
- * Do not change the umask to 0000 when daemonizing anymore, just leave it as it
90
+ * Do not change the umask to 0000 when daemonizing anymore, just leave it as it
30
91
  was (thanks to Jon Botelho).
31
92
 
32
93
  == Release 1.1.3: April 14, 2011
33
94
 
34
95
  * Fixed a bug in Application.stop: the cached pid number needs to
35
96
  be used to check for the status of a killed process (thanks to Jimmy Sieben).
36
-
97
+
37
98
  == Release 1.1.2: March 29, 2011
38
99
 
39
100
  * Fixed gemspec to include all needed files.
40
-
101
+
41
102
  == Release 1.1.1: March 29, 2011
42
103
 
43
- * Make the logging facilities work in :mode => :none (i.e. when calling
104
+ * Make the logging facilities work in :mode => :none (i.e. when calling
44
105
  Daemons.daemonize) (thanks to the input from Peter Hegedus).
45
-
106
+
46
107
  == Release 1.1.0: June 20, 2010
47
108
 
48
109
  * Honour the options[:app_name] in Daemons.daemonize (thanks to Ryan Tecco).
49
- * Included a new option :stop_proc to specify a proc that will be called when a
110
+ * Included a new option :stop_proc to specify a proc that will be called when a
50
111
  daemonized process receives a request to stop (thanks to Dave Dupre).
51
112
  * Only delete the pidfile if the current pid is the original pid (ghazel).
52
113
  * Start when restart but no application running (pcreux).
53
114
  * Silently continue if there is no pidfile (ghazel).
54
115
  * We now per default wait for processes to stop and
55
- kill them automatically it if they do not stop within a given time
56
- (force_kill_waittime). Use the option --no_wait to not wait for processes to
116
+ kill them automatically it if they do not stop within a given time
117
+ (force_kill_waittime). Use the option --no_wait to not wait for processes to
57
118
  stop.
58
119
  * Set log files mode to 0644 (mikehale).
59
120
  * Set pid file permissions to 0644 (mikehale).
60
121
  * Added ability to change process uid/gid (mikehale).
61
- * Fix for: If you happen to start a daemon from a process that has open file
62
- descriptors these will stay open. As it is daemonize.rb only closes ruby IO
122
+ * Fix for: If you happen to start a daemon from a process that has open file
123
+ descriptors these will stay open. As it is daemonize.rb only closes ruby IO
63
124
  objects (thanks to Han Holl).
64
125
  * New reload command (SIGHUP) (thanks to Michael Schuerig).
65
126
 
66
127
  == Release 1.0.10: March 21, 2008
67
128
 
68
- * By default, we now delete stray pid-files (i.e. pid-files which result for
69
- example from a killed daemon) automatically. This function can be deactivated
129
+ * By default, we now delete stray pid-files (i.e. pid-files which result for
130
+ example from a killed daemon) automatically. This function can be deactivated
70
131
  by passing :keep_pid_files => true as an option.
71
- * All pid files of :multiple daemons new get deleted correctly upon exit of the
132
+ * All pid files of :multiple daemons new get deleted correctly upon exit of the
72
133
  daemons (reported by Han Holl).
73
134
  * Use the signal 'KILL' instead of 'TERM' on Windows platforms.
74
- * Use exit! in trap('TERM') instead of exit when option :hard_exit is given
135
+ * Use exit! in trap('TERM') instead of exit when option :hard_exit is given
75
136
  (thanks to Han Holl).
76
137
  * Did some clarification on the exception log.
77
138
 
@@ -82,12 +143,12 @@
82
143
 
83
144
  == Release 1.0.8: September 24, 2007
84
145
 
85
- * new Pid.running? function. Checking whether a process exists by sending
146
+ * new Pid.running? function. Checking whether a process exists by sending
86
147
  signal '0' (thanks to Dru Nelson).
87
148
 
88
149
  == Release 1.0.7: July 7, 2007
89
150
 
90
- * Patch to fix wrong ARGV when using :exec (in def start_exec:
151
+ * Patch to fix wrong ARGV when using :exec (in def start_exec:
91
152
  Kernel.exec(script(), *(@app_argv || []))) (thanks to Alex McGuire).
92
153
 
93
154
  == Release 1.0.6: Mai 8, 2007
@@ -97,7 +158,7 @@
97
158
 
98
159
  == Release 1.0.5: February 24, 2007
99
160
 
100
- * Applied patch that makes daemons to use '/var/log' as logfile
161
+ * Applied patch that makes daemons to use '/var/log' as logfile
101
162
  directory if you use :dir_mode = :system (thanks to Han Holl).
102
163
  * Daemons should now work with Ruby 1.9 (at least the basic features).
103
164
 
@@ -105,7 +166,7 @@
105
166
 
106
167
  * Document the :log_output option (thanks to Andrew Kuklewicz).
107
168
  * Set STDOUT.sync = true when redirecting to a logfile (thanks to Andrew Kuklewicz).
108
- * Should now run also correctly when there is no working 'ps ax' on the system
169
+ * Should now run also correctly when there is no working 'ps ax' on the system
109
170
  (thanks to Daniel Kehoe).
110
171
 
111
172
  == Release 1.0.3: November 1, 2006
@@ -117,7 +178,7 @@
117
178
  * Changed the 'ps -ax' call back to 'ps ax'.
118
179
  * Fixed the documentation for the :normal :dir_mode.
119
180
  * As a default for Daemons.run_proc, the pid file is now saved in the current directory.
120
- * In :ontop mode for running a proc (this is equal to calling something like 'ruby ctrl_proc.rb run'),
181
+ * In :ontop mode for running a proc (this is equal to calling something like 'ruby ctrl_proc.rb run'),
121
182
  the proc now runs directly in the calling script, not in a forked process anymore (thanks to Paul Butcher).
122
183
  * Set $0 to app_name in the daemons (thanks to Ilya Novoselov).
123
184
 
@@ -131,7 +192,7 @@
131
192
 
132
193
  == Release 0.4.4: February 14, 2006
133
194
 
134
- * Several fixes that allow us to use the Daemons::Controller
195
+ * Several fixes that allow us to use the Daemons::Controller
135
196
  with a proc instead of wrapping a script file. This gives us all the
136
197
  PID file management, monitoring, command line options, etc. without having
137
198
  to specify a path to our script which can be tricky, especially when using
@@ -143,7 +204,7 @@
143
204
  on calling Daemons.run. This will be used to contruct the name of the pid files
144
205
  and log files. Defaults to the basename of the script. (thanks to Stephen R. Veit)
145
206
 
146
- * Bugfix: Handle the case where no controller options are given when calling Daemons,
207
+ * Bugfix: Handle the case where no controller options are given when calling Daemons,
147
208
  just options after "--". (thanks to Stephen R. Veit)
148
209
 
149
210
 
@@ -6,12 +6,10 @@ else
6
6
  begin; require 'rubygems'; rescue ::Exception; end
7
7
  end
8
8
 
9
-
10
9
  require 'daemons'
11
10
 
12
11
  testfile = File.expand_path(__FILE__) + '.log'
13
12
 
14
-
15
13
  # On the first call to <tt<call</tt>, an application group (accessible by <tt>Daemons.group</tt>)
16
14
  # will be created an the options will be kept within, so you only have to specify
17
15
  # <tt>:multiple</tt> once.
@@ -23,35 +21,34 @@ options = {
23
21
  :multiple => true
24
22
  }
25
23
 
26
-
27
24
  Daemons.call(options) do
28
- File.open(testfile, 'w') {|f|
29
- f.puts "test"
30
- }
25
+ File.open(testfile, 'w') do |f|
26
+ f.puts 'test'
27
+ end
31
28
 
32
- loop { puts "1"; sleep 5 }
29
+ loop { puts '1'; sleep 5 }
33
30
  end
34
- puts "first task started"
31
+ puts 'first task started'
35
32
 
36
33
  Daemons.call do
37
- loop { puts "2"; sleep 4 }
34
+ loop { puts '2'; sleep 4 }
38
35
  end
39
- puts "second task started"
36
+ puts 'second task started'
40
37
 
41
38
  # NOTE: this process will exit after 5 seconds
42
39
  Daemons.call do
43
- puts "3"
40
+ puts '3'
44
41
  sleep 5
45
42
  end
46
- puts "third task started"
43
+ puts 'third task started'
47
44
 
48
- puts "waiting 20 seconds..."
45
+ puts 'waiting 20 seconds...'
49
46
  sleep(20)
50
47
 
51
- # This call would result in an exception as it will try to kill the third process
48
+ # This call would result in an exception as it will try to kill the third process
52
49
  # which has already terminated by that time; but using the 'true' parameter forces the
53
50
  # stop_all procedure.
54
- puts "trying to stop all tasks..."
51
+ puts 'trying to stop all tasks...'
55
52
  Daemons.group.stop_all(true)
56
53
 
57
- puts "done"
54
+ puts 'done'
@@ -6,12 +6,10 @@ else
6
6
  begin; require 'rubygems'; rescue ::Exception; end
7
7
  end
8
8
 
9
-
10
9
  require 'daemons'
11
10
 
12
11
  testfile = File.expand_path(__FILE__) + '.log'
13
12
 
14
-
15
13
  # On the first call to <tt<call</tt>, an application group (accessible by <tt>Daemons.group</tt>)
16
14
  # will be created an the options will be kept within, so you only have to specify
17
15
  # <tt>:multiple</tt> once.
@@ -23,33 +21,31 @@ options = {
23
21
  :monitor => true
24
22
  }
25
23
 
26
-
27
24
  Daemons.call(options) do
28
- loop { puts "1"; sleep 20 }
25
+ loop { puts '1'; sleep 20 }
29
26
  end
30
- puts "first task started"
31
-
27
+ puts 'first task started'
32
28
 
33
29
  # NOTE: this process will exit after 5 seconds
34
30
  Daemons.call do
35
- File.open(testfile, 'a') {|f|
36
- f.puts "started..."
37
- puts "2"
38
-
31
+ File.open(testfile, 'a') do |f|
32
+ f.puts 'started...'
33
+ puts '2'
34
+
39
35
  sleep 5
40
36
 
41
- f.puts "...exit"
42
- }
37
+ f.puts '...exit'
38
+ end
43
39
  end
44
- puts "second task started"
40
+ puts 'second task started'
45
41
 
46
- puts "waiting 100 seconds..."
42
+ puts 'waiting 100 seconds...'
47
43
  sleep(100)
48
44
 
49
- # This call would result in an exception as it will try to kill the third process
45
+ # This call would result in an exception as it will try to kill the third process
50
46
  # which has already terminated by that time; but using the 'true' parameter forces the
51
47
  # stop_all procedure.
52
- puts "trying to stop all tasks..."
48
+ puts 'trying to stop all tasks...'
53
49
  Daemons.group.stop_all(true)
54
50
 
55
- puts "done"
51
+ puts 'done'
@@ -6,22 +6,18 @@ else
6
6
  begin; require 'rubygems'; rescue ::Exception; end
7
7
  end
8
8
 
9
-
10
-
11
9
  require 'daemons'
12
10
 
13
-
14
11
  options = {
15
12
  :log_output => true
16
13
  }
17
14
 
18
-
19
15
  testfile = File.expand_path(__FILE__) + '.txt'
20
16
 
21
17
  Daemons.daemonize(options)
22
18
 
23
- puts "some output..."
19
+ puts 'some output...'
24
20
 
25
- File.open(testfile, 'w') {|f|
26
- f.write("test")
27
- }
21
+ File.open(testfile, 'w') do |f|
22
+ f.write('test')
23
+ end
@@ -8,7 +8,6 @@ end
8
8
 
9
9
  require 'daemons'
10
10
 
11
-
12
11
  options = {
13
12
  :log_output => true,
14
13
  :backtrace => true
@@ -0,0 +1,18 @@
1
+ lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
2
+
3
+ if File.exist?(File.join(lib_dir, 'daemons.rb'))
4
+ $LOAD_PATH.unshift lib_dir
5
+ else
6
+ begin; require 'rubygems'; rescue ::Exception; end
7
+ end
8
+
9
+ require 'daemons'
10
+
11
+ options = {
12
+ :log_output => true,
13
+ :backtrace => true,
14
+ :output_logfilename => "custom_output.txt",
15
+ :logfilename => "custom_log.log"
16
+ }
17
+
18
+ Daemons.run(File.join(File.dirname(__FILE__), 'myserver_crashing.rb'), options)
@@ -8,7 +8,6 @@ end
8
8
 
9
9
  require 'daemons'
10
10
 
11
-
12
11
  options = {
13
12
  :mode => :exec
14
13
  }
@@ -8,7 +8,6 @@ end
8
8
 
9
9
  require 'daemons'
10
10
 
11
-
12
11
  options = {
13
12
  }
14
13
 
@@ -8,10 +8,8 @@ end
8
8
 
9
9
  require 'daemons'
10
10
 
11
-
12
11
  options = {
13
12
  :keep_pid_files => true
14
13
  }
15
14
 
16
-
17
- Daemons.run(File.join(File.dirname(__FILE__), 'myserver.rb'), options)
15
+ Daemons.run(File.join(File.dirname(__FILE__), 'myserver.rb'), options)
@@ -8,7 +8,6 @@ end
8
8
 
9
9
  require 'daemons'
10
10
 
11
-
12
11
  options = {
13
12
  :monitor => true
14
13
  }
@@ -0,0 +1,17 @@
1
+ lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
2
+
3
+ if File.exist?(File.join(lib_dir, 'daemons.rb'))
4
+ $LOAD_PATH.unshift lib_dir
5
+ else
6
+ begin; require 'rubygems'; rescue ::Exception; end
7
+ end
8
+
9
+ require 'daemons'
10
+
11
+ options = {
12
+ :multiple => true,
13
+ :monitor => true,
14
+ :log_output => true,
15
+ }
16
+
17
+ Daemons.run(File.join(File.dirname(__FILE__), 'myserver_crashing.rb'), options)
@@ -0,0 +1,15 @@
1
+ lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
2
+
3
+ if File.exist?(File.join(lib_dir, 'daemons.rb'))
4
+ $LOAD_PATH.unshift lib_dir
5
+ else
6
+ begin; require 'rubygems'; rescue ::Exception; end
7
+ end
8
+
9
+ require 'daemons'
10
+
11
+ options = {
12
+ :monitor => true
13
+ }
14
+
15
+ Daemons.run(File.join(File.dirname(__FILE__), 'myserver.rb'), options)