winter 0.0.1
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/.gitignore +21 -0
- data/.rbenv-version +1 -0
- data/.rspec +1 -0
- data/Gemfile +15 -0
- data/LICENSE +75 -0
- data/NOTICE +10 -0
- data/README.md +235 -0
- data/Rakefile +10 -0
- data/bin/winter +19 -0
- data/example/Winterfile +33 -0
- data/example/conf/default/config.properties.erb +51 -0
- data/example/conf/default/logback.xml.erb +47 -0
- data/example/conf/default/logger_bundle.properties.erb +31 -0
- data/example/conf/default/wf_config.json +8 -0
- data/example/example.pom +401 -0
- data/lib/maven_pom.rb +109 -0
- data/lib/winter/cli.rb +89 -0
- data/lib/winter/constants.rb +32 -0
- data/lib/winter/dependency.rb +72 -0
- data/lib/winter/dsl.rb +180 -0
- data/lib/winter/logger.rb +29 -0
- data/lib/winter/service/build.rb +33 -0
- data/lib/winter/service/start.rb +174 -0
- data/lib/winter/service/status.rb +48 -0
- data/lib/winter/service/stop.rb +49 -0
- data/lib/winter/service/validate.rb +26 -0
- data/lib/winter/templates.rb +27 -0
- data/lib/winter/version.rb +17 -0
- data/lib/winter.rb +23 -0
- data/spec/cli_spec.rb +102 -0
- data/spec/sample_data/Winterfile +30 -0
- data/spec/sample_data/conf/default/config.properties.erb +51 -0
- data/spec/sample_data/conf/default/logger_bundle.properties.erb +31 -0
- data/spec/sample_data/conf/default/wf_config.json +8 -0
- data/spec/sample_data/example.pom +398 -0
- data/spec/sample_data/felix.pom +139 -0
- data/spec/spec_helper.rb +17 -0
- data/winter.gemspec +23 -0
- metadata +127 -0
@@ -0,0 +1,72 @@
|
|
1
|
+
# Copyright 2013 LiveOps, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
4
|
+
# use this file except in compliance with the License. You may obtain a copy
|
5
|
+
# of the License at:
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
12
|
+
# License for the specific language governing permissions and limitations
|
13
|
+
# under the License.
|
14
|
+
|
15
|
+
require 'winter/logger'
|
16
|
+
|
17
|
+
module Winter
|
18
|
+
|
19
|
+
class Dependency
|
20
|
+
attr_accessor :artifact
|
21
|
+
attr_accessor :group
|
22
|
+
attr_accessor :version
|
23
|
+
attr_accessor :repositories
|
24
|
+
attr_accessor :package
|
25
|
+
attr_accessor :offline
|
26
|
+
attr_accessor :transative
|
27
|
+
attr_accessor :destination
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
@artifact = nil
|
31
|
+
@group = nil
|
32
|
+
@version = 'LATEST'
|
33
|
+
@repositories = []
|
34
|
+
@package = 'jar'
|
35
|
+
@offline = false
|
36
|
+
@transative = false
|
37
|
+
@verbose = false
|
38
|
+
@destination = '.'
|
39
|
+
end
|
40
|
+
|
41
|
+
def getMaven
|
42
|
+
dest_file = File.join(@destination,"#{@artifact}-#{@version}.#{@package}")
|
43
|
+
|
44
|
+
c = "mvn org.apache.maven.plugins:maven-dependency-plugin:2.5:get "
|
45
|
+
c << " -DremoteRepositories=#{@repositories.join(',').shellescape}"
|
46
|
+
c << " -Dtransitive=#{@transative}"
|
47
|
+
c << " -Dartifact=#{@group.shellescape}:#{@artifact.shellescape}:#{@version.shellescape}:#{@package.shellescape}"
|
48
|
+
c << " -Ddest=#{dest_file.shellescape}"
|
49
|
+
|
50
|
+
if @offline
|
51
|
+
c << " --offline"
|
52
|
+
end
|
53
|
+
|
54
|
+
if !@verbose
|
55
|
+
#quiet mode is default
|
56
|
+
c << " -q"
|
57
|
+
end
|
58
|
+
|
59
|
+
result = system( c )
|
60
|
+
if result == false
|
61
|
+
$LOG.debug c
|
62
|
+
$LOG.error("Failed to retrieve artifact: #{@group}:#{@artifact}:#{@version}:#{@package}")
|
63
|
+
else
|
64
|
+
$LOG.info "#{@group}:#{@artifact}:#{@version}:#{@package}"
|
65
|
+
$LOG.debug dest_file
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
data/lib/winter/dsl.rb
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
# Copyright 2013 LiveOps, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
4
|
+
# use this file except in compliance with the License. You may obtain a copy
|
5
|
+
# of the License at:
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
12
|
+
# License for the specific language governing permissions and limitations
|
13
|
+
# under the License.
|
14
|
+
|
15
|
+
#This is the Domain Specific Language definition for the Winterfile
|
16
|
+
|
17
|
+
require 'open-uri'
|
18
|
+
require 'json'
|
19
|
+
|
20
|
+
require 'maven_pom'
|
21
|
+
|
22
|
+
#require 'maven_gem/pom_fetcher'
|
23
|
+
#require 'pom_spec'
|
24
|
+
|
25
|
+
#require 'winter/bundles'
|
26
|
+
require 'winter/constants'
|
27
|
+
require 'winter/dependency'
|
28
|
+
#require 'winter/json_util'
|
29
|
+
require 'winter/logger'
|
30
|
+
require 'winter/templates'
|
31
|
+
|
32
|
+
module Winter
|
33
|
+
class DSL
|
34
|
+
|
35
|
+
def initialize( options={} )
|
36
|
+
@name = 'default'
|
37
|
+
@groups = []
|
38
|
+
@repositories = []
|
39
|
+
@dependencies = []
|
40
|
+
@options = options
|
41
|
+
@config = {}
|
42
|
+
@directives = {}
|
43
|
+
@felix = nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.evaluate( winterfile, options={} )
|
47
|
+
# Must create instance for instance_eval to have correct scope
|
48
|
+
dsl = DSL.new options
|
49
|
+
res = dsl.eval_winterfile winterfile
|
50
|
+
validate(res)
|
51
|
+
end
|
52
|
+
|
53
|
+
def eval_winterfile( winterfile, contents=nil )
|
54
|
+
contents ||= File.open(winterfile.to_s, "rb"){|f| f.read}
|
55
|
+
|
56
|
+
# set CWD to where the winterfile is located
|
57
|
+
Dir.chdir (File.split(winterfile.to_s)[0]) do
|
58
|
+
instance_eval(contents)
|
59
|
+
end
|
60
|
+
|
61
|
+
# add default felix in context
|
62
|
+
if !@felix #TODO Move default version somewhere
|
63
|
+
@felix = lib('org.apache.felix', 'org.apache.felix.main', '4.0.2')
|
64
|
+
end
|
65
|
+
|
66
|
+
{
|
67
|
+
:config => @config,
|
68
|
+
:dependencies => @dependencies,
|
69
|
+
:felix => @felix,
|
70
|
+
:directives => @directives
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.validate( res )
|
75
|
+
raise "Must have at least one service name." if res[:config]['service'].nil?
|
76
|
+
res
|
77
|
+
end
|
78
|
+
|
79
|
+
# **************************************************************************
|
80
|
+
# Winterfile DSL spec
|
81
|
+
# **************************************************************************
|
82
|
+
|
83
|
+
def name( name )
|
84
|
+
@name = @config['service'] = name
|
85
|
+
end
|
86
|
+
|
87
|
+
def info( msg=nil )
|
88
|
+
$LOG.info msg
|
89
|
+
end
|
90
|
+
|
91
|
+
def directive( key, value=nil )
|
92
|
+
@directives[key] = value
|
93
|
+
end
|
94
|
+
|
95
|
+
def lib( group, artifact, version='LATEST', *args )
|
96
|
+
options = Hash === args.last ? args.pop : {}
|
97
|
+
dep = Dependency.new
|
98
|
+
dep.artifact = artifact
|
99
|
+
dep.group = group
|
100
|
+
dep.version = version
|
101
|
+
dep.repositories = @repositories
|
102
|
+
dep.package = options[:package] || 'jar'
|
103
|
+
dep.offline = @options['offline'] || @options['offline'] == 'true'
|
104
|
+
dep.transative = true
|
105
|
+
dep.destination = File.join(Dir.getwd,RUN_DIR,@name,LIBS_DIR)
|
106
|
+
#dep.verbose = true
|
107
|
+
|
108
|
+
@dependencies.push dep
|
109
|
+
dep
|
110
|
+
end
|
111
|
+
|
112
|
+
def bundle( group, artifact, version='LATEST', *args )
|
113
|
+
options = Hash === args.last ? args.pop : {}
|
114
|
+
dep = Dependency.new
|
115
|
+
dep.artifact = artifact
|
116
|
+
dep.group = group
|
117
|
+
dep.version = version
|
118
|
+
dep.repositories = @repositories
|
119
|
+
dep.package = options[:package] || 'jar'
|
120
|
+
dep.offline = @options['offline'] || @options['offline'] == 'true'
|
121
|
+
dep.transative = false
|
122
|
+
dep.destination = File.join(Dir.getwd,RUN_DIR,@name,BUNDLES_DIR)
|
123
|
+
#dep.verbose = true
|
124
|
+
|
125
|
+
@dependencies.push dep
|
126
|
+
dep
|
127
|
+
end
|
128
|
+
|
129
|
+
def felix( group, artifact, version='LATEST', *args )
|
130
|
+
@felix = lib( group, artifact, version, args )
|
131
|
+
end
|
132
|
+
|
133
|
+
def pom( pom, *args )
|
134
|
+
if pom.is_a?(Symbol)
|
135
|
+
raise "Poms must be URLs, paths to poms, or Strings"
|
136
|
+
end
|
137
|
+
|
138
|
+
pom_file = MavenPom.fetch(pom)
|
139
|
+
pom_spec = MavenPom.parse_pom(pom_file)
|
140
|
+
#$LOG.debug pom_spec.dependencies
|
141
|
+
pom_spec.dependencies.each do |dep|
|
142
|
+
$LOG.debug dep
|
143
|
+
if dep[:scope] == 'provided'
|
144
|
+
lib( dep[:group], dep[:artifact], dep[:version] )
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def conf( dir )
|
150
|
+
#$LOG.debug( dir << " " << File.join(WINTERFELL_DIR,RUN_DIR,'conf') )
|
151
|
+
process_templates( dir, File.join(WINTERFELL_DIR,RUN_DIR,@name,'conf') )
|
152
|
+
end
|
153
|
+
|
154
|
+
def read( file )
|
155
|
+
if File.exist?(file)
|
156
|
+
@config.merge!( JSON.parse(File.read file ))
|
157
|
+
else
|
158
|
+
$LOG.warn "#{file} could not be found."
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def group(*args, &blk)
|
163
|
+
@groups.concat args
|
164
|
+
#$LOG.info @options['group'].split(",")
|
165
|
+
#$LOG.info "in group " << @groups.join("::")
|
166
|
+
if( @options['group'] \
|
167
|
+
&& @options['group'].split(",").include?(@groups.join("::")) )
|
168
|
+
yield
|
169
|
+
end
|
170
|
+
ensure
|
171
|
+
args.each { @groups.pop }
|
172
|
+
end
|
173
|
+
|
174
|
+
def repository( url )
|
175
|
+
@repositories.push url
|
176
|
+
end
|
177
|
+
alias :repo :repository
|
178
|
+
|
179
|
+
end
|
180
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Copyright 2013 LiveOps, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
4
|
+
# use this file except in compliance with the License. You may obtain a copy
|
5
|
+
# of the License at:
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
12
|
+
# License for the specific language governing permissions and limitations
|
13
|
+
# under the License.
|
14
|
+
|
15
|
+
require 'logger'
|
16
|
+
|
17
|
+
if $LOG.nil?
|
18
|
+
$LOG = Logger.new(STDOUT)
|
19
|
+
#original_formatter = Logger::Formatter.new
|
20
|
+
$LOG.level = Logger::INFO
|
21
|
+
$LOG.formatter = proc { |severity, datetime, progname, msg|
|
22
|
+
#original_formatter.call(severity, datetime, progname, msg.dump)
|
23
|
+
if( severity == 'DEBUG')
|
24
|
+
"#{severity}: #{msg} \n"
|
25
|
+
else
|
26
|
+
"#{msg} \n"
|
27
|
+
end
|
28
|
+
}
|
29
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Copyright 2013 LiveOps, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
4
|
+
# use this file except in compliance with the License. You may obtain a copy
|
5
|
+
# of the License at:
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
12
|
+
# License for the specific language governing permissions and limitations
|
13
|
+
# under the License.
|
14
|
+
|
15
|
+
require 'winter/constants'
|
16
|
+
require 'winter/logger'
|
17
|
+
|
18
|
+
module Winter
|
19
|
+
class Service
|
20
|
+
|
21
|
+
def build(winterfile, options)
|
22
|
+
#dsl = DSL.new options
|
23
|
+
tmp = DSL.evaluate winterfile, options
|
24
|
+
dependencies = tmp[:dependencies]
|
25
|
+
#$LOG.debug dependencies
|
26
|
+
|
27
|
+
dependencies.each do |dep|
|
28
|
+
dep.getMaven
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
# Copyright 2013 LiveOps, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
4
|
+
# use this file except in compliance with the License. You may obtain a copy
|
5
|
+
# of the License at:
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
12
|
+
# License for the specific language governing permissions and limitations
|
13
|
+
# under the License.
|
14
|
+
|
15
|
+
require 'winter/constants'
|
16
|
+
require 'winter/logger'
|
17
|
+
require 'shellwords'
|
18
|
+
|
19
|
+
# TODO This needs a larger refactor to make it more functional and less reliant
|
20
|
+
# upon class variables (@foo). HELP!
|
21
|
+
|
22
|
+
module Winter
|
23
|
+
class Service
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
#put defaults here
|
27
|
+
@config = {}
|
28
|
+
@config['java_home'] = ENV['JAVA_HOME']
|
29
|
+
@config['service'] = 'default'
|
30
|
+
@config['log.level'] = 1
|
31
|
+
@config['64bit'] = true
|
32
|
+
@config['jvm.mx'] = '1g'
|
33
|
+
@config['console'] = '/dev/null'
|
34
|
+
@config['web.port'] = 8080
|
35
|
+
@config['osgi.port'] = 6070
|
36
|
+
@config['jdb.port'] = 6071
|
37
|
+
@config['jmx.port'] = 6072
|
38
|
+
@config['service.conf.dir'] = "conf"
|
39
|
+
|
40
|
+
#@config['log.dir'] = File.join(WINTERFELL_DIR,RUN_DIR,@config['service'],'logs')
|
41
|
+
@directives = {}
|
42
|
+
end
|
43
|
+
|
44
|
+
def start(winterfile, options)
|
45
|
+
dsl = DSL.evaluate winterfile, options
|
46
|
+
dsl[:dependencies].each do |dep|
|
47
|
+
$LOG.debug "dependency: #{dep.group}.#{dep.artifact}"
|
48
|
+
end
|
49
|
+
@felix = dsl[:felix]
|
50
|
+
|
51
|
+
@config.merge! dsl[:config] # add Winterfile 'directive' commands
|
52
|
+
@config.merge! options # overwrite @config with command-line options
|
53
|
+
@config.each do |k,v|
|
54
|
+
k = k.shellescape if k.is_a? String
|
55
|
+
v = v.shellescape if v.is_a? String
|
56
|
+
end
|
57
|
+
$LOG.debug @config
|
58
|
+
|
59
|
+
@service_dir = File.join(File.split(winterfile)[0],RUN_DIR,@config['service']).shellescape
|
60
|
+
|
61
|
+
@config['log.dir'] = File.join(@service_dir,'logs')
|
62
|
+
|
63
|
+
@directives.merge! dsl[:directives]
|
64
|
+
|
65
|
+
java_cmd = generate_java_invocation
|
66
|
+
java_cmd << " > #{@config['console']} 2>&1"
|
67
|
+
$LOG.debug java_cmd
|
68
|
+
|
69
|
+
# execute
|
70
|
+
if( File.exists?(File.join(@service_dir, "pid")) )
|
71
|
+
$LOG.error "PID file already exists. Is the process running?"
|
72
|
+
exit
|
73
|
+
end
|
74
|
+
pid_file = File.open(File.join(@service_dir, "pid"), "w")
|
75
|
+
pid = fork do
|
76
|
+
exec(java_cmd)
|
77
|
+
end
|
78
|
+
pid_file.write(pid)
|
79
|
+
pid_file.close
|
80
|
+
|
81
|
+
$LOG.info "Started #{@config['service']} (#{pid})"
|
82
|
+
end
|
83
|
+
|
84
|
+
def find_java
|
85
|
+
if !@config['java_home'].nil? && File.exists?(File.join(@config['java_home'],'bin','java'))
|
86
|
+
return File.join(@config['java_home'],'bin','java')
|
87
|
+
end
|
88
|
+
if !ENV['JAVA_HOME'].nil? && File.exists?(File.join(ENV['JAVA_HOME'],'bin','java'))
|
89
|
+
return File.join(ENV['JAVA_HOME'],'bin','java')
|
90
|
+
end
|
91
|
+
env = `env java -version 2>&1`
|
92
|
+
if env['version']
|
93
|
+
return "java"
|
94
|
+
end
|
95
|
+
raise "JRE could not be found. Please set JAVA_HOME or configure java_home."
|
96
|
+
end
|
97
|
+
|
98
|
+
def generate_java_invocation
|
99
|
+
java_bin = find_java
|
100
|
+
|
101
|
+
felix_jar = File.join(@felix.destination,"#{@felix.artifact}-#{@felix.version}.#{@felix.package}")
|
102
|
+
|
103
|
+
# start building the command
|
104
|
+
cmd = [ "#{java_bin.shellescape} -server" ]
|
105
|
+
cmd << (@config["64bit"]==true ? " -d64 -XX:+UseCompressedOops":'')
|
106
|
+
cmd << " -XX:MaxPermSize=256m -XX:NewRatio=3"
|
107
|
+
cmd << " -Xmx#{@config['jvm.mx']}"
|
108
|
+
cmd << opt("felix.fileinstall.dir", "#{@service_dir}/#{BUNDLES_DIR}")
|
109
|
+
|
110
|
+
config_properties = File.join(@service_dir, "conf", F_CONFIG_PROPERTIES)
|
111
|
+
cmd << opt("felix.config.properties", "file:" + config_properties)
|
112
|
+
cmd << opt("felix.log.level", felix_log_level(@config['log.level']))
|
113
|
+
|
114
|
+
# TODO remove these options when the logger bundle is updated to use the classpath
|
115
|
+
logger_properties = File.join(@service_dir, "conf", F_LOGGER_PROPERTIES)
|
116
|
+
logback_xml = File.join(@service_dir, "conf", F_LOGBACK_XML)
|
117
|
+
cmd << opt("log4j.configuration", logger_properties)
|
118
|
+
cmd << opt("logback.configurationFile", logback_xml)
|
119
|
+
|
120
|
+
cmd << opt("web.port", @config["web.port"])
|
121
|
+
cmd << opt("osgi.port", @config["osgi.port"])
|
122
|
+
cmd << opt("log.dir", @config['log.dir'])
|
123
|
+
cmd << opt("service.conf.dir", File.join(@service_dir, "conf"))
|
124
|
+
cmd << opt(OPT_BUNDLE_DIR, "#{@service_dir}/bundles")
|
125
|
+
cmd << add_directives( @directives )
|
126
|
+
cmd << @config["osgi.shell.telnet.ip"]?" -Dosgi.shell.telnet.ip=#{@config["osgi.shell.telnet.ip"]}":''
|
127
|
+
#cmd.push(add_code_coverage())
|
128
|
+
cmd << (@config["jdb.port"] ? " -Xdebug -Xrunjdwp:transport=dt_socket,address=#{@config["jdb.port"]},server=y,suspend=n" : '')
|
129
|
+
cmd << (@config["jmx.port"] ? " -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=#{@config["jmx.port"]} -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false" : '')
|
130
|
+
cmd << " -cp #{@service_dir}/conf:#{felix_jar.to_s.shellescape} org.apache.felix.main.Main"
|
131
|
+
cmd << " -b #{@service_dir}/libs"
|
132
|
+
cmd << " #{@service_dir}/felix_cache"
|
133
|
+
|
134
|
+
return cmd.join(" \\\n ")
|
135
|
+
end
|
136
|
+
|
137
|
+
def add_directives( dir )
|
138
|
+
tmp = ""
|
139
|
+
dir.each do |key, value|
|
140
|
+
tmp << " -D"+Shellwords.escape(key)
|
141
|
+
if value
|
142
|
+
tmp << "="+Shellwords.escape(value.to_s)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
tmp
|
146
|
+
end
|
147
|
+
|
148
|
+
def opt(key, value)
|
149
|
+
" -D#{Shellwords.escape(key.to_s)}=#{Shellwords.escape(value.to_s)}"
|
150
|
+
end
|
151
|
+
|
152
|
+
def felix_log_level(level)
|
153
|
+
if level =~ /[1-4]/
|
154
|
+
return level
|
155
|
+
end
|
156
|
+
if !level.is_a? String
|
157
|
+
return 1
|
158
|
+
end
|
159
|
+
case level.upcase
|
160
|
+
when "ERROR"
|
161
|
+
return 1
|
162
|
+
when "WARN"
|
163
|
+
return 2
|
164
|
+
when "INFO"
|
165
|
+
return 3
|
166
|
+
when "DEBUG"
|
167
|
+
return 4
|
168
|
+
else
|
169
|
+
return 1
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Copyright 2013 LiveOps, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
4
|
+
# use this file except in compliance with the License. You may obtain a copy
|
5
|
+
# of the License at:
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
12
|
+
# License for the specific language governing permissions and limitations
|
13
|
+
# under the License.
|
14
|
+
|
15
|
+
require 'winter/constants'
|
16
|
+
require 'winter/logger'
|
17
|
+
|
18
|
+
module Winter
|
19
|
+
class Service
|
20
|
+
|
21
|
+
def status
|
22
|
+
pid_files = Dir.glob(File.join(WINTERFELL_DIR,RUN_DIR, "**", "pid"))
|
23
|
+
if( pid_files.length == 0 )
|
24
|
+
$LOG.info "No services are running."
|
25
|
+
end
|
26
|
+
|
27
|
+
services = {}
|
28
|
+
|
29
|
+
pid_files.each do |f_pid|
|
30
|
+
service = f_pid.sub( %r{#{WINTERFELL_DIR}/#{RUN_DIR}/([^/]+)/pid}, '\1')
|
31
|
+
pid_file = File.open(f_pid, "r")
|
32
|
+
pid = pid_file.read().to_i
|
33
|
+
|
34
|
+
begin
|
35
|
+
Process.getpgid( pid )
|
36
|
+
running = "Running"
|
37
|
+
rescue Errno::ESRCH
|
38
|
+
running = "Dangling pid file : #{f_pid}"
|
39
|
+
end
|
40
|
+
|
41
|
+
services["#{service} (#{pid})"] = "#{running}"
|
42
|
+
end
|
43
|
+
|
44
|
+
return services
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# Copyright 2013 LiveOps, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
4
|
+
# use this file except in compliance with the License. You may obtain a copy
|
5
|
+
# of the License at:
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
12
|
+
# License for the specific language governing permissions and limitations
|
13
|
+
# under the License.
|
14
|
+
|
15
|
+
require 'winter/constants'
|
16
|
+
require 'winter/logger'
|
17
|
+
|
18
|
+
module Winter
|
19
|
+
class Service
|
20
|
+
|
21
|
+
# stop winterfell service
|
22
|
+
def stop(winterfile='Winterfile', options={})
|
23
|
+
tmp = DSL.evaluate winterfile, options
|
24
|
+
config = tmp[:config]
|
25
|
+
service = config['service']
|
26
|
+
|
27
|
+
@service_dir = File.join(File.split(winterfile)[0],RUN_DIR,service)
|
28
|
+
f_pid = File.join(@service_dir, "pid")
|
29
|
+
|
30
|
+
if File.exists?(f_pid)
|
31
|
+
pid = nil;
|
32
|
+
File.open(f_pid, "r") do |f|
|
33
|
+
pid = f.read().to_i
|
34
|
+
end
|
35
|
+
Process.kill("TERM", -Process.getpgid(pid))
|
36
|
+
begin
|
37
|
+
File.unlink(f_pid)
|
38
|
+
rescue
|
39
|
+
$LOG.error( "Error deleting PID file." )
|
40
|
+
end
|
41
|
+
else
|
42
|
+
$LOG.error("Failed to find process Id file: #{f_pid}")
|
43
|
+
false
|
44
|
+
end
|
45
|
+
true
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Copyright 2013 LiveOps, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
4
|
+
# use this file except in compliance with the License. You may obtain a copy
|
5
|
+
# of the License at:
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
12
|
+
# License for the specific language governing permissions and limitations
|
13
|
+
# under the License.
|
14
|
+
|
15
|
+
require 'winter/constants'
|
16
|
+
require 'winter/logger'
|
17
|
+
|
18
|
+
module Winter
|
19
|
+
class Service
|
20
|
+
|
21
|
+
def validate( winterfile='Winterfile', options={} )
|
22
|
+
DSL.evaluate winterfile, options
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Copyright 2013 LiveOps, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
4
|
+
# use this file except in compliance with the License. You may obtain a copy
|
5
|
+
# of the License at:
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
12
|
+
# License for the specific language governing permissions and limitations
|
13
|
+
# under the License.
|
14
|
+
|
15
|
+
require 'winter/logger'
|
16
|
+
require 'erb'
|
17
|
+
|
18
|
+
def process_templates(source_templates, destination_dir)
|
19
|
+
#$LOG.debug "'#{source_templates}' -> #{destination_dir}"
|
20
|
+
Dir.glob(File.join(source_templates, "**", "*.erb")) do |tmpl|
|
21
|
+
result = ERB.new(File.open(tmpl).read).result(binding)
|
22
|
+
dest = destination_dir + tmpl.sub(%r{#{source_templates}},"").sub(/\.erb$/, "")
|
23
|
+
#$LOG.debug "Processing: #{dest}"
|
24
|
+
FileUtils.mkpath File.dirname(dest)
|
25
|
+
File.new(dest,'w').write(result)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Copyright 2013 LiveOps, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
4
|
+
# use this file except in compliance with the License. You may obtain a copy
|
5
|
+
# of the License at:
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
12
|
+
# License for the specific language governing permissions and limitations
|
13
|
+
# under the License.
|
14
|
+
|
15
|
+
module Winter
|
16
|
+
VERSION = "0.0.1"
|
17
|
+
end
|
data/lib/winter.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Copyright 2013 LiveOps, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
4
|
+
# use this file except in compliance with the License. You may obtain a copy
|
5
|
+
# of the License at:
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
12
|
+
# License for the specific language governing permissions and limitations
|
13
|
+
# under the License.
|
14
|
+
|
15
|
+
require "winter/version"
|
16
|
+
#require "winter/specfile"
|
17
|
+
|
18
|
+
module Winter
|
19
|
+
|
20
|
+
def self.assemble
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|