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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/dyn-daemon +39 -40
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9865e3c62d77afeeb77227f4403b00e1affc9315
4
- data.tar.gz: 59f745d4d7e18172d2d386cc31df64f65b78d7b9
3
+ metadata.gz: c787377080210db3adbd84ed6871e8195a89ada2
4
+ data.tar.gz: 3d1b786c61c83b54cc9c57e5a1028d8666c2b953
5
5
  SHA512:
6
- metadata.gz: a090d105c804629ad0b6b95207113ca9f5f5ece176aa32c663888109f68e7c620d858792fbd3d46690461d53d8aaeaa9e82d7bea717bfdfc2c5183f00e338860
7
- data.tar.gz: 8201263ce061291ec86be7ea25795a1b2cb99a7123070144ed2ccc720aaf8b5738ffca61351294b11909a98f617db3393b7d587fe61ba12f7af903877dc2e517
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[1].strip
4
- exit unless ["dyn-srv","dyntask-srv"].include? SRV
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
- ACTION=ARGV[2] || "status"
10
+ require 'win32/daemon'
11
+ require 'win32/process'
12
+ include Win32
10
13
 
11
- case ACTION
12
- when "start"
13
- begin
14
- require 'win32/daemon'
15
- include Win32
16
-
17
- class DynDaemon < Daemon
18
-
19
- def service_init
20
- File.open(DYN_DAEMON_LOG_FILE, 'a'){ |f| f.puts "Initializing service #{Time.now}" }
21
-
22
- @server_pid = Process.spawn 'dyntask-server', :chdir => DYN_DAEMON_DIR, :err => [DYN_DAEMON_LOG_FILE, 'a']
23
- File.open(DYN_DAEMON_LOG_FILE, 'a'){ |f| f.puts @server_pid.inspect }
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
- DynDaemon.mainloop
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dyn-ruby-win32daemon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - CQLS