itamae-plugin-resource-daemontools_service 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d62e1c8bf385519952d4198d46e971d106fdba0a
4
- data.tar.gz: cb952cf722dc8923444750262d6854a215286198
3
+ metadata.gz: 6e45984ee2b35354f357ed041f68754b18a5af4e
4
+ data.tar.gz: 7721e4b5c2a26c21ab0f11f279729739eec17dc0
5
5
  SHA512:
6
- metadata.gz: 9c764f407e051fc222d56bd250ffb11e7a1a4737b90b8cf2f2903b26388880c390e9a48307ca7bf94bce114523160864ad2fc13cf488b8959029a88053187c13
7
- data.tar.gz: 68ab940a6585739cec458998b0b46e16aa1a0acf72706eacf46c2b3f5bf26e753ad16c38148193b2c999a20a3539555742182c340c6dec21cb03f5a0ba2fa3da
6
+ metadata.gz: 1140cf4e83596b0ad53939fd23d0d497fb5588e70b272cddb6937823628d55ec49f5397f4e786c523483486d39420195344a47e2a348a2dba2cb64797bb85038
7
+ data.tar.gz: f9fe3613689220f5790037473882af505774636934763d40ca75e8f48516aad64d5b48385be1150b27aae1ba1b57a589de8dca3de18083bf2f8d73cbbfa03718
data/README.md CHANGED
@@ -33,10 +33,14 @@ end
33
33
 
34
34
  Options:
35
35
 
36
- - service_dir (optional)
37
- - directory that svscan monitors. default is `/service`
38
36
  - directory (required)
39
- - directory contains `run` file. The basename is used to link to `/service/#{basename(directory)}`
37
+ - directory contains `run` file. This directory is symlinked.
38
+ - service_dir (option)
39
+ - directory that svscan monitors. default is `/service`
40
+ - svc_command (option)
41
+ - the path of the svc command. default is `svc`
42
+ - svstat_command (option)
43
+ - the path of the svstat command. default is `svstat`
40
44
 
41
45
  ## Acknowledgement
42
46
 
@@ -16,71 +16,71 @@ execute "start svscan" do
16
16
  not_if "initctl status svscan | grep running"
17
17
  end
18
18
 
19
- # sync test scripts
20
19
  directory "/tmp/service"
21
20
 
22
- remote_directory "/tmp/service/test/" do
23
- source "files/tmp/service/test/"
24
- end
25
-
26
- # tests
27
-
28
- daemontools_service "test" do
29
- directory "/tmp/service/test"
30
- action [:enable]
31
- end
32
-
33
- daemontools_service "test" do
34
- directory "/tmp/service/test"
35
- action [:enable]
36
- end
37
-
38
- daemontools_service "test" do
39
- directory "/tmp/service/test"
40
- action [:start]
41
- end
42
-
43
- daemontools_service "test" do
44
- directory "/tmp/service/test"
45
- action [:start]
46
- end
47
-
48
- daemontools_service "test" do
49
- directory "/tmp/service/test"
50
- action [:reload]
51
- end
52
-
53
- daemontools_service "test" do
54
- directory "/tmp/service/test"
55
- action [:reload]
56
- end
57
-
58
- daemontools_service "test" do
59
- directory "/tmp/service/test"
60
- action [:stop]
61
- end
62
-
63
- daemontools_service "test" do
64
- directory "/tmp/service/test"
65
- action [:stop]
66
- end
67
-
68
- daemontools_service "test" do
69
- directory "/tmp/service/test"
70
- action [:restart]
71
- end
72
-
73
- daemontools_service "test" do
74
- directory "/tmp/service/test"
75
- action [:restart]
76
- end
77
-
78
- daemontools_service "test" do
79
- directory "/tmp/service/test"
80
- action [:disable]
81
- end
82
-
83
- daemontools_service "test" do
84
- directory "/tmp/service/test"
85
- action [:disable]
21
+ %w[with_log without_log].each do |_service|
22
+ # sync test scripts
23
+ remote_directory "/tmp/service/#{_service}/" do
24
+ source "files/tmp/service/#{_service}/"
25
+ end
26
+
27
+ daemontools_service "#{_service}" do
28
+ directory "/tmp/service/#{_service}"
29
+ action [:enable]
30
+ end
31
+
32
+ daemontools_service "#{_service}" do
33
+ directory "/tmp/service/#{_service}"
34
+ action [:enable]
35
+ end
36
+
37
+ daemontools_service "#{_service}" do
38
+ directory "/tmp/service/#{_service}"
39
+ action [:start]
40
+ end
41
+
42
+ daemontools_service "#{_service}" do
43
+ directory "/tmp/service/#{_service}"
44
+ action [:start]
45
+ end
46
+
47
+ daemontools_service "#{_service}" do
48
+ directory "/tmp/service/#{_service}"
49
+ action [:reload]
50
+ end
51
+
52
+ daemontools_service "#{_service}" do
53
+ directory "/tmp/service/#{_service}"
54
+ action [:reload]
55
+ end
56
+
57
+ daemontools_service "#{_service}" do
58
+ directory "/tmp/service/#{_service}"
59
+ action [:stop]
60
+ end
61
+
62
+ daemontools_service "#{_service}" do
63
+ directory "/tmp/service/#{_service}"
64
+ action [:stop]
65
+ end
66
+
67
+ daemontools_service "#{_service}" do
68
+ directory "/tmp/service/#{_service}"
69
+ action [:restart]
70
+ end
71
+
72
+ daemontools_service "#{_service}" do
73
+ directory "/tmp/service/#{_service}"
74
+ action [:restart]
75
+ end
76
+
77
+ daemontools_service "#{_service}" do
78
+ directory "/tmp/service/#{_service}"
79
+ action [:disable]
80
+ end
81
+
82
+ daemontools_service "#{_service}" do
83
+ directory "/tmp/service/#{_service}"
84
+ action [:disable]
85
+ end
86
86
  end
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+ exec 2>&1
3
+ set -e
4
+ exec envdir ./env \
5
+ sh -c '
6
+ exec vmstat 1 2>&1
7
+ '
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "itamae-plugin-resource-daemontools_service"
7
- spec.version = "0.0.1"
7
+ spec.version = "0.0.2"
8
8
  spec.authors = ["Naotoshi Seo"]
9
9
  spec.email = ["sonots@gmail.com"]
10
10
  spec.summary = %q{Itamae resource plugin to manage daemontools service.}
@@ -7,10 +7,10 @@ module Itamae
7
7
  define_attribute :action, default: :nothing
8
8
  define_attribute :name, type: String, default_name: true
9
9
 
10
- define_attribute :service_directory, type: String, default: '/service'
11
10
  define_attribute :directory, type: String
12
- define_attribute :svc_command, type: String, default: '/usr/local/bin/svc'
13
- define_attribute :svstat_command, type: String, default: '/usr/local/bin/svstat'
11
+ define_attribute :service_dir, type: String, default: '/service'
12
+ define_attribute :svc_command, type: String, default: 'svc'
13
+ define_attribute :svstat_command, type: String, default: 'svstat'
14
14
 
15
15
  def initialize(*args)
16
16
  super
@@ -25,11 +25,11 @@ module Itamae
25
25
  end
26
26
 
27
27
  def service_name
28
- shell_escape(File.basename(attributes.directory))
28
+ shell_escape(attributes.name)
29
29
  end
30
30
 
31
31
  def service_link
32
- "#{shell_escape(attributes.service_directory)}/#{service_name}"
32
+ "#{shell_escape(attributes.service_dir)}/#{service_name}"
33
33
  end
34
34
 
35
35
  def pre_action
@@ -52,63 +52,53 @@ module Itamae
52
52
 
53
53
  def action_start(options)
54
54
  if current.enabled && !current.running
55
- run_command("sudo #{svc_command} -u #{service_link}")
55
+ run_command("#{svc_command} -u #{service_link}")
56
56
  end
57
57
  end
58
58
 
59
59
  def action_stop(options)
60
60
  if current.enabled && current.running
61
- run_command("sudo #{svc_command} -d #{service_link}")
61
+ run_command("#{svc_command} -d #{service_link}")
62
62
  end
63
63
  end
64
64
 
65
65
  def action_restart(options)
66
66
  if current.enabled && current.running
67
- run_command("sudo #{svc_command} -t #{service_link}")
67
+ run_command("#{svc_command} -t #{service_link}")
68
68
  end
69
69
  end
70
70
 
71
71
  def action_reload(options)
72
72
  if current.enabled && current.running
73
- run_command("sudo #{svc_command} -h #{service_link}")
73
+ run_command("#{svc_command} -h #{service_link}")
74
74
  end
75
75
  end
76
76
 
77
77
  def action_enable(options)
78
78
  if !current.enabled
79
- # run_command("sudo ln -sf #{attributes.directory} #{service_link}")
80
- run_command("sudo ln -sf #{attributes.directory} #{shell_escape(attributes.service_directory)}/")
79
+ run_command("ln -snf #{attributes.directory} #{service_link}")
81
80
  end
82
81
  end
83
82
 
84
83
  def action_disable(options)
85
84
  if current.enabled
86
- service_dot_link = "#{shell_escape(attributes.service_directory)}/.#{service_name}"
87
- command = <<-"EOF"
88
- sudo mv #{service_link} #{service_dot_link}
89
- sudo #{svc_command} -dx #{service_dot_link}
90
- if [ -d #{service_dot_link}/log ]; then
91
- sudo #{svc_command} -dx #{service_dot_link}/log
92
- fi
93
- sudo rm -f #{service_dot_link}
94
- EOF
95
- run_command(command)
85
+ run_command("( cd #{service_link} && rm -f #{service_link} && svc -dx . log )")
96
86
  end
97
87
  end
98
88
 
99
- # private
89
+ private
100
90
 
101
91
  def service_status!
102
92
  if run_command("test -L #{service_link} && test -f #{service_link}/run", error: false).exit_status == 0
103
93
  current.enabled = true
104
- result = run_command("sudo #{svstat_command} #{service_link}", error: false)
94
+ result = run_command("#{svstat_command} #{service_link}", error: false)
105
95
  if result.exit_status == 0
106
96
 
107
97
  retry_count = 4
108
98
  while result.stdout =~ /: supervise not running/ or result.stdout =~ /: unable to open supervise\/ok/
109
99
  sleep 1
110
100
  retry_count -= 1
111
- result = run_command("sudo #{svstat_command} #{service_link}", error: false)
101
+ result = run_command("#{svstat_command} #{service_link}", error: false)
112
102
  break if retry_count < 0
113
103
  end
114
104
 
data/test.sh CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/bin/bash
2
- bundle exec itamae ssh --vagrant -h vagrant-centos examples/daemontools_service.rb
2
+ bundle exec itamae ssh -l debug --vagrant -h vagrant-centos examples/daemontools_service.rb
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itamae-plugin-resource-daemontools_service
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
  - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-18 00:00:00.000000000 Z
11
+ date: 2015-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -82,9 +82,11 @@ files:
82
82
  - Vagrantfile
83
83
  - examples/daemontools_service.rb
84
84
  - examples/files/etc/init/svscan.conf
85
- - examples/files/tmp/service/test/env/.gitkeep
86
- - examples/files/tmp/service/test/log/run
87
- - examples/files/tmp/service/test/run
85
+ - examples/files/tmp/service/with_log/env/.gitkeep
86
+ - examples/files/tmp/service/with_log/log/run
87
+ - examples/files/tmp/service/with_log/run
88
+ - examples/files/tmp/service/without_log/env/.gitkeep
89
+ - examples/files/tmp/service/without_log/run
88
90
  - itamae-plugin-resource-daemontools_service.gemspec
89
91
  - lib/itamae/plugin/resource/daemontools_service.rb
90
92
  - spec/itamae/plugin/resource/daemontools_service_spec.rb