rails-ahoy 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.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/ahoy.gemspec +24 -0
- data/lib/ahoy.rb +5 -0
- data/lib/ahoy/version.rb +3 -0
- data/lib/generators/ahoy/ansible_generator.rb +36 -0
- data/lib/generators/ahoy/base.rb +24 -0
- data/lib/generators/ahoy/deploy_generator.rb +47 -0
- data/lib/generators/ahoy/init_generator.rb +49 -0
- data/lib/generators/ahoy/templates/_Vagrantfile +20 -0
- data/lib/generators/ahoy/templates/_database.yml +18 -0
- data/lib/generators/ahoy/templates/_deploy.rb +51 -0
- data/lib/generators/ahoy/templates/_env_vars.yml +7 -0
- data/lib/generators/ahoy/templates/_puma.rb +24 -0
- data/lib/generators/ahoy/templates/_puma.sh +79 -0
- data/lib/generators/ahoy/templates/ansible/playbooks/playbook.yml +22 -0
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/deploy_env/tasks/main.yml +10 -0
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/deploy_env/templates/database.yml +9 -0
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/deploy_env/templates/secrets.yml +2 -0
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/essentials/tasks/main.yml +43 -0
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/essentials/templates/vimrc +472 -0
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/nginx/tasks/main.yml +15 -0
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/nginx/templates/platform.conf +24 -0
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/nodejs/tasks/main.yml +6 -0
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/postgresql/handlers/main.yml +3 -0
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/postgresql/tasks/main.yml +39 -0
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/postgresql/templates/pg_hba.conf +91 -0
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/ruby/files/gemrc +5 -0
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/ruby/tasks/gems.yml +6 -0
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/ruby/tasks/main.yml +4 -0
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/ruby/tasks/rbenv.yml +31 -0
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/ruby/tasks/ruby.yml +15 -0
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/security/tasks/firewall.yml +6 -0
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/security/tasks/main.yml +9 -0
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/user/tasks/main.yml +6 -0
- data/lib/generators/ahoy/templates/ansible/playbooks/tasks/vagrant_settings.yml +3 -0
- data/lib/generators/ahoy/templates/ansible_templates/_hosts +5 -0
- data/lib/generators/ahoy/templates/ansible_templates/_provision.sh +1 -0
- data/lib/generators/ahoy/templates/ansible_templates/playbooks/group_vars/_all.yml +6 -0
- data/lib/generators/ahoy/templates/ansible_templates/playbooks/host_vars/_default.yml +8 -0
- data/lib/generators/ahoy/templates/ansible_templates/playbooks/host_vars/_production_deploy.yml +7 -0
- data/lib/generators/ahoy/templates/ansible_templates/playbooks/host_vars/_production_root.yml +2 -0
- data/lib/generators/ahoy/templates/ansible_templates/playbooks/roles/security/tasks/_ssh_settings.yml +25 -0
- data/lib/generators/ahoy/vagrant_generator.rb +52 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0243134f09fc42ce05630abbe6b2a8224292a903
|
4
|
+
data.tar.gz: db22045904e68900afc1cb5d2888df4574305ad1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 15ac64bbe9c3147a0f7a31085eccdb45be40a64b6dc07baa44eb12f6498e61fe485808817508bcd25963c025ed6c343740d734e159117ecad96df7fd7f8b3b6f
|
7
|
+
data.tar.gz: ac78e1fb7af0cb995ce488e7a3bd8616ffb6d9693f20022444e9793329e7a05512a17b979966f83c892e5983e16005a366bdd73831303bdde793f694c8958dd4
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Nathan Pearson
|
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,31 @@
|
|
1
|
+
# Ahoy
|
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 'ahoy'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ahoy
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/ahoy/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
|
data/Rakefile
ADDED
data/ahoy.gemspec
ADDED
@@ -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
|
+
require 'ahoy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rails-ahoy"
|
8
|
+
spec.version = Ahoy::VERSION
|
9
|
+
spec.authors = ["Nathan Pearson"]
|
10
|
+
spec.email = ["npearson72@gmail.com"]
|
11
|
+
spec.summary = "Quick and painless Rails deployment"
|
12
|
+
spec.description = "Generator for building ansible based provisioning scripts, and mina/puma deployment scripts"
|
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
|
24
|
+
|
data/lib/ahoy.rb
ADDED
data/lib/ahoy/version.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'generators/ahoy/base'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
module Ahoy
|
6
|
+
class AnsibleGenerator < Ahoy::Generator::Base
|
7
|
+
|
8
|
+
def prompt_user
|
9
|
+
defaults('127.0.0.1')
|
10
|
+
@server_ip = ask('=> Which IP address will you be deploying to? [enter for default]').chomp
|
11
|
+
defaults('22')
|
12
|
+
@server_ssh_port = ask('=> What SSH port would you like to use on your server? [enter for default]').chomp
|
13
|
+
defaults('2.1.5')
|
14
|
+
@ruby_version = ask('=> Which version of Ruby would you like to install? [enter for default]').chomp
|
15
|
+
defaults('9.3')
|
16
|
+
@postgresql_version = ask('=> Which version of PostgreSQL would you like to install? [enter for default]').chomp
|
17
|
+
end
|
18
|
+
|
19
|
+
def copy_directory
|
20
|
+
directory 'ansible', 'config/ansible'
|
21
|
+
end
|
22
|
+
|
23
|
+
def copy_templates
|
24
|
+
template 'ansible_templates/_provision.sh', 'config/ansible/provision.sh'
|
25
|
+
template 'ansible_templates/_hosts', 'config/ansible/hosts'
|
26
|
+
template 'ansible_templates/playbooks/group_vars/_all.yml', 'config/ansible/playbooks/group_vars/all.yml'
|
27
|
+
template 'ansible_templates/playbooks/host_vars/_production_root.yml', 'config/ansible/playbooks/host_vars/production_root.yml'
|
28
|
+
template 'ansible_templates/playbooks/host_vars/_production_deploy.yml', 'config/ansible/playbooks/host_vars/production_deploy.yml'
|
29
|
+
template 'ansible_templates/playbooks/roles/security/tasks/_ssh_settings.yml', 'config/ansible/playbooks/roles/security/tasks/ssh_settings.yml'
|
30
|
+
end
|
31
|
+
|
32
|
+
def change_permissions
|
33
|
+
FileUtils.chmod 0751, 'config/ansible/provision.sh'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Ahoy
|
2
|
+
module Initialize
|
3
|
+
def root
|
4
|
+
File.dirname(__FILE__)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
module Generator
|
9
|
+
extend Initialize
|
10
|
+
|
11
|
+
class Base < Rails::Generators::Base
|
12
|
+
def self.source_root
|
13
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def defaults(value)
|
19
|
+
puts '-' * 100
|
20
|
+
puts "Default: #{value}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'generators/ahoy/base'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
module Ahoy
|
6
|
+
class DeployGenerator < Ahoy::Generator::Base
|
7
|
+
|
8
|
+
def use_deploy
|
9
|
+
defaults('No')
|
10
|
+
@use_deploy = yes?('=> Would you like to setup deployment files using Puma and Mina? [enter for default]')
|
11
|
+
end
|
12
|
+
|
13
|
+
def prompt_user
|
14
|
+
if @use_deploy
|
15
|
+
@github_repo = ask('=> What is the github repository for this application?').chomp
|
16
|
+
defaults('127.0.0.1')
|
17
|
+
@server_ip = ask('=> Which IP address will you be deploying to? [enter for default]').chomp
|
18
|
+
defaults('22')
|
19
|
+
@server_ssh_port = ask('=> What SSH port would you like to use on your server? [enter for default]').chomp
|
20
|
+
copy_templates
|
21
|
+
add_gems
|
22
|
+
change_permissions
|
23
|
+
else
|
24
|
+
puts 'Skipping deployment scripts'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def copy_templates
|
31
|
+
template '_puma.sh', 'bin/puma.sh'
|
32
|
+
template '_puma.rb', 'config/puma.rb'
|
33
|
+
template '_deploy.rb', 'config/deploy.rb'
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_gems
|
37
|
+
gem_group :production do
|
38
|
+
gem 'puma'
|
39
|
+
gem 'rb-readline'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def change_permissions
|
44
|
+
FileUtils.chmod 0751, 'bin/puma.sh'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'generators/ahoy/base'
|
3
|
+
|
4
|
+
module Ahoy
|
5
|
+
class InitGenerator < Ahoy::Generator::Base
|
6
|
+
|
7
|
+
def init
|
8
|
+
divider
|
9
|
+
masthead
|
10
|
+
divider
|
11
|
+
generate 'ahoy:ansible'
|
12
|
+
divider
|
13
|
+
generate 'ahoy:vagrant'
|
14
|
+
divider
|
15
|
+
generate 'ahoy:deploy'
|
16
|
+
divider
|
17
|
+
puts 'Finalizing...'
|
18
|
+
copy_env_vars_file
|
19
|
+
divider
|
20
|
+
puts 'Finished!'
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def copy_env_vars_file
|
26
|
+
template '_env_vars.yml', 'config/env_vars.yml'
|
27
|
+
append_file '.gitignore', 'config/env_vars.yml'
|
28
|
+
end
|
29
|
+
|
30
|
+
def divider
|
31
|
+
puts '=' * 100
|
32
|
+
end
|
33
|
+
|
34
|
+
def masthead
|
35
|
+
puts ' ___ ___ ___ ___ '
|
36
|
+
puts ' / /\ /__/\ / /\ /__/| '
|
37
|
+
puts ' / /++\ \ \+\ / /++\ | |+| '
|
38
|
+
puts ' / /+/\+\ \__\+\ / /+/\+\ | |+| ' + ' Ahoy!'
|
39
|
+
puts ' / /+/~/++\ ___ / /++\ / /+/ \+\ | |+| ' + ' Get your Rails app deployed'
|
40
|
+
puts ' /__/+/ /+/\+\ /__/\ /+/\+\ /__/+/ \__\+\ ___|__|+| '
|
41
|
+
puts ' \ \+\/+/__\/ \ \+\/+/__\/ \ \+\ / /+/ /__/+++++\ ' + " v.#{Ahoy::VERSION}"
|
42
|
+
puts ' \ \++/ \ \++/ \ \+\ /+/ \__\~~~~++\ '
|
43
|
+
puts ' \ \+\ \ \+\ \ \+\/+/ \ \+\ '
|
44
|
+
puts ' \ \+\ \ \+\ \ \++/ \ \+\ '
|
45
|
+
puts ' \__\/ \__\/ \__\/ \__\/ '
|
46
|
+
puts
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
VAGRANTFILE_API_VERSION = 2
|
5
|
+
|
6
|
+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
7
|
+
config.vm.box = 'hashicorp/precise64'
|
8
|
+
|
9
|
+
config.vm.network :forwarded_port, guest: 3000, host: 3000
|
10
|
+
|
11
|
+
config.vm.provider 'virtualbox' do |v|
|
12
|
+
v.memory = <%= @memory == 0 ? 2048 : (@memory * 1024) %>
|
13
|
+
v.cpus = <%= @cpus == 0 ? 1 : @cpus %>
|
14
|
+
end
|
15
|
+
|
16
|
+
config.vm.provision 'ansible' do |ansible|
|
17
|
+
ansible.playbook = 'config/ansible/playbooks/playbook.yml'
|
18
|
+
ansible.limit = 'default'
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
default: &default
|
2
|
+
adapter: postgresql
|
3
|
+
host: localhost
|
4
|
+
encoding: unicode
|
5
|
+
ctype: en_US.utf8
|
6
|
+
collation: en_US.utf8
|
7
|
+
template: template0
|
8
|
+
pool: 5
|
9
|
+
username: vagrant
|
10
|
+
password: vagrant
|
11
|
+
|
12
|
+
development:
|
13
|
+
<<: *default
|
14
|
+
database: <%= Rails.application.class.parent_name.underscore %>_development
|
15
|
+
|
16
|
+
test:
|
17
|
+
<<: *default
|
18
|
+
database: <%= Rails.application.class.parent_name.underscore %>_test
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'mina/bundler'
|
2
|
+
require 'mina/rails'
|
3
|
+
require 'mina/git'
|
4
|
+
require 'mina/rbenv'
|
5
|
+
|
6
|
+
set :repository, "<%= @github_repo %>"
|
7
|
+
set :branch, 'master'
|
8
|
+
set :deploy_to, "/var/www/<%= Rails.application.class.parent_name.underscore %>"
|
9
|
+
set :app_path, "/var/www/<%= Rails.application.class.parent_name.underscore %>/current"
|
10
|
+
set :forward_agent, true
|
11
|
+
set :shared_paths, ['config/database.yml', 'config/secrets.yml', 'log', 'tmp']
|
12
|
+
|
13
|
+
task :production do
|
14
|
+
set :user, 'deploy'
|
15
|
+
set :domain, "<%= @server_ip == '' ? '127.0.0.1' : @server_ip %>"
|
16
|
+
set :port, <%= @server_ssh_port == '' ? '22' : @server_ssh_port %>
|
17
|
+
set :stage, 'production'
|
18
|
+
end
|
19
|
+
|
20
|
+
task :environment do
|
21
|
+
queue! %[export PATH="/usr/local/rbenv/bin:/usr/local/rbenv/shims:$PATH"]
|
22
|
+
end
|
23
|
+
|
24
|
+
task :setup => :environment do
|
25
|
+
['log', 'config', 'tmp/log', 'tmp/pids', 'tmp/sockets'].each do |dir|
|
26
|
+
queue! %[mkdir -m 750 -p "#{deploy_to}/#{shared_path}/#{dir}"]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
task :deploy => :environment do
|
31
|
+
deploy do
|
32
|
+
invoke :'git:clone'
|
33
|
+
invoke :'deploy:link_shared_paths'
|
34
|
+
invoke :'bundle:install'
|
35
|
+
invoke :'rails:db_migrate'
|
36
|
+
invoke :'rails:assets_precompile'
|
37
|
+
invoke :'deploy:cleanup'
|
38
|
+
|
39
|
+
to :launch do
|
40
|
+
invoke :'server:restart'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
namespace :server do
|
46
|
+
[:start, :stop, :restart].each do |action|
|
47
|
+
task action do
|
48
|
+
queue "cd #{app_path} && RAILS_ENV=#{stage} && bin/puma.sh #{action}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
application_name: <%= Rails.application.class.parent_name.underscore %>
|
3
|
+
production:
|
4
|
+
db_name: <%= Rails.application.class.parent_name.underscore %>_production
|
5
|
+
db_user: deploy
|
6
|
+
db_password: # Remember to add your own!!
|
7
|
+
secret_key_base: # Remember to add your own!!
|
@@ -0,0 +1,24 @@
|
|
1
|
+
workers Integer(ENV['PUMA_WORKERS'] || 3)
|
2
|
+
threads Integer(ENV['MIN_THREADS'] || 1), Integer(ENV['MAX_THREADS'] || 16)
|
3
|
+
|
4
|
+
preload_app!
|
5
|
+
|
6
|
+
rackup DefaultRackup
|
7
|
+
port ENV['PORT'] || 3000
|
8
|
+
environment ENV['RACK_ENV'] || 'production'
|
9
|
+
|
10
|
+
daemonize true
|
11
|
+
|
12
|
+
pidfile "/var/www/<%= Rails.application.class.parent_name.underscore %>/shared/tmp/pids/puma.pid"
|
13
|
+
stdout_redirect "/var/www/<%= Rails.application.class.parent_name.underscore %>/shared/tmp/log/stdout", "/var/www/<%= Rails.application.class.parent_name.underscore %>/shared/tmp/log/stderr"
|
14
|
+
|
15
|
+
bind "unix:///var/www/<%= Rails.application.class.parent_name.underscore %>/shared/tmp/sockets/puma.sock"
|
16
|
+
|
17
|
+
on_worker_boot do
|
18
|
+
# worker specific setup
|
19
|
+
ActiveSupport.on_load(:active_record) do
|
20
|
+
config = ActiveRecord::Base.configurations[Rails.env] || Rails.application.config.database_configuration[Rails.env]
|
21
|
+
config['pool'] = ENV['MAX_THREADS'] || 16
|
22
|
+
ActiveRecord::Base.establish_connection(config)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
#! /bin/sh
|
2
|
+
|
3
|
+
BUNDLE_BIN=/usr/local/rbenv/shims/bundle
|
4
|
+
APP_PATH=/var/www/<%= Rails.application.class.parent_name.underscore %>
|
5
|
+
PUMA_CONFIG_FILE=$APP_PATH/current/config/puma.rb
|
6
|
+
PUMA_PID_FILE=$APP_PATH/shared/tmp/pids/puma.pid
|
7
|
+
PUMA_SOCKET=$APP_PATH/shared/tmp/sockets/puma.sock
|
8
|
+
|
9
|
+
# check if puma process is running
|
10
|
+
puma_is_running() {
|
11
|
+
if [ -S $PUMA_SOCKET ] ; then
|
12
|
+
if [ -e $PUMA_PID_FILE ] ; then
|
13
|
+
if cat $PUMA_PID_FILE | xargs pgrep -P > /dev/null ; then
|
14
|
+
return 0
|
15
|
+
else
|
16
|
+
echo "No puma process found"
|
17
|
+
fi
|
18
|
+
else
|
19
|
+
echo "No puma pid file found"
|
20
|
+
fi
|
21
|
+
else
|
22
|
+
echo "No puma socket found"
|
23
|
+
fi
|
24
|
+
|
25
|
+
return 1
|
26
|
+
}
|
27
|
+
|
28
|
+
puma_start() {
|
29
|
+
rm -f $PUMA_SOCKET
|
30
|
+
if [ -e $PUMA_CONFIG_FILE ] ; then
|
31
|
+
$BUNDLE_BIN exec puma -C $PUMA_CONFIG_FILE
|
32
|
+
else
|
33
|
+
$BUNDLE_BIN exec puma
|
34
|
+
fi
|
35
|
+
}
|
36
|
+
|
37
|
+
puma_stop() {
|
38
|
+
cat $PUMA_PID_FILE | xargs kill -31
|
39
|
+
rm -f $PUMA_PID_FILE
|
40
|
+
rm -f $PUMA_SOCKET
|
41
|
+
}
|
42
|
+
|
43
|
+
case "$1" in
|
44
|
+
start)
|
45
|
+
echo "Starting puma..."
|
46
|
+
puma_start
|
47
|
+
echo "done"
|
48
|
+
;;
|
49
|
+
|
50
|
+
stop)
|
51
|
+
echo "Stopping puma..."
|
52
|
+
puma_stop
|
53
|
+
echo "done"
|
54
|
+
;;
|
55
|
+
|
56
|
+
restart)
|
57
|
+
if puma_is_running ; then
|
58
|
+
echo "Hot-restarting puma..."
|
59
|
+
puma_stop
|
60
|
+
puma_start
|
61
|
+
|
62
|
+
echo "Doublechecking the process restart..."
|
63
|
+
sleep 5
|
64
|
+
if puma_is_running ; then
|
65
|
+
echo "done"
|
66
|
+
exit 0
|
67
|
+
else
|
68
|
+
echo "Puma restart failed :/"
|
69
|
+
fi
|
70
|
+
fi
|
71
|
+
|
72
|
+
echo "Trying cold reboot"
|
73
|
+
bin/puma.sh start
|
74
|
+
;;
|
75
|
+
|
76
|
+
*)
|
77
|
+
echo "Usage: script/puma.sh {start|stop|restart}" >&2
|
78
|
+
;;
|
79
|
+
esac
|