winter 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.
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Winter
2
2
 
3
- Winter is a system for maintaining the configuration of java web applications with a specific focus on the Felix OSGi container. Simply create a `Winterfile` and describe the configuration of your application with the Winter DSL. You can then use the `winter` CLI tool to `winter build` the appliation. This will download all the necessary dependencies for your application. When the build is complete, you can run it with `winter start`.
3
+ [![Gem Version](https://badge.fury.io/rb/winter.png)](http://badge.fury.io/rb/winter)
4
+
5
+ Winter is a system for maintaining the configuration of java web applications with a specific focus on the Felix OSGi container. Simply create a `Winterfile` and describe the configuration of your application with the Winter DSL. You can then use the `winter` CLI tool to `winter build` the application. This will download all the necessary dependencies for your application. When the build is complete, you can run it with `winter start`.
4
6
 
5
7
  ## Installation from Rubygems
6
8
 
@@ -8,7 +10,7 @@ Winter is a system for maintaining the configuration of java web applications wi
8
10
 
9
11
  ## Installation from source
10
12
 
11
- $ git clone https://github.liveops.com/swilson/winter.git && cd winter
13
+ $ git clone git@github.com:liveops/winter.git && cd winter
12
14
  $ gem build winter.gemspec
13
15
  $ gem install winter*.gem
14
16
 
data/example/Winterfile CHANGED
@@ -17,7 +17,7 @@ end
17
17
  #lib 'org.apache.felix', 'org.apache.felix.configadmin', '1.4.0'
18
18
 
19
19
  # core OSGi artifacts
20
- felix 'org.apache.felix', 'org.apache.felix.main', '3.0.1'
20
+ felix 'org.apache.felix', 'org.apache.felix.main', '4.0.2'
21
21
  lib 'org.apache.felix', 'org.apache.felix.shell', '1.4.3'
22
22
  lib 'org.apache.felix', 'org.apache.felix.shell.remote', '1.1.2'
23
23
  lib 'org.apache.felix', 'org.apache.felix.scr', '1.6.2'
data/lib/winter/cli.rb CHANGED
@@ -47,9 +47,9 @@ module Winter
47
47
  end
48
48
 
49
49
  desc "start [Winterfile]", "Start the services in [Winterfile] "
50
- method_option :group, :desc => "Config group"
51
- #method_option :verbose, :desc => "Verbose maven output"
52
- method_option :debug, :desc => "Set log level to debug."
50
+ method_option :group, :desc => "Config group"
51
+ method_option :debug, :desc => "Set log level to debug."
52
+ method_option :daemonize, :desc => "Keep winter process running to trap system signals."
53
53
  method_option :console, :desc => "Send console output to [file]",
54
54
  :default => "/dev/null", :aliases => "--con"
55
55
  def start(winterfile='Winterfile')
@@ -67,16 +67,20 @@ module Winter
67
67
 
68
68
  desc "status", "Show status of available services"
69
69
  def status
70
+ running = 0
70
71
  s = Winter::Service.new
71
72
  s.status.each do |service, status|
72
73
  $LOG.info " #{service} : #{status}"
74
+ running += 1 if status =~ /Running/i
73
75
  end
76
+ $LOG.info "#{running} services are running."
74
77
  end
75
78
 
76
79
  desc "build [Winterfile]", "Build a service from a Winterfile"
77
80
  method_option :group, :desc => "Config group"
78
81
  method_option :verbose, :desc => "Verbose maven output"
79
82
  method_option :debug, :desc => "Set log level to debug."
83
+ method_option :clean, :desc => "Remove all artifacts before building."
80
84
  method_option :local, :desc => "Resolve dependencies only from local repository"
81
85
  def build( winterfile='Winterfile' )
82
86
  $LOG.level = Logger::DEBUG if options[:debug]
data/lib/winter/dsl.rb CHANGED
@@ -19,13 +19,8 @@ require 'json'
19
19
 
20
20
  require 'maven_pom'
21
21
 
22
- #require 'maven_gem/pom_fetcher'
23
- #require 'pom_spec'
24
-
25
- #require 'winter/bundles'
26
22
  require 'winter/constants'
27
23
  require 'winter/dependency'
28
- #require 'winter/json_util'
29
24
  require 'winter/logger'
30
25
  require 'winter/templates'
31
26
 
@@ -54,7 +49,7 @@ module Winter
54
49
  contents ||= File.open(winterfile.to_s, "rb"){|f| f.read}
55
50
 
56
51
  # set CWD to where the winterfile is located
57
- Dir.chdir (File.split(winterfile.to_s)[0]) do
52
+ Dir.chdir(File.split(winterfile.to_s)[0]) do
58
53
  instance_eval(contents)
59
54
  end
60
55
 
@@ -137,7 +132,6 @@ module Winter
137
132
 
138
133
  pom_file = MavenPom.fetch(pom)
139
134
  pom_spec = MavenPom.parse_pom(pom_file)
140
- #$LOG.debug pom_spec.dependencies
141
135
  pom_spec.dependencies.each do |dep|
142
136
  $LOG.debug dep
143
137
  if dep[:scope] == 'provided'
@@ -147,7 +141,6 @@ module Winter
147
141
  end
148
142
 
149
143
  def conf( dir )
150
- #$LOG.debug( dir << " " << File.join(WINTERFELL_DIR,RUN_DIR,'conf') )
151
144
  process_templates( dir, File.join(WINTERFELL_DIR,RUN_DIR,@name,'conf') )
152
145
  end
153
146
 
@@ -14,20 +14,62 @@
14
14
 
15
15
  require 'winter/constants'
16
16
  require 'winter/logger'
17
+ require 'winter/service/status'
18
+ include Process
17
19
 
18
20
  module Winter
19
21
  class Service
20
22
 
21
23
  def build(winterfile, options)
22
24
  #dsl = DSL.new options
23
- tmp = DSL.evaluate winterfile, options
24
- dependencies = tmp[:dependencies]
25
+ dsl = DSL.evaluate winterfile, options
26
+ dependencies = dsl[:dependencies]
27
+ service = dsl[:config]['service']
28
+ service_dir = File.join(WINTERFELL_DIR,RUN_DIR,service)
25
29
  #$LOG.debug dependencies
30
+
31
+ if options['clean'] and File.directory?(service_dir)
32
+ s = Winter::Service.new
33
+ stats = s.status
34
+ if stats.size == 0
35
+ FileUtils.rm_r service_dir
36
+ $LOG.debug "Deleted service directory #{service_dir}"
37
+ else
38
+ stats.each do |srvs,status|
39
+ if service == srvs && status !~ /running/i
40
+ FileUtils.rm_r service_dir
41
+ $LOG.debug "Deleted service directory #{service_dir}"
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ #I hate waiting so this is going to become faster.
48
+ max_threads = 10 #make this configurable later.
49
+ active_threads = 0
50
+ Signal.trap("CHLD") do
51
+ #Reap everything you possibly can.
52
+ begin
53
+ pid = waitpid(-1, Process::WNOHANG)
54
+ #puts "reaped #{pid}" if pid
55
+ active_threads -= 1 if pid
56
+ rescue Errno::ECHILD
57
+ break
58
+ end while pid
59
+ end
26
60
 
27
61
  dependencies.each do |dep|
28
- dep.getMaven
62
+ while (active_threads >= max_threads) do
63
+ #puts "Total active threads: #{active_threads}"
64
+ sleep 1
65
+ end
66
+ active_threads += 1
67
+ fork do
68
+ dep.getMaven
69
+ end
29
70
  end
71
+ #wait for stragglers
72
+ sleep 1 while (active_threads > 0)
30
73
  end
31
-
32
74
  end
33
75
  end
@@ -14,6 +14,7 @@
14
14
 
15
15
  require 'winter/constants'
16
16
  require 'winter/logger'
17
+ require 'winter/service/stop'
17
18
  require 'shellwords'
18
19
 
19
20
  # TODO This needs a larger refactor to make it more functional and less reliant
@@ -72,13 +73,77 @@ module Winter
72
73
  exit
73
74
  end
74
75
  pid_file = File.open(File.join(@service_dir, "pid"), "w")
75
- pid = fork do
76
+
77
+ # Normally, we'd just use Process.daemon for ruby 1.9, but for some
78
+ # reason the OSGi container we're using crashes when the CWD is changed
79
+ # to '/'. So, we'll just leave the CWD alone.
80
+ #Process.daemon(Dir.getwd,nil)
81
+
82
+ java_pid = fork do
76
83
  exec(java_cmd)
77
84
  end
85
+
86
+ pid = java_pid
87
+ pid = Process.pid if @config['daemonize']
78
88
  pid_file.write(pid)
79
89
  pid_file.close
80
90
 
81
91
  $LOG.info "Started #{@config['service']} (#{pid})"
92
+
93
+ if( @config['daemonize'] )
94
+ stay_resident(java_pid,winterfile)
95
+ end
96
+ end
97
+
98
+ def stay_resident( child_pid, winterfile )
99
+ interrupted = false
100
+
101
+ #TERM, CONT STOP HUP ALRM INT and KILL
102
+ Signal.trap("EXIT") do
103
+ $LOG.debug "EXIT Terminating... #{$$}"
104
+ interrupted = true
105
+ begin
106
+ stop winterfile
107
+ # not working...
108
+ # Process.getpgid child_pid
109
+ # Process.kill child_pid #skipped if process is alredy dead
110
+ rescue
111
+ $LOG.debug "Child pid (#{child_pid}) is already gone."
112
+ end
113
+ end
114
+ Signal.trap("HUP") do
115
+ $LOG.debug "HUP Terminating... #{$$}"
116
+ interrupted = true
117
+ end
118
+ Signal.trap("TERM") do
119
+ $LOG.debug "TERM Terminating... #{$$}"
120
+ interrupted = true
121
+ end
122
+ Signal.trap("KILL") do
123
+ $LOG.debug "KILL Terminating... #{$$}"
124
+ interrupted = true
125
+ end
126
+ Signal.trap("CONT") do
127
+ $LOG.debug "CONT Terminating... #{$$}"
128
+ interrupted = true
129
+ end
130
+ Signal.trap("ALRM") do
131
+ $LOG.debug "ALRM Terminating... #{$$}"
132
+ interrupted = true
133
+ end
134
+ Signal.trap("INT") do
135
+ $LOG.debug "INT Terminating... #{$$}"
136
+ interrupted = true
137
+ end
138
+ Signal.trap("CHLD") do
139
+ $LOG.debug "CHLD Terminating... #{$$}"
140
+ interrupted = true
141
+ end
142
+ #Process.detach(pid)
143
+
144
+ while 1
145
+ exit 0 if interrupted
146
+ end
82
147
  end
83
148
 
84
149
  def find_java
@@ -21,7 +21,8 @@ module Winter
21
21
  def status
22
22
  pid_files = Dir.glob(File.join(WINTERFELL_DIR,RUN_DIR, "**", "pid"))
23
23
  if( pid_files.length == 0 )
24
- $LOG.info "No services are running."
24
+ #$LOG.info "No services are running."
25
+ return {}
25
26
  end
26
27
 
27
28
  services = {}
@@ -32,7 +32,14 @@ module Winter
32
32
  File.open(f_pid, "r") do |f|
33
33
  pid = f.read().to_i
34
34
  end
35
- Process.kill("TERM", -Process.getpgid(pid))
35
+
36
+ begin
37
+ Process.getpgid pid
38
+ Process.kill("TERM", -Process.getpgid(pid))
39
+ rescue
40
+ $LOG.info( "Process #{pid} does not exist. Removing pid file." )
41
+ end
42
+
36
43
  begin
37
44
  File.unlink(f_pid)
38
45
  rescue
@@ -22,6 +22,9 @@ def process_templates(source_templates, destination_dir)
22
22
  dest = destination_dir + tmpl.sub(%r{#{source_templates}},"").sub(/\.erb$/, "")
23
23
  #$LOG.debug "Processing: #{dest}"
24
24
  FileUtils.mkpath File.dirname(dest)
25
- File.new(dest,'w').write(result)
25
+ File.open(dest,'w') do |f|
26
+ f.write(result)
27
+ f.close()
28
+ end
26
29
  end
27
30
  end
@@ -13,5 +13,5 @@
13
13
  # under the License.
14
14
 
15
15
  module Winter
16
- VERSION = "0.0.1"
16
+ VERSION = "0.0.2"
17
17
  end
data/spec/cli_spec.rb CHANGED
@@ -54,7 +54,7 @@ describe Winter do
54
54
  it "Build a service from a manifest" do
55
55
  begin
56
56
  lambda {
57
- args = ["build", "spec/sample_data/Winterfile"]
57
+ args = ["build", "spec/sample_data/Winterfile", "--clean"]
58
58
  cli = Winter::CLI.start( args )
59
59
  }.should_not raise_error
60
60
  Dir["run/default/libs"].include? "maven-dependency-plugin-2.5.jar"
@@ -67,7 +67,7 @@ describe Winter do
67
67
  context "start, status and stop " do
68
68
  it "Start, status and stop a service" do
69
69
  begin
70
- Dir.chdir (File.split("spec/sample_data/Winterfile")[0]) do
70
+ Dir.chdir(File.split("spec/sample_data/Winterfile")[0]) do
71
71
  lambda {
72
72
  Winter::CLI.start ["start" , "--debug"]
73
73
  Winter::CLI.start ["status"]
@@ -92,7 +92,7 @@ describe Winter do
92
92
  end
93
93
 
94
94
  after do
95
- Dir.chdir (File.split("spec/sample_data/Winterfile")[0]) do
95
+ Dir.chdir(File.split("spec/sample_data/Winterfile")[0]) do
96
96
  Winter::CLI.start ["stop"]
97
97
  end
98
98
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: winter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-24 00:00:00.000000000 Z
12
+ date: 2013-10-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler