• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

"yadaemon.rb" is my daemon wrapper class to protect the multiple process invocation.


Commit MetaInfo

Revisão1425596385054f3a66ec425c64bd057df793bc22 (tree)
Hora2011-01-29 01:25:53
AutorYasuhiro ABE <yasundial@user...>
CommiterYasuhiro ABE

Mensagem de Log

Added force_stop method for emergency stop function.

Mudança Sumário

Diff

--- a/sample/change_euid.rb
+++ b/sample/change_euid.rb
@@ -19,6 +19,9 @@ daemon = YaDaemon.new(appname,"#{appname}.pid","/tmp", opts)
1919 if ARGV[0] == "restart"
2020 begin
2121 daemon.stop
22+ while daemon.check_proc
23+ sleep 1
24+ end
2225 puts "running process was terminated."
2326 rescue
2427 puts $!
@@ -27,6 +30,9 @@ if ARGV[0] == "restart"
2730 elsif ARGV[0] == "stop"
2831 begin
2932 daemon.stop
33+ while daemon.check_proc
34+ sleep 1
35+ end
3036 puts "running process was terminated."
3137 rescue
3238 puts $!
@@ -47,4 +53,4 @@ daemon.run do |pid|
4753 sleep 5
4854 end
4955 end
50-exit(1)
56+puts "another daemon is already running" if daemon.running
--- a/sample/start_stop.rb
+++ b/sample/start_stop.rb
@@ -17,6 +17,9 @@ daemon = YaDaemon.new(appname,"#{appname}.pid","/tmp", opts)
1717 if ARGV[0] == "restart"
1818 begin
1919 daemon.stop
20+ while daemon.check_proc
21+ sleep 1
22+ end
2023 puts "running process was terminated."
2124 rescue
2225 puts $!
@@ -25,6 +28,9 @@ if ARGV[0] == "restart"
2528 elsif ARGV[0] == "stop"
2629 begin
2730 daemon.stop
31+ while daemon.check_proc
32+ sleep 1
33+ end
2834 puts "running process was terminated."
2935 rescue
3036 puts $!
@@ -45,3 +51,4 @@ daemon.run do |pid|
4551 sleep 5
4652 end
4753 end
54+puts "another daemon is already running" if daemon.running
--- a/yadaemon.rb
+++ b/yadaemon.rb
@@ -133,7 +133,7 @@
133133 # See the License for the specific language governing permissions and
134134 # limitations under the License.
135135 #
136-#
136+
137137 # It's a utility class to process common tasks.
138138 # These methods should be tested by the unit test script.
139139 #
@@ -362,37 +362,40 @@ class YaDaemon
362362 logit "run: return"
363363 end
364364
365+ ## safelly
365366 def stop
366367 logit "stop: called"
367368
368- ## overwrite @stopfile
369369 create_stop_file()
370-
370+ end
371+
372+ def force_stop
371373 if not check_proc
372- logit "stop: this process has already stopped."
374+ logit "force_stop: this process has already stopped."
373375 return
374376 end
375377 pid = get_pid
376378 ## case 1
377379 if pid == $$
380+ create_stop_file()
378381 exit(0)
379382 end
380383 ## case 2
381384 if pid > 0
382385 n = Process::kill(15, pid)
383386 if n > 0
384- logit "stop: the terminate signal succesfully sent."
387+ logit "force_stop: the terminate signal succesfully sent."
385388 else
386- logit "stop: failed to sent the terminate signal."
389+ logit "force_stop: failed to sent the terminate signal."
387390 end
388391 while check_proc
389392 logit "stop: waiting terminate process, pid=#{pid}."
390393 sleep 3
391394 end
392395 else
393- logit "stop: failed to get my pid number"
396+ logit "force_stop: failed to get my pid number"
394397 end
395- logit "stop: return"
398+ logit "force_stop: return"
396399 end
397400
398401 ## change privileges using from run method, but place here for unit test.