dyn-ruby-win32daemon 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -39
  3. data/bin/dyn-daemon +82 -48
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f746aa523cf1d3554f7d7e0a250b2e0c7bba3df7
4
- data.tar.gz: aab6aa93a891af947d55d8c04651e6f6c0e1c02c
3
+ metadata.gz: 3c349c753ae751c89d130b86d40b32dbacce2f8f
4
+ data.tar.gz: 750b26cfa474661a03c6a20a0fb72edd6b6cb128
5
5
  SHA512:
6
- metadata.gz: 4a7e8a1775e7a90efe33ab44576c993dce720efb5dd93d8d6a0f642d9a4d532f7bdef29d4fcdc3ea1896b0efc2566fcd66434c51b38c3c2485b461ec714f9d42
7
- data.tar.gz: ce51d5f07ceaef1dbba7da7af2c39da5ebb4ddd04fb931a9bb41dac73e6ff58b80d749a05260560580fde990ff8989a2865605bbbffdcb8ccf3ef5e29053d57c
6
+ metadata.gz: 72232eb1742a29b560597adf8e728be138e25138e08701af779777756a84548ba606aa3f5723ac0f1472c7ac035edcdd4ff7496bcfabe1edfece9a8aa3e132b7
7
+ data.tar.gz: 4742ecdfdda8667c55c41ce768dfbba1f5810bff0f03cb0cd1cbcd95b356bf9be90c62877df67975f60125c6743863db41030cce6d0bb1fa01501fe5a7cae7da
data/README.md CHANGED
@@ -1,39 +1 @@
1
- # DynTask
2
-
3
- First of all, inspiration DynTask comes from the filewatcher project. The goal is a bit different since the goal is to provide a very basic system to manage chainable tasks.
4
-
5
-
6
- ## Kinds of task
7
-
8
- when depending on source (and/or output) file or content to be copied in some particular path, one may be interested in:
9
-
10
- * local task: everything is executed inside the same computer. This allows to write task in any path different from the source file path.
11
- * remote task: when using docker or dropbox-like tools, a synchronized task can be executed in a different computer or docker container. As a constraint, the source (and/or output) file path and the task file path have to be defined relatively to a common root independently in any synchronized computers supposed to execute the tasks. Obviously, the task file and source file can be in the same directory which is the simplest case.
12
-
13
- The goal of such approach is to watch only one folder containing task file with predefined extension and not subdirectories which makes the watching less reactive.
14
-
15
- ## Main actions to perform
16
-
17
- * dyn
18
- * dyn-cli
19
- * pdflatex
20
- * pandoc
21
-
22
-
23
- ## Examples
24
-
25
- ```{bash}
26
- ## To specify a folder to watch with specific tasks
27
- dyntask-init default <dyndoc-project-folder>:dyn,pandoc,dyn_cli
28
-
29
- ## Optional for pandoc task
30
- dyntask-init pandoc-extra dir --force /dyndoc-library/pandoc-extra
31
- ##
32
- dyntask-init pandoc-extra wget
33
- ```
34
-
35
- ## How this works
36
-
37
- * add_task: to push task
38
- * save_tasks: to save all the pushed tasks
39
- * read_tasks: read first task and pop to the stack of tasks
1
+ # Dyn Win32daemon
@@ -1,65 +1,99 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "fileutils"
3
- SRV=ARGV[0].strip
4
- exit! unless ["srv","dyntask"].include? SRV
5
- CMD={ "srv" => "dyn-srv", "dyntask" => "dyntask-server"}
6
- FileUtils.mkdir_p File.join(ENV["USERPROFILE"],"dyndoc","log")
7
- DYN_DAEMON_LOG_FILE = File.join(ENV["USERPROFILE"],"dyndoc","log","win32daemon_")+SRV+".log"
8
- DYN_DAEMON_DIR = File.dirname `where ruby`.strip
3
+ SRV=(ARGV[0] || "help").strip
4
+ exit! unless ["srv","dyntask","help","status","list"].include? SRV
5
+ CMD={ "srv" => "dyn-srv", "dyntask" => "dyntask-server"}[SRV]
6
+ if CMD
7
+ FileUtils.mkdir_p File.join(ENV["USERPROFILE"],"dyndoc","log")
8
+ DYN_DAEMON_LOG_FILE = File.join(ENV["USERPROFILE"],"dyndoc","log","")+CMD+".log"
9
+ DYN_DAEMON_DIR = File.dirname `where ruby`.strip
10
+ end
9
11
 
10
- require 'win32/daemon'
11
- require 'win32/process'
12
- include Win32
12
+ unless RUBY_PLATFORM =~ /mswin|mingw/i
13
+ puts "Only available for Windows!"
14
+ exit!
15
+ end
13
16
 
14
- class DynDaemon < Daemon
17
+ case SRV
18
+ when "help"
19
+ puts <<-DOC
20
+ Service helpers to launch dyn-srv or dyntask daemon.
21
+ Usage:
22
+ dyn-daemon srv|dyntask new|load => create when not existing the service
23
+ dyn-daemon srv|dyntask delete|unload => unload existing service
24
+ dyn-daemon srv|dyntask start/stop => start/stop the service
25
+ dyn-daemon srv|dyntask log => to watch log files
15
26
 
16
- def service_init
17
- File.open(DYN_DAEMON_LOG_FILE, 'a'){ |f| f.puts "Initializing service #{Time.now}" }
27
+ dyn-daemon status => status of dyntask service
28
+ dyn-daemon list => echo
29
+ DOC
30
+ when "status"
31
+ require 'sys/proctable'
32
+ msg={"dyn-srv" => "","dyntask-server" => ""}
33
+ msg.keys.each do |srv|
34
+ Sys::ProcTable.ps{ |s| msg[srv] << "["+s.pid.to_s+"] "+s.cmdline if s.pid != Process.pid and s.cmdline =~ /#{srv}/ }
35
+ end
36
+ puts (msg["dyn-srv"].empty? ? "Stopped" : "Running") + "|" + (msg["dyntask-server"].empty? ? "Stopped" : "Running")
37
+ else
18
38
 
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
39
+ require 'win32/daemon'
40
+ require 'win32/process'
41
+ include Win32
22
42
 
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
43
+ class DynDaemon < Daemon
44
+
45
+ def service_init
46
+ File.open(DYN_DAEMON_LOG_FILE, 'a'){ |f| f.puts "Initializing service #{Time.now}" }
47
+
48
+ @server_pid = Process.spawn CMD, :chdir => DYN_DAEMON_DIR, :err => [DYN_DAEMON_LOG_FILE, 'a']
49
+ File.open(DYN_DAEMON_LOG_FILE, 'a'){ |f| f.puts @server_pid.inspect }
50
+ end
51
+
52
+ def service_main
53
+ File.open(DYN_DAEMON_LOG_FILE, 'a'){ |f| f.puts "Service is running #{Time.now} with pid #{@server_pid}" }
54
+ while running?
55
+ sleep 10
56
+ end
27
57
  end
28
- end
29
58
 
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!
59
+ def service_stop
60
+ File.open(DYN_DAEMON_LOG_FILE, 'a'){ |f| f.puts "Stopping server thread #{Time.now}" }
61
+ system "taskkill /PID #{@server_pid} /T /F"
62
+ Process.waitall
63
+ File.open(DYN_DAEMON_LOG_FILE, 'a'){ |f| f.puts "Service stopped #{Time.now}" }
64
+ exit!
65
+ end
36
66
  end
37
- end
38
67
 
39
- action = ARGV[1] || "status"
40
68
 
41
- case action
42
- when "start"
43
- begin
44
- DynDaemon.mainloop
45
- rescue Exception => e
46
- File.open(DYN_DAEMON_LOG_FILE,'a+'){ |f| f.puts " ***Daemon failure #{Time.now} exception=#{e.inspect}\n#{e.backtrace.join($/)}" }
47
- raise
48
- end
49
- when "stop"
50
- require 'sys/proctable'
69
+ action = ARGV[1] || "status"
70
+
71
+ case action
72
+ when "start"
73
+ begin
74
+ DynDaemon.mainloop
75
+ rescue Exception => e
76
+ File.open(DYN_DAEMON_LOG_FILE,'a+'){ |f| f.puts " ***Daemon failure #{Time.now} exception=#{e.inspect}\n#{e.backtrace.join($/)}" }
77
+ raise
78
+ end
79
+ when "stop"
80
+ require 'sys/proctable'
51
81
 
52
- pids = []
82
+ pids = []
53
83
 
54
- Sys::ProcTable.ps{ |s| pids.push(s.pid) if s.cmdline =~ /#{SRV}/ }
84
+ Sys::ProcTable.ps{ |s| pids.push(s.pid) if s.cmdline =~ /#{SRV}/ }
55
85
 
56
- pids -= [Process.pid]
57
- unless pids.empty?
58
- print "Kill process with pid #{pids.last}"
59
- res=Process.kill(9,pids.last)
60
- puts " => "+(res == 1 ? "Ok!" : "Failed!")
86
+ pids -= [Process.pid]
87
+ unless pids.empty?
88
+ print "Kill process with pid #{pids.last}"
89
+ res=Process.kill(9,pids.last)
90
+ puts " => "+(res == 1 ? "Ok!" : "Failed!")
91
+ end
92
+ when "status"
93
+ require 'sys/proctable'
94
+ Sys::ProcTable.ps{ |s| puts "["+s.pid.to_s+"] "+s.cmdline if s.pid != Process.pid and s.cmdline =~ /#{SRV}/ }
95
+ when "log"
96
+ puts File.read(DYN_DAEMON_LOG_FILE)
61
97
  end
62
- when "status"
63
- require 'sys/proctable'
64
- Sys::ProcTable.ps{ |s| puts "["+s.pid.to_s+"] "+s.cmdline if s.pid != Process.pid and s.cmdline =~ /#{SRV}/ }
98
+
65
99
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dyn-ruby-win32daemon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - CQLS
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-16 00:00:00.000000000 Z
11
+ date: 2016-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: win32-service