dyn-ruby-win32daemon 0.0.1 → 0.0.2
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 +4 -4
- data/bin/dyn-daemon +39 -40
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c787377080210db3adbd84ed6871e8195a89ada2
|
4
|
+
data.tar.gz: 3d1b786c61c83b54cc9c57e5a1028d8666c2b953
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e39713d212795d30fb1d09fb1f200887bdb20d2c07f56014a2aa5994bd3eafcc24c2df4dcb1720f0dc2d224ffcfd00fa403c3c71bde1b41f37106f22450c9d0
|
7
|
+
data.tar.gz: a96bff3d82c02be5928d6d70d98a4ffc771f5089b3e29de305ed4a8fa70f0f8fde3b7d7502fbee5cd6d526aff90f88c8f18732b1cd7de0b0c277f0686c851314
|
data/bin/dyn-daemon
CHANGED
@@ -1,46 +1,47 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require "fileutils"
|
3
|
-
SRV=ARGV[
|
4
|
-
exit unless ["
|
3
|
+
SRV=ARGV[0].strip
|
4
|
+
exit! unless ["srv","dyntask"].include? SRV
|
5
|
+
CMD={ "srv" => "dyn-srv", "dyntask" => "dyntask-server"}
|
5
6
|
FileUtils.mkdir_p File.join(ENV["USERPROFILE"],"dyndoc","log")
|
6
7
|
DYN_DAEMON_LOG_FILE = File.join(ENV["USERPROFILE"],"dyndoc","log","win32daemon_")+SRV+".log"
|
7
|
-
DYN_DAEMON_DIR=File.dirname `where ruby`.strip
|
8
|
+
DYN_DAEMON_DIR = File.dirname `where ruby`.strip
|
8
9
|
|
9
|
-
|
10
|
+
require 'win32/daemon'
|
11
|
+
require 'win32/process'
|
12
|
+
include Win32
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
def service_main
|
27
|
-
File.open(DYN_DAEMON_LOG_FILE, 'a'){ |f| f.puts "Service is running #{Time.now} with pid #{@server_pid}" }
|
28
|
-
while running?
|
29
|
-
sleep 10
|
30
|
-
endx
|
31
|
-
end
|
32
|
-
|
33
|
-
def service_stop
|
34
|
-
File.open(DYN_DAEMON_LOG_FILE, 'a'){ |f| f.puts "Stopping server thread #{Time.now}" }
|
35
|
-
system "taskkill /PID #{@server_pid} /T /F"
|
36
|
-
Process.waitall
|
37
|
-
File.open(DYN_DAEMON_LOG_FILE, 'a'){ |f| f.puts "Service stopped #{Time.now}" }
|
38
|
-
exit!
|
39
|
-
end
|
14
|
+
class DynDaemon < Daemon
|
15
|
+
|
16
|
+
def service_init
|
17
|
+
File.open(DYN_DAEMON_LOG_FILE, 'a'){ |f| f.puts "Initializing service #{Time.now}" }
|
18
|
+
|
19
|
+
@server_pid = Process.spawn CMD[SRV], :chdir => DYN_DAEMON_DIR, :err => [DYN_DAEMON_LOG_FILE, 'a']
|
20
|
+
File.open(DYN_DAEMON_LOG_FILE, 'a'){ |f| f.puts @server_pid.inspect }
|
21
|
+
end
|
22
|
+
|
23
|
+
def service_main
|
24
|
+
File.open(DYN_DAEMON_LOG_FILE, 'a'){ |f| f.puts "Service is running #{Time.now} with pid #{@server_pid}" }
|
25
|
+
while running?
|
26
|
+
sleep 10
|
40
27
|
end
|
28
|
+
end
|
41
29
|
|
42
|
-
|
30
|
+
def service_stop
|
31
|
+
File.open(DYN_DAEMON_LOG_FILE, 'a'){ |f| f.puts "Stopping server thread #{Time.now}" }
|
32
|
+
system "taskkill /PID #{@server_pid} /T /F"
|
33
|
+
Process.waitall
|
34
|
+
File.open(DYN_DAEMON_LOG_FILE, 'a'){ |f| f.puts "Service stopped #{Time.now}" }
|
35
|
+
exit!
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
action = ARGV[1] || "status"
|
43
40
|
|
41
|
+
case action
|
42
|
+
when "start"
|
43
|
+
begin
|
44
|
+
DynDaemon.mainloop
|
44
45
|
rescue Exception => e
|
45
46
|
File.open(DYN_DAEMON_LOG_FILE,'a+'){ |f| f.puts " ***Daemon failure #{Time.now} exception=#{e.inspect}\n#{e.backtrace.join($/)}" }
|
46
47
|
raise
|
@@ -50,14 +51,12 @@ when "stop"
|
|
50
51
|
|
51
52
|
pids = []
|
52
53
|
|
53
|
-
ProcTable.ps{ |s|
|
54
|
-
pids.push(s.pid) if s.cmdline =~ /#{SRV}/
|
55
|
-
}
|
54
|
+
Sys::ProcTable.ps{ |s| pids.push(s.pid) if s.cmdline =~ /#{SRV}/ }
|
56
55
|
|
56
|
+
pids -= [Process.pid]
|
57
|
+
p pids
|
57
58
|
p Process.kill(9,pids.last)
|
58
59
|
when "status"
|
59
60
|
require 'sys/proctable'
|
60
|
-
ProcTable.ps{ |s|
|
61
|
-
puts s.pid+"->"+s.cmdline if s.cmdline =~ /#{SRV}/
|
62
|
-
}
|
61
|
+
Sys::ProcTable.ps{ |s| puts s.pid.to_s+" -> "+s.cmdline if s.pid != Process.pid and s.cmdline =~ /#{SRV}/ }
|
63
62
|
end
|