daemontools 0.1.3 → 0.1.5

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3f78e344526e58126e95c1a9359e456eb99444c3
4
+ data.tar.gz: 658709fb1dd2e52a45fc476e14fd6276cf1d4898
5
+ SHA512:
6
+ metadata.gz: f552266c433984fa406203d175618731bf1d5e960e0d3504d1014c31b292cce80c394440df4fbc1eb3acc7f6acc8d2e7cdec725cb74c70618684dff9584d310b
7
+ data.tar.gz: c51b2afc52bf61a3c5c4d3a4b9408d709c189cdcf11445adf78c68c000fbe1da4e0514228d5ef655f1a6fcce93d6a2c8814d908f79b81c3aad90662550980924
data/bin/daemontools-gen CHANGED
@@ -8,4 +8,4 @@ roles = ARGV[1] || ""
8
8
  puts "Building svc services for roles #{roles} .."
9
9
 
10
10
  builder = Daemontools::Builder.new("#{Dir.pwd}/config/services.rb")
11
- builder.gen(roles, environment)
11
+ builder.gen(roles, environment)
data/lib/daemontools.rb CHANGED
@@ -9,11 +9,11 @@ module Daemontools
9
9
  end
10
10
  @svc_root = '/etc/service'
11
11
  @log_root = '/var/log/svc'
12
-
12
+
13
13
  def self.exists?(name)
14
14
  check_service_exists(name, false)
15
15
  end
16
-
16
+
17
17
  def self.status(name)
18
18
  check_service_exists(name)
19
19
  r = `sudo svstat #{@path} 2>&1`
@@ -21,27 +21,27 @@ module Daemontools
21
21
  raise "Unknown status" unless r.match(/.*?:\s*(\S+).*\s(\d+) seconds.*/)
22
22
  [$1, $2.to_i]
23
23
  end
24
-
24
+
25
25
  def self.up?(name)
26
26
  status(name)[0] == "up"
27
27
  end
28
-
28
+
29
29
  def self.down?(name)
30
30
  status(name)[0] == "down"
31
31
  end
32
-
32
+
33
33
  def self.stop(name)
34
34
  run_svc(name, 'd')
35
35
  end
36
-
36
+
37
37
  def self.start(name)
38
38
  run_svc(name, 'u')
39
39
  end
40
-
40
+
41
41
  def self.restart(name)
42
42
  run_svc(name, 't')
43
43
  end
44
-
44
+
45
45
  def self.add_empty(name)
46
46
  path = "#{@svc_root}/#{name}"
47
47
  Dir.mkdir(path) unless Dir.exists?(path)
@@ -55,7 +55,7 @@ module Daemontools
55
55
  stop(name)
56
56
  true
57
57
  end
58
-
58
+
59
59
  def self.add(name, command, options = {})
60
60
  @name = name
61
61
  @command = command
@@ -63,7 +63,9 @@ module Daemontools
63
63
  @pre_command = options[:pre_command]
64
64
  @sleep = options[:sleep] || 3
65
65
  @path = "#{@svc_root}/#{name}"
66
-
66
+ @change_user_command = options[:change_user_command]
67
+ @ulimit = options[:ulimit]
68
+
67
69
  if Dir.exists?(@path)
68
70
  stop(name)
69
71
  else
@@ -73,7 +75,7 @@ module Daemontools
73
75
  Dir.mkdir("#{@path}/log") unless Dir.exists?("#{@path}/log")
74
76
  File.open("#{@path}/log/run", 'w', 0755) {|f| f.write(run_template('log.erb'))}
75
77
  File.open("#{@path}/run", 'w', 0755) {|f| f.write(run_template('run.erb'))}
76
-
78
+
77
79
  unless options[:not_wait]
78
80
  wait_timeout = options[:wait_timeout] || 10
79
81
  now = Time.now.to_f
@@ -82,10 +84,10 @@ module Daemontools
82
84
  sleep 0.1
83
85
  end
84
86
  end
85
-
87
+
86
88
  true
87
89
  end
88
-
90
+
89
91
  def self.delete(name)
90
92
  check_service_exists(name)
91
93
  stop(name)
@@ -93,33 +95,33 @@ module Daemontools
93
95
  raise r if $?.exitstatus != 0
94
96
  true
95
97
  end
96
-
98
+
97
99
  def self.run_status(name)
98
100
  check_service_exists(name)
99
101
  File.exists?("#{@path}/down") ? "down" : "up"
100
102
  end
101
-
103
+
102
104
  def self.run_status_up?(name)
103
105
  run_status(name) == "up"
104
106
  end
105
-
107
+
106
108
  def self.run_status_down?(name)
107
109
  run_status(name) == "down"
108
110
  end
109
-
111
+
110
112
  def self.make_run_status_up(name)
111
113
  File.delete("#{@path}/down")
112
114
  true
113
115
  end
114
-
116
+
115
117
  def self.make_run_status_down(name)
116
118
  check_service_exists(name)
117
119
  File.open("#{@path}/down", 'w') {|f| f.write('')}
118
120
  true
119
121
  end
120
-
122
+
121
123
  private
122
-
124
+
123
125
  def self.check_service_exists(name, raise_error = true)
124
126
  @path = "#{@svc_root}/#{name}"
125
127
  if raise_error
@@ -128,7 +130,7 @@ module Daemontools
128
130
  Dir.exists?(@path)
129
131
  end
130
132
  end
131
-
133
+
132
134
  def self.run_svc(name, command)
133
135
  check_service_exists(name)
134
136
  r = `sudo svc -#{command} #{@path} 2>&1`
@@ -136,7 +138,7 @@ module Daemontools
136
138
  raise r if ! r.empty?
137
139
  true
138
140
  end
139
-
141
+
140
142
  def self.run_template(template_name)
141
143
  @user = Etc.getlogin
142
144
  template_path = File.expand_path(File.dirname(__FILE__))+'/../templates/'+template_name
@@ -1,34 +1,36 @@
1
1
  module Daemontools
2
2
  class Builder
3
- attr_accessor :environment, :all_roles, :services, :curr_service_name
4
-
3
+ attr_accessor :environment, :all_roles, :services, :curr_service_name, :change_user_command, :ulimit
4
+
5
5
  def initialize(filename)
6
6
  @all_roles = []
7
7
  @services = {}
8
+ @change_user_command = 'setuidgid'
9
+ @ulimit = {}
8
10
  eval(File.read(filename), binding())
9
11
  end
10
-
12
+
11
13
  def run_command(command_name, param)
12
14
  self.class.send(:define_method, command_name) do |task, options = {}|
13
15
  p = param.gsub(':task', task)
14
- options.each {|key, val| p.gsub!(":#{key}", val.to_s) }
16
+ options.each { |key, val| p.gsub!(":#{key}", val.to_s) }
15
17
  command(p, options)
16
18
  end
17
19
  end
18
-
20
+
19
21
  def command(param, options = {})
20
22
  Daemontools.stop(@curr_service_name) if Daemontools.exists?(@curr_service_name)
21
23
  @command = param.gsub(':environment', @environment)
22
24
  template_path = File.expand_path(File.dirname(__FILE__))+'/../../templates/rvm.erb'
23
25
  cmd = ERB.new(File.read(template_path)).result(binding())
24
- Daemontools.add(@curr_service_name, cmd)
26
+ Daemontools.add(@curr_service_name, cmd, { :change_user_command => @change_user_command, :ulimit => @ulimit })
25
27
  Daemontools.make_run_status_up(@curr_service_name)
26
28
  Daemontools.start(@curr_service_name)
27
29
  end
28
-
30
+
29
31
  def service(name, opts = {}, &block)
30
32
  if opts[:roles]
31
- opts[:roles].each do |role|
33
+ opts[:roles].each do |role|
32
34
  role = role.to_sym
33
35
  @all_roles << role unless @all_roles.member?(role)
34
36
  @services[role] = [] unless @services[role]
@@ -38,15 +40,23 @@ module Daemontools
38
40
  raise "service without roles"
39
41
  end
40
42
  end
41
-
43
+
42
44
  def gen(roles, env)
43
45
  @environment = env
44
- roles.split(',').each do |role|
46
+ roles.split(',').each do |role|
45
47
  (@services[role.to_sym] || []).each do |service|
46
48
  @curr_service_name = service[0].to_s
47
- service[1].call
49
+ service[1].call
48
50
  end
49
51
  end
50
52
  end
53
+
54
+ def change_user_command(cmd)
55
+ @change_user_command = cmd
56
+ end
57
+
58
+ def ulimit(opt, val)
59
+ @ulimit[opt] = val
60
+ end
51
61
  end
52
- end
62
+ end
@@ -1,3 +1,3 @@
1
1
  module Daemontools
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.5"
3
3
  end
data/templates/run.erb CHANGED
@@ -1,5 +1,8 @@
1
1
  #!/bin/sh
2
+ <% @ulimit.each do |k,v| %>
3
+ ulimit -<%=k%> <%=v%>
4
+ <% end %>
2
5
  <%= "sleep #{@sleep}" if @sleep && @sleep.to_i > 0 %>
3
6
  exec 2>&1
4
7
  <%= @pre_command if @pre_command %>
5
- exec <%= "setuidgid #{@user}" if @user %> <%= @command %>
8
+ exec <%= "#{@change_user_command} #{@user}" if @user %> <%= @command %>
metadata CHANGED
@@ -1,46 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daemontools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
5
- prerelease:
4
+ version: 0.1.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - sh
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-12-12 00:00:00.000000000 Z
11
+ date: 2016-01-22 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  description: Distributed storage
@@ -51,7 +46,7 @@ executables:
51
46
  extensions: []
52
47
  extra_rdoc_files: []
53
48
  files:
54
- - .gitignore
49
+ - ".gitignore"
55
50
  - Gemfile
56
51
  - LICENSE.txt
57
52
  - README.md
@@ -67,32 +62,25 @@ files:
67
62
  - templates/rvm.erb
68
63
  homepage: ''
69
64
  licenses: []
65
+ metadata: {}
70
66
  post_install_message:
71
67
  rdoc_options: []
72
68
  require_paths:
73
69
  - lib
74
70
  required_ruby_version: !ruby/object:Gem::Requirement
75
- none: false
76
71
  requirements:
77
- - - ! '>='
72
+ - - ">="
78
73
  - !ruby/object:Gem::Version
79
74
  version: '0'
80
- segments:
81
- - 0
82
- hash: 3917808334691883764
83
75
  required_rubygems_version: !ruby/object:Gem::Requirement
84
- none: false
85
76
  requirements:
86
- - - ! '>='
77
+ - - ">="
87
78
  - !ruby/object:Gem::Version
88
79
  version: '0'
89
- segments:
90
- - 0
91
- hash: 3917808334691883764
92
80
  requirements: []
93
81
  rubyforge_project:
94
- rubygems_version: 1.8.24
82
+ rubygems_version: 2.4.3
95
83
  signing_key:
96
- specification_version: 3
84
+ specification_version: 4
97
85
  summary: Distributed storage
98
86
  test_files: []