itamae-plugin-recipe-openresty 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f89efec1e48122b252dbd9218ca1dbc5e5fd51f2
4
+ data.tar.gz: c7b2b56851f14337ac97baa61436460a9d36445d
5
+ SHA512:
6
+ metadata.gz: 7ea7408b218de9560b9fcd531ccb20a8096c46cff0a52ad397ef186a57943397079145351fbe028688af8df3b0630b0f7ea509e6aa9e564bfd7f9b7c77262d79
7
+ data.tar.gz: a2c91c07ff8938df69bb81937bfbc1d1a9b48629b088746d388fb161175ee16cd1d22fbc3b060fe4cf9220082a89e72d5e1d1518d6ad2b72d5a4abbb3a200bcb
@@ -0,0 +1,14 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in itamae-plugin-recipe-openresty.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Takatoshi Maeda
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.
@@ -0,0 +1,31 @@
1
+ # Itamae::Plugin::Recipe::Openresty
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'itamae-plugin-recipe-openresty'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install itamae-plugin-recipe-openresty
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/itamae-plugin-recipe-openresty/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'itamae/plugin/recipe/openresty/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "itamae-plugin-recipe-openresty"
8
+ spec.version = Itamae::Plugin::Recipe::Openresty::VERSION
9
+ spec.authors = ["Takatoshi Maeda"]
10
+ spec.email = ["me@tmd.tw"]
11
+ spec.summary = %q{Itamae openresty recipe plugin}
12
+ spec.description = %q{Itamae openresty recipe plugin}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,89 @@
1
+ require 'itamae/plugin/recipe/openresty/version'
2
+
3
+ module Itamae
4
+ module Plugin
5
+ module Recipe
6
+ module Openresty
7
+ DEFAULT_VERSION = '1.7.4.1'.freeze
8
+
9
+ DEFAULT_PACKAGES = {
10
+ ubuntu: [
11
+ 'perl',
12
+ 'make',
13
+ 'wget',
14
+ 'libreadline-dev',
15
+ 'libssl-dev',
16
+ 'libpcre3-dev',
17
+ 'libncurses5-dev',
18
+ ],
19
+ centos: [
20
+ 'make',
21
+ 'wget',
22
+ 'readline-devel',
23
+ 'openssl-devel',
24
+ 'pcre-devel,'
25
+ ]
26
+ }.freeze
27
+
28
+ DEFAULT_CONFIGURE_FLAGS = {
29
+ 'prefix' => '/opt',
30
+ 'with-lua51' => nil,
31
+ 'with-luajit' => nil,
32
+ 'with-pcre-jit' => nil,
33
+ 'with-http_gzip_static_module' => nil,
34
+ 'user' => 'nginx',
35
+ 'group' => 'nginx',
36
+ }.freeze
37
+
38
+ DEFAULT_INIT_SCRIPT_PATH = '/etc/init.d/openresty'
39
+
40
+ BUILD_WORKING_DIR = '/tmp/openresty'
41
+
42
+ def self.extract_metadata(node)
43
+ raw = node['openresty'] || {}
44
+
45
+ metadata = {}
46
+ metadata[:version] = raw['version'] || DEFAULT_VERSION
47
+ metadata[:archive_url] = raw['archive_url'] || "http://openresty.org/download/ngx_openresty-#{metadata[:version]}.tar.gz"
48
+ metadata[:work_dir] = raw['work_dir'] || BUILD_WORKING_DIR
49
+ metadata[:configure_flags] = self.extract_configure_flags(raw['configure_flags'])
50
+ metadata[:install_depends_package] = raw['install_depends_package'] || true
51
+
52
+ metadata
53
+ end
54
+
55
+ def self.extract_configure_flags(options)
56
+ if options.nil?
57
+ options = DEFAULT_CONFIGURE_FLAGS.dup
58
+ end
59
+
60
+ options.map do |key, value|
61
+ if value.nil?
62
+ "--#{key}"
63
+ else
64
+ "--#{key}=#{value}"
65
+ end
66
+ end
67
+ end
68
+
69
+ def self.extract_init_script_options(node)
70
+ raw = node['openresty'] || {}
71
+ configure_flags = raw['configure_flags'] || DEFAULT_CONFIGURE_FLAGS
72
+ {
73
+ prefix: configure_flags['configure_flags'] || DEFAULT_CONFIGURE_FLAGS['prefix'],
74
+ sbin_path: self.sbin_path(node),
75
+ config_path: configure_flags['config-path'] || DEFAULT_CONFIGURE_FLAGS['prefix'] + '/nginx/conf/nginx.conf',
76
+ pid_path: configure_flags['pid-path'] || DEFAULT_CONFIGURE_FLAGS['prefix'] + '/nginx/logs/nginx.pid',
77
+ init_script_path: raw['init_script_path'] || DEFAULT_INIT_SCRIPT_PATH
78
+ }
79
+ end
80
+
81
+ def self.sbin_path(node)
82
+ raw = node['openresty'] || {}
83
+ configure_flags = raw['configure_flags'] || DEFAULT_CONFIGURE_FLAGS
84
+ configure_flags['sbin-path'] || DEFAULT_CONFIGURE_FLAGS['prefix'] + '/nginx/sbin/nginx'
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,132 @@
1
+ #!/bin/sh
2
+ #
3
+ # chkconfig: 2345 55 25
4
+ # Description: Nginx init.d script, put in /etc/init.d, chmod +x /etc/init.d/nginx
5
+ # For Debian, run: update-rc.d -f nginx defaults
6
+ # For CentOS, run: chkconfig --add nginx
7
+ #
8
+ ### BEGIN INIT INFO
9
+ # Provides: nginx(OpenResty)
10
+ # Required-Start: $all
11
+ # Required-Stop: $all
12
+ # Default-Start: 2 3 4 5
13
+ # Default-Stop: 0 1 6
14
+ # Short-Description: nginx(OpenResty) HTTP and reverse proxy server.
15
+ ### END INIT INFO
16
+ #
17
+
18
+ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
19
+ DESC="nginx(OpenResty) Daemon"
20
+ PREFIX=<%= @prefix %>
21
+ DAEMON=<%= @sbin_path %>
22
+ CONF=<%= @config_path %>
23
+ PID=<%= @pid_path %>
24
+ SCRIPT=<%= @init_script_path %>
25
+
26
+ if [ ! -x "$DAEMON" ]; then
27
+ echo -e "\033[33m $DAEMON has no permission to run. \033[0m"
28
+ sleep 1
29
+ exit 1
30
+ fi
31
+
32
+ if [ ! -f "$CONF" ]; then
33
+ echo -e "\033[33m Or $CONF doesn't exist. \033[0m"
34
+ sleep 1
35
+ exit 1
36
+ fi
37
+
38
+ do_start() {
39
+ if [ -f $PID ]; then
40
+ echo -e "\033[33m $PID already exists. \033[0m"
41
+ echo -e "\033[33m $DESC is already running or crashed. \033[0m"
42
+ echo -e "\033[32m $DESC Reopening $CONF ... \033[0m"
43
+ $DAEMON -s reopen -c $CONF
44
+ sleep 1
45
+ echo -e "\033[36m $DESC reopened. \033[0m"
46
+ else
47
+ echo -e "\033[32m $DESC Starting $CONF ... \033[0m"
48
+ $DAEMON -c $CONF
49
+ sleep 1
50
+ echo -e "\033[36m $DESC started. \033[0m"
51
+ fi
52
+ }
53
+
54
+ do_stop() {
55
+ if [ ! -f $PID ]; then
56
+ echo -e "\033[33m $PID doesn't exist. \033[0m"
57
+ echo -e "\033[33m $DESC isn't running. \033[0m"
58
+ else
59
+ echo -e "\033[32m $DESC Stopping $CONF ... \033[0m"
60
+ $DAEMON -s stop -c $CONF
61
+ sleep 1
62
+ echo -e "\033[36m $DESC stopped. \033[0m"
63
+ fi
64
+ }
65
+
66
+ do_reload() {
67
+ if [ ! -f $PID ]; then
68
+ echo -e "\033[33m $PID doesn't exist. \033[0m"
69
+ echo -e "\033[33m $DESC isn't running. \033[0m"
70
+ echo -e "\033[32m $DESC Starting $CONF ... \033[0m"
71
+ $DAEMON -c $CONF
72
+ sleep 1
73
+ echo -e "\033[36m $DESC started. \033[0m"
74
+ else
75
+ echo -e "\033[32m $DESC Reloading $CONF ... \033[0m"
76
+ $DAEMON -s reload -c $CONF
77
+ sleep 1
78
+ echo -e "\033[36m $DESC reloaded. \033[0m"
79
+ fi
80
+ }
81
+
82
+ do_quit() {
83
+ if [ ! -f $PID ]; then
84
+ echo -e "\033[33m $PID doesn't exist. \033[0m"
85
+ echo -e "\033[33m $DESC isn't running. \033[0m"
86
+ else
87
+ echo -e "\033[32m $DESC Quitting $CONF ... \033[0m"
88
+ $DAEMON -s quit -c $CONF
89
+ sleep 1
90
+ echo -e "\033[36m $DESC quitted. \033[0m"
91
+ fi
92
+ }
93
+
94
+ do_test() {
95
+ echo -e "\033[32m $DESC Testing $CONF ... \033[0m"
96
+ $DAEMON -t -c $CONF
97
+ }
98
+
99
+ do_info() {
100
+ $DAEMON -V
101
+ }
102
+
103
+ case "$1" in
104
+ start)
105
+ do_start
106
+ ;;
107
+ stop)
108
+ do_stop
109
+ ;;
110
+ reload)
111
+ do_reload
112
+ ;;
113
+ restart)
114
+ do_stop
115
+ do_start
116
+ ;;
117
+ quit)
118
+ do_quit
119
+ ;;
120
+ test)
121
+ do_test
122
+ ;;
123
+ info)
124
+ do_info
125
+ ;;
126
+ *)
127
+ echo "Usage: $SCRIPT {start|stop|reload|restart|quit|test|info}"
128
+ exit 2
129
+ ;;
130
+ esac
131
+
132
+ :
@@ -0,0 +1,47 @@
1
+ require 'itamae/plugin/recipe/openresty'
2
+
3
+ metadata = Itamae::Plugin::Recipe::Openresty.extract_metadata(node)
4
+
5
+ if metadata[:install_depends_package]
6
+ Itamae::Plugin::Recipe::Openresty::DEFAULT_PACKAGES[os[:family].to_sym].each do |pkg|
7
+ package pkg
8
+ end
9
+ end
10
+
11
+ execute 'create openresty install working directory' do
12
+ command "mkdir -p #{metadata[:work_dir]}"
13
+ end
14
+
15
+ execute 'download openresty archive file' do
16
+ command "wget #{metadata[:archive_url]} -O #{metadata[:work_dir]}/openresty.tar.gz"
17
+ not_if "test #{metadata[:work_dir]}/openresty.tar.gz"
18
+ end
19
+
20
+ execute 'unzip openresty' do
21
+ command "tar xvfz #{metadata[:work_dir]}/openresty.tar.gz -C #{metadata[:work_dir]}"
22
+ not_if "test #{metadata[:work_dir]}/ngx_openresty-#{metadata[:version]}"
23
+ end
24
+
25
+ execute 'build openresty' do
26
+ command "cd #{metadata[:work_dir]}/ngx_openresty-#{metadata[:version]} && ./configure #{metadata[:configure_flags].join(' ')} && make && make install"
27
+ unless ENV['OPENRESTY_REBUILD'] != nil
28
+ not_if "test #{Itamae::Plugin::Recipe::Openresty.sbin_path(node)}"
29
+ end
30
+ end
31
+
32
+ init_script_options = Itamae::Plugin::Recipe::Openresty.extract_init_script_options(node)
33
+ template init_script_options[:init_script_path] do
34
+ source 'assets/openresty.init.erb'
35
+ action :create
36
+ variables(init_script_options)
37
+ end
38
+
39
+ execute 'setup openresty init script' do
40
+ command "chmod +x #{init_script_options[:init_script_path]}"
41
+ only_if "test #{init_script_options[:init_script_path]}"
42
+ end
43
+
44
+ service 'openresty' do
45
+ name init_script_options[:init_script_path].split('/').last
46
+ action :enable
47
+ end
@@ -0,0 +1,9 @@
1
+ module Itamae
2
+ module Plugin
3
+ module Recipe
4
+ module Openresty
5
+ VERSION = "0.0.1"
6
+ end
7
+ end
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: itamae-plugin-recipe-openresty
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Takatoshi Maeda
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-29 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
+ description: Itamae openresty recipe plugin
42
+ email:
43
+ - me@tmd.tw
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - itamae-plugin-recipe-openresty.gemspec
54
+ - lib/itamae/plugin/recipe/openresty.rb
55
+ - lib/itamae/plugin/recipe/openresty/assets/openresty.init.erb
56
+ - lib/itamae/plugin/recipe/openresty/source.rb
57
+ - lib/itamae/plugin/recipe/openresty/version.rb
58
+ homepage: ''
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.2.2
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Itamae openresty recipe plugin
82
+ test_files: []