daemonize_rails 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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +27 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/bin/daemonize_rails +18 -0
- data/daemonize_rails.gemspec +23 -0
- data/lib/daemonize_rails.rb +65 -0
- data/lib/daemonize_rails/version.rb +3 -0
- data/lib/init_template.erb +91 -0
- data/lib/unicorn_template.erb +24 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4469f0167727400cd7a191b35875b1b6471d7b13
|
4
|
+
data.tar.gz: fe8c9f443c25648a551a25a0e6f7dd1766814e9d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6e90c0fbc51ed336bbfcacebfc846072649b186412bf5476078e321c0afe8466bf5edd5923c7556aaab363b4c26c9ca18e89576fdec381d16fd86422e59a44ff
|
7
|
+
data.tar.gz: 9893e589bf08f333fd4296a69ea18a1dd244f25bb38f47f196d1e807b144e4ef03e2b3fe7b23e1ae164bdc8df4bad1c59ca65602ef57e14501d2c0676f80e28a
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
Copyright (c) 2014, Joel Byron Smith
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
|
10
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
12
|
+
and/or other materials provided with the distribution.
|
13
|
+
|
14
|
+
* Neither the name of Trosic nor the names of its
|
15
|
+
contributors may be used to endorse or promote products derived from
|
16
|
+
this software without specific prior written permission.
|
17
|
+
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
22
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
23
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
24
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
25
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
26
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Daemonize Rails
|
2
|
+
|
3
|
+
**Intended for use with Debian/Ubuntu, Unicorn and Nginx**
|
4
|
+
|
5
|
+
Daemonize Rails will configure your server to add a new process for your rails app in production.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'daemonize_rails'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install daemonize_rails
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( http://github.com/jbsmith86/daemonize_rails/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 new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/daemonize_rails
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'daemonize_rails'
|
4
|
+
|
5
|
+
app_path = Dir.pwd
|
6
|
+
|
7
|
+
if app_path[/^\/var\/www\/[a-zA-Z0-9\-_.]+/] != app_path
|
8
|
+
raise "Folder check invalid. Please put you Rails project in \"/var/www\""
|
9
|
+
end
|
10
|
+
|
11
|
+
unicorn_binding = DaemonizeRails::UnicornConfig.new(app_name, workers).get_binding
|
12
|
+
init_binding = DaemonizeRails::InitConfig.new(app_name, `echo $PATH`.chomp).get_binding
|
13
|
+
|
14
|
+
unicorn = DaemonizeRails::Unicorn.new(unicorn_binding, app_name)
|
15
|
+
init = DaemonizeRails::Init.new(unicorn_binding, app_name)
|
16
|
+
|
17
|
+
unicorn.create_file
|
18
|
+
init.create_file
|
@@ -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 'daemonize_rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "daemonize_rails"
|
8
|
+
spec.version = DaemonizeRails::VERSION
|
9
|
+
spec.authors = ["Joel Smith"]
|
10
|
+
spec.email = ["joel@trosic.com"]
|
11
|
+
spec.summary = "Daemonize Rails is a Gem to make a system process for your Rails app."
|
12
|
+
spec.description = "Daemonize Rails will configure your server to add a new process for your rails app in production."
|
13
|
+
spec.homepage = "http://www.github.com/jbsmith86/daemonize_rails"
|
14
|
+
spec.license = "BSD-3-Clause-Clear"
|
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.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "daemonize_rails/version"
|
2
|
+
require "erb"
|
3
|
+
|
4
|
+
module DaemonizeRails
|
5
|
+
class Unicorn
|
6
|
+
def initialize(bindings, app_name)
|
7
|
+
@bindings = bindings
|
8
|
+
@app_name = app_name
|
9
|
+
@app_path = "/var/www/#{app_name}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_file
|
13
|
+
#check_and_create_folder(@app_path + "/tmp")
|
14
|
+
#check_and_create_folder(@app_path + "/tmp/pids")
|
15
|
+
unicorn_file = ERB.new File.new("unicorn_template.erb").read, nil, "%"
|
16
|
+
create_file "config/unicorn.rb", unicorn_file.result(@bindings)
|
17
|
+
puts `chmod 755 ./config/unicorn.rb`
|
18
|
+
end
|
19
|
+
|
20
|
+
def check_and_create_folder(path)
|
21
|
+
if !File.exists? path
|
22
|
+
Dir.mkdir path
|
23
|
+
puts `chmod 755 #{path}`
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Init
|
29
|
+
def initialize(bindings, app_name)
|
30
|
+
@bindings = bindings
|
31
|
+
@app_name = app_name
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_file
|
35
|
+
init_file = ERB.new File.new("init_template.erb").read, nil, "%"
|
36
|
+
init_output = open("/etc/init.d/#{@app_name}", 'w') { |f| f.puts init_file.result(@bindings) }
|
37
|
+
init_output.close
|
38
|
+
puts `chmod 755 /etc/init.d/#{app_name}`
|
39
|
+
puts `chmod +x /etc/init.d/#{app_name}`
|
40
|
+
puts `update-rc.d #{app_name} defaults`
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class UnicornConfig
|
45
|
+
def initialize(app_name, workers)
|
46
|
+
@app_name = app_name
|
47
|
+
@workers = workers
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_binding
|
51
|
+
return binding()
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class InitConfig
|
56
|
+
def initialize(app_name, path)
|
57
|
+
@app_name = app_name
|
58
|
+
@path = path
|
59
|
+
end
|
60
|
+
|
61
|
+
def get_binding
|
62
|
+
return binding()
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
# /etc/init.d/<%= @app_name %>
|
3
|
+
|
4
|
+
# ### BEGIN INIT INFO
|
5
|
+
# Provides: <%= @app_name %>
|
6
|
+
# Required-Start: $network $remote_fs $local_fs
|
7
|
+
# Required-Stop: $network $remote_fs $local_fs
|
8
|
+
# Default-Start: 2 3 4 5
|
9
|
+
# Default-Stop: 0 1 6
|
10
|
+
# Short-Description: Stop/start <%= @app_name %>
|
11
|
+
### END INIT INFO
|
12
|
+
|
13
|
+
export PATH=<%= @path %>
|
14
|
+
|
15
|
+
PROJ_NAME="<%= @app_name %>"
|
16
|
+
PID_FILE=/var/www/<%= @app_name %>/tmp/pids/unicorn.pid
|
17
|
+
OLD_PID_FILE=$PID_FILE.oldbin
|
18
|
+
PROJ_DIR=/var/www/<%= @app_name %>
|
19
|
+
TAG='[<%= @app_name %>]'
|
20
|
+
UNICORN_CONFIG=config/unicorn.rb
|
21
|
+
RAILS_ENV=${RAILS_ENV:-production}
|
22
|
+
|
23
|
+
# Start the service
|
24
|
+
start() {
|
25
|
+
if [[ -f $PID_FILE ]]; then
|
26
|
+
logger -sit $TAG "There is a PID file in $PID_FILE. Service should be running"
|
27
|
+
exit 1
|
28
|
+
else
|
29
|
+
logger -sit "$TAG" "Trying to start server..."
|
30
|
+
cd $PROJ_DIR ; bundle exec unicorn -c $UNICORN_CONFIG -E $RAILS_ENV -D
|
31
|
+
if [[ $? == 0 ]]; then
|
32
|
+
logger -sit "$TAG" "server started"
|
33
|
+
else
|
34
|
+
logger -sit "$TAG" "FAILED to start server"
|
35
|
+
exit 1
|
36
|
+
fi
|
37
|
+
fi
|
38
|
+
}
|
39
|
+
|
40
|
+
# Stop the service
|
41
|
+
stop() {
|
42
|
+
kill -TERM $(cat $PID_FILE)
|
43
|
+
sleep 2
|
44
|
+
if [[ ! -f $PID_FILE ]]; then
|
45
|
+
logger -sit "$TAG" "Server stoped"
|
46
|
+
else
|
47
|
+
logger -sit "$TAG" "FAILED to stop server"
|
48
|
+
exit 1
|
49
|
+
fi
|
50
|
+
}
|
51
|
+
|
52
|
+
# Reload service
|
53
|
+
reload() {
|
54
|
+
logger -sit "$TAG" "Trying to reload server"
|
55
|
+
kill -USR2 $(cat $PID_FILE)
|
56
|
+
sleep 1
|
57
|
+
if [[ -f $OLD_PID_FILE ]]; then
|
58
|
+
logger -sit "$TAG" "Server reloaded"
|
59
|
+
else
|
60
|
+
logger -sit "$TAG" "FAILED to reload server"
|
61
|
+
exit 1
|
62
|
+
fi
|
63
|
+
}
|
64
|
+
|
65
|
+
restart() {
|
66
|
+
logger -sit "$TAG" "Restarting server"
|
67
|
+
kill -HUP $(cat $PID_FILE)
|
68
|
+
}
|
69
|
+
|
70
|
+
### main logic ###
|
71
|
+
case "$1" in
|
72
|
+
start)
|
73
|
+
start
|
74
|
+
;;
|
75
|
+
|
76
|
+
stop)
|
77
|
+
stop
|
78
|
+
;;
|
79
|
+
|
80
|
+
restart)
|
81
|
+
restart
|
82
|
+
;;
|
83
|
+
reload)
|
84
|
+
reload
|
85
|
+
;;
|
86
|
+
*)
|
87
|
+
echo $"Usage: $0 {start|stop|restart|reload}"
|
88
|
+
exit 1
|
89
|
+
esac
|
90
|
+
|
91
|
+
exit 0
|
@@ -0,0 +1,24 @@
|
|
1
|
+
worker_processes <%= @workers %>
|
2
|
+
APP_PATH = "/var/www/<%= @app_name %>"
|
3
|
+
working_directory APP_PATH
|
4
|
+
listen "/tmp/unicorn.<%= @app_name %>.sock"
|
5
|
+
timeout 30
|
6
|
+
pid APP_PATH + "/tmp/pids/unicorn.pid"
|
7
|
+
stderr_path APP_PATH + "/log/unicorn.stderr.log"
|
8
|
+
stdout_path APP_PATH + "/log/unicorn.stdout.log"
|
9
|
+
|
10
|
+
preload_app true
|
11
|
+
GC.respond_to?(:copy_on_write_friendly=) and
|
12
|
+
GC.copy_on_write_friendly = true
|
13
|
+
|
14
|
+
check_client_connection false
|
15
|
+
|
16
|
+
before_fork do |server, worker|
|
17
|
+
defined?(ActiveRecord::Base) and
|
18
|
+
ActiveRecord::Base.connection.disconnect!
|
19
|
+
end
|
20
|
+
|
21
|
+
after_fork do |server, worker|
|
22
|
+
defined?(ActiveRecord::Base) and
|
23
|
+
ActiveRecord::Base.establish_connection
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: daemonize_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joel Smith
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-23 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.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Daemonize Rails will configure your server to add a new process for your
|
42
|
+
rails app in production.
|
43
|
+
email:
|
44
|
+
- joel@trosic.com
|
45
|
+
executables:
|
46
|
+
- daemonize_rails
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- ".gitignore"
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/daemonize_rails
|
56
|
+
- daemonize_rails.gemspec
|
57
|
+
- lib/daemonize_rails.rb
|
58
|
+
- lib/daemonize_rails/version.rb
|
59
|
+
- lib/init_template.erb
|
60
|
+
- lib/unicorn_template.erb
|
61
|
+
homepage: http://www.github.com/jbsmith86/daemonize_rails
|
62
|
+
licenses:
|
63
|
+
- BSD-3-Clause-Clear
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.2.2
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Daemonize Rails is a Gem to make a system process for your Rails app.
|
85
|
+
test_files: []
|