itamae-plugin-resource-daemontools_service 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d62e1c8bf385519952d4198d46e971d106fdba0a
4
+ data.tar.gz: cb952cf722dc8923444750262d6854a215286198
5
+ SHA512:
6
+ metadata.gz: 9c764f407e051fc222d56bd250ffb11e7a1a4737b90b8cf2f2903b26388880c390e9a48307ca7bf94bce114523160864ad2fc13cf488b8959029a88053187c13
7
+ data.tar.gz: 68ab940a6585739cec458998b0b46e16aa1a0acf72706eacf46c2b3f5bf26e753ad16c38148193b2c999a20a3539555742182c340c6dec21cb03f5a0ba2fa3da
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.gem
16
+ .vagrant/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 2.1.*
3
+ - 2.2.*
4
+ gemfile:
5
+ - Gemfile
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+ gem 'pry'
5
+ gem 'pry-nav'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Naotoshi Seo
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Itamae::Plugin::Resource::DaemontoolsService
2
+
3
+ [Itamae](https://github.com/itamae-kitchen/itamae) resource plugin to manage daemontools service.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'itamae-plugin-resource-daemontools_service'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install itamae-plugin-resource-daemontools_service
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require "itamae/plugin/resource/daemontools_service"
25
+
26
+ # ln -s /etc/djbdns/tinydns-internal /service/tinydns-internal
27
+ # svc -u /service/tinydns-internal
28
+ daemontools_service "tinydns-iternal" do
29
+ directory '/etc/djbdns/tinydns-internal'
30
+ action [:enable, :start]
31
+ end
32
+ ```
33
+
34
+ Options:
35
+
36
+ - service_dir (optional)
37
+ - directory that svscan monitors. default is `/service`
38
+ - directory (required)
39
+ - directory contains `run` file. The basename is used to link to `/service/#{basename(directory)}`
40
+
41
+ ## Acknowledgement
42
+
43
+ This is an itamae plugin version of https://github.com/hirose31/chef-provider-service-daemontools. Thanks!
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( https://github.com/k0kubun/itamae-plugin-resource-daemontools_service/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc 'Open an irb session preloaded with the gem library'
4
+ task :console do
5
+ sh 'irb -rubygems -I lib'
6
+ end
7
+ task :c => :console
data/Vagrantfile ADDED
@@ -0,0 +1,19 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5
+ VAGRANTFILE_API_VERSION = "2"
6
+
7
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8
+ # All Vagrant configuration is done here. The most common configuration
9
+ # options are documented and commented below. For a complete reference,
10
+ # please see the online documentation at vagrantup.com.
11
+
12
+ # Every Vagrant virtual environment requires a box to build off of.
13
+ config.vm.box = "centos6.5.3"
14
+ config.vm.box_url = 'https://github.com/2creatives/vagrant-centos/releases/download/v6.5.3/centos65-x86_64-20140116.box'
15
+
16
+ # name
17
+ config.vm.define "vagrant-centos"
18
+ config.ssh.forward_agent = true
19
+ end
@@ -0,0 +1,86 @@
1
+ require 'itamae/plugin/resource/daemontools_service'
2
+
3
+ # install daemontools
4
+ package 'daemontools'
5
+
6
+ remote_file "/etc/init/svscan.conf" do
7
+ owner "root"
8
+ group "root"
9
+ end
10
+
11
+ execute "start svscan" do
12
+ command [
13
+ "initctl reload-configuration",
14
+ "initctl start svscan"
15
+ ].join("\n")
16
+ not_if "initctl status svscan | grep running"
17
+ end
18
+
19
+ # sync test scripts
20
+ directory "/tmp/service"
21
+
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]
86
+ end
@@ -0,0 +1,3 @@
1
+ start on runlevel [12345]
2
+ respawn
3
+ exec /command/svscanboot
File without changes
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+ exec 2>&1
3
+ exec envdir ../env \
4
+ sh -c '
5
+ [ ! -d ./main ] && install -o root -d ./main
6
+ exec multilog ./main
7
+ '
@@ -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
+ '
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "itamae-plugin-resource-daemontools_service"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Naotoshi Seo"]
9
+ spec.email = ["sonots@gmail.com"]
10
+ spec.summary = %q{Itamae resource plugin to manage daemontools service.}
11
+ spec.description = %q{Itamae resource plugin to manage daemontools service.}
12
+ spec.homepage = "https://github.com/sonots/itamae-plugin-resource-daemontools_service"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec"
23
+ spec.add_dependency "itamae"
24
+ end
@@ -0,0 +1,135 @@
1
+ require "itamae"
2
+
3
+ module Itamae
4
+ module Plugin
5
+ module Resource
6
+ class DaemontoolsService < Itamae::Resource::Base
7
+ define_attribute :action, default: :nothing
8
+ define_attribute :name, type: String, default_name: true
9
+
10
+ define_attribute :service_directory, type: String, default: '/service'
11
+ 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'
14
+
15
+ def initialize(*args)
16
+ super
17
+ end
18
+
19
+ def svc_command
20
+ shell_escape(attributes.svc_command)
21
+ end
22
+
23
+ def svstat_command
24
+ shell_escape(attributes.svstat_command)
25
+ end
26
+
27
+ def service_name
28
+ shell_escape(File.basename(attributes.directory))
29
+ end
30
+
31
+ def service_link
32
+ "#{shell_escape(attributes.service_directory)}/#{service_name}"
33
+ end
34
+
35
+ def pre_action
36
+ case @current_action
37
+ when :start, :restart
38
+ attributes.running = true
39
+ when :stop
40
+ attributes.running = false
41
+ when :enable
42
+ attributes.enabled = true
43
+ when :disable
44
+ attributes.enabled = false
45
+ end
46
+ end
47
+
48
+ def set_current_attributes
49
+ super
50
+ service_status!
51
+ end
52
+
53
+ def action_start(options)
54
+ if current.enabled && !current.running
55
+ run_command("sudo #{svc_command} -u #{service_link}")
56
+ end
57
+ end
58
+
59
+ def action_stop(options)
60
+ if current.enabled && current.running
61
+ run_command("sudo #{svc_command} -d #{service_link}")
62
+ end
63
+ end
64
+
65
+ def action_restart(options)
66
+ if current.enabled && current.running
67
+ run_command("sudo #{svc_command} -t #{service_link}")
68
+ end
69
+ end
70
+
71
+ def action_reload(options)
72
+ if current.enabled && current.running
73
+ run_command("sudo #{svc_command} -h #{service_link}")
74
+ end
75
+ end
76
+
77
+ def action_enable(options)
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)}/")
81
+ end
82
+ end
83
+
84
+ def action_disable(options)
85
+ 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)
96
+ end
97
+ end
98
+
99
+ # private
100
+
101
+ def service_status!
102
+ if run_command("test -L #{service_link} && test -f #{service_link}/run", error: false).exit_status == 0
103
+ current.enabled = true
104
+ result = run_command("sudo #{svstat_command} #{service_link}", error: false)
105
+ if result.exit_status == 0
106
+
107
+ retry_count = 4
108
+ while result.stdout =~ /: supervise not running/ or result.stdout =~ /: unable to open supervise\/ok/
109
+ sleep 1
110
+ retry_count -= 1
111
+ result = run_command("sudo #{svstat_command} #{service_link}", error: false)
112
+ break if retry_count < 0
113
+ end
114
+
115
+ if result.stdout =~ /: up \(pid [1-9]/
116
+ current.running = true
117
+ elsif result.stdout =~ /: down [1-9]/
118
+ current.running = false
119
+ else
120
+ current.running = false
121
+ end
122
+ else
123
+ current.running = false
124
+ end
125
+ else
126
+ current.enabled = false
127
+ current.running = false
128
+ end
129
+
130
+ current
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,4 @@
1
+ require_relative '../../../spec_helper'
2
+
3
+ describe Itamae::Plugin::Resource::DaemontoolsService do
4
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
+ require "itamae/plugin/resource/daemontools_service"
data/test.sh ADDED
@@ -0,0 +1,2 @@
1
+ #!/bin/bash
2
+ bundle exec itamae ssh --vagrant -h vagrant-centos examples/daemontools_service.rb
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: itamae-plugin-resource-daemontools_service
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Naotoshi Seo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: itamae
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Itamae resource plugin to manage daemontools service.
70
+ email:
71
+ - sonots@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - Vagrantfile
83
+ - examples/daemontools_service.rb
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
88
+ - itamae-plugin-resource-daemontools_service.gemspec
89
+ - lib/itamae/plugin/resource/daemontools_service.rb
90
+ - spec/itamae/plugin/resource/daemontools_service_spec.rb
91
+ - spec/spec_helper.rb
92
+ - test.sh
93
+ homepage: https://github.com/sonots/itamae-plugin-resource-daemontools_service
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.2.2
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Itamae resource plugin to manage daemontools service.
117
+ test_files:
118
+ - spec/itamae/plugin/resource/daemontools_service_spec.rb
119
+ - spec/spec_helper.rb