mina-unicorn_systemd 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +56 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +50 -0
- data/Rakefile +1 -0
- data/lib/mina/templates/unicorn.service.erb +43 -0
- data/lib/mina/unicorn.rb +105 -0
- data/lib/mina/unicorn/version.rb +5 -0
- data/mina-unicorn_systemd.gemspec +25 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f61e026a1e150bdc56cc14d0c20871a9ac4ab39f6a519de09d3debd713e210ab
|
4
|
+
data.tar.gz: 8db9dc35c5a631ad6488feb2c8d301cd893a03f931824e01dc2be3861a699431
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3467ec21d4ae700d9bbd2dda8ce6f5906ca0358e789693caab816a458bb465154b7a394f2b2f1a642566ebd122a38e7eae8e2996c79cab2e555233dfb14b0609
|
7
|
+
data.tar.gz: edb3c9611090d1dc8d09f4af1e5bd5ced4d206438e0f38a2439de90b1d4140a21ead936f1afdfa99236baa15dd9be98bf98f0964f318de953f5176b0afe8e137
|
data/.gitignore
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
+
# .rubocop-https?--*
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 coezbek
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# mina-unicorn_systemd
|
2
|
+
|
3
|
+
Gem extension for mina-deploy to enable easy setup and deployment of unicorn application server managed via systemd.
|
4
|
+
|
5
|
+
## Assumptions
|
6
|
+
|
7
|
+
This gem assumes that you
|
8
|
+
|
9
|
+
* Are on a Linux system with systemd in /etc/systemd/
|
10
|
+
* Are using RVM to manage your Ruby version
|
11
|
+
* That the setup task has sudoer or root permissions or that you are running with execution_mode :system and are entering passwords. If your regular user does not have sudo, then you can set the `setup_user` to the name of a user who does.
|
12
|
+
* Want to run nginx in front and that you want to update nginx configuration to point to unicorn instead.
|
13
|
+
|
14
|
+
## Basic installation instructions
|
15
|
+
|
16
|
+
1. Add the following to your Gemfile and make sure that unicorn is available in production environment
|
17
|
+
|
18
|
+
```
|
19
|
+
group :production do
|
20
|
+
gem 'unicorn'
|
21
|
+
end
|
22
|
+
|
23
|
+
group :development do
|
24
|
+
gem 'mina-unicorn_systemd', require: false # not necessary to load this when running rails
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
2. Change your `deploy.rb` to include `'mina/unicorn.rb'`. Make sure to add after `nginx`
|
29
|
+
|
30
|
+
```
|
31
|
+
require 'mina/nginx'
|
32
|
+
require 'mina/unicorn'
|
33
|
+
```
|
34
|
+
|
35
|
+
3. Manually run `'mina unicorn:setup'` or invoke from your own setup task.
|
36
|
+
|
37
|
+
4. Manually run `'mina unicorn:restart'` or invoke from your own deploy task.
|
38
|
+
|
39
|
+
## Customization
|
40
|
+
|
41
|
+
To change the unicorn systemd service template and/or the `unicorn_conf.rb`, run `'mina unicorn:generate'`.
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it ( http://github.com/coezbek/mina-unicorn_systemd/fork )
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Change gemfile to refer to your local version (`gem 'mina-unicorn_systemd', path: <your path>`)
|
48
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# This file was generated from the unicorn.service.erb template.
|
2
|
+
# It is deployed on unicorn:setup.
|
3
|
+
# To customize this template run the task unicorn:generate and modify locally
|
4
|
+
<% application = fetch :application_name, 'application' %>
|
5
|
+
[Unit]
|
6
|
+
Description=<%= application %> Unicorn service
|
7
|
+
After=network.target
|
8
|
+
|
9
|
+
[Service]
|
10
|
+
Type=forking
|
11
|
+
WorkingDirectory=/home/<%= application %>/app/
|
12
|
+
|
13
|
+
<%# Use the defined user and fall back to the application name -%>
|
14
|
+
User=<%= fetch :user, application %>
|
15
|
+
|
16
|
+
#
|
17
|
+
# How to actually start Unicorn?
|
18
|
+
#
|
19
|
+
# Needs to be adjusted for rbenv.
|
20
|
+
#
|
21
|
+
# Open question: would it be better to use a fully defined path? /usr/share/rvm/bin/rvm
|
22
|
+
#
|
23
|
+
ExecStart=/usr/share/rvm/bin/rvm in /home/<%= application %>/app/current/ do bundle exec unicorn -D -c /home/<%= application %>/app/current/config/unicorn.rb -E production
|
24
|
+
|
25
|
+
# How to identify in the logs:
|
26
|
+
SyslogIdentifier=unicorn-<%= application %>
|
27
|
+
|
28
|
+
# stop by sending only the main process a SIGQUIT signal
|
29
|
+
KillMode=process
|
30
|
+
KillSignal=SIGQUIT
|
31
|
+
|
32
|
+
# Enable reloading unicorn via HUP signal
|
33
|
+
ExecReload=/bin/kill -HUP $MAINPID
|
34
|
+
|
35
|
+
# Try to restart the service after 1 second
|
36
|
+
Restart=always
|
37
|
+
RestartSec=1
|
38
|
+
|
39
|
+
# Path to Unicorn PID file (as specified in unicorn configuration file)
|
40
|
+
PIDFile=/home/<%= application %>/app/shared/unicorn.pid
|
41
|
+
|
42
|
+
[Install]
|
43
|
+
WantedBy=multi-user.target
|
data/lib/mina/unicorn.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
require "mina/unicorn/version"
|
2
|
+
|
3
|
+
#
|
4
|
+
# The following tasks are for generating and setting up the systemd service which runs Unicorn
|
5
|
+
#
|
6
|
+
namespace :unicorn do
|
7
|
+
|
8
|
+
set :unicorn_service_name, -> { "unicorn-#{fetch(:application_name)}.service" }
|
9
|
+
set :unicorn_systemd_config_path, -> { "/etc/systemd/system/#{fetch :unicorn_service_name}" }
|
10
|
+
|
11
|
+
set :nginx_socket_path, -> { "#{fetch(:shared_path)}/unicorn.sock" }
|
12
|
+
|
13
|
+
desc "Generate Unicorn systemd service template in the local repo to customize it"
|
14
|
+
task :generate do
|
15
|
+
run :local do
|
16
|
+
|
17
|
+
target_path = File.expand_path("./config/deploy/templates/unicorn.service.erb")
|
18
|
+
source_path = File.expand_path("../templates/unicorn.service.erb", __FILE__)
|
19
|
+
|
20
|
+
if File.exist? target_path
|
21
|
+
error! %(Unicorn service template already exists; please rm to continue: #{target_path})
|
22
|
+
else
|
23
|
+
command %(mkdir -p config/deploy/templates)
|
24
|
+
command %(cp #{source_path} #{target_path})
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Setup Unicorn systemd service on the remote server"
|
31
|
+
task :setup do
|
32
|
+
|
33
|
+
elevate
|
34
|
+
|
35
|
+
comment %(Check for systemd on remote server)
|
36
|
+
command %([[ `systemctl` =~ -\.mount ]] || { echo 'Systemd not found, but mina-unicorn_systemd needs it.'; exit 1; }) # From https://unix.stackexchange.com/a/164092
|
37
|
+
|
38
|
+
target_path = fetch :unicorn_systemd_config_path
|
39
|
+
|
40
|
+
comment %(Installing unicorn systemd config file to #{target_path})
|
41
|
+
command %(echo '#{erb template_path}' > #{target_path})
|
42
|
+
|
43
|
+
comment %(Reloading systemd configuration)
|
44
|
+
command %(systemctl daemon-reload)
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
desc "Get the status of the Unicorn systemd service on the remote server"
|
49
|
+
task :status do
|
50
|
+
command %(systemctl status #{fetch :unicorn_service_name})
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "Start the Unicorn systemd service on the remote server"
|
54
|
+
task :start do
|
55
|
+
elevate
|
56
|
+
# Start the service and if it fails print the error information
|
57
|
+
command %((systemctl start #{fetch :unicorn_service_name} && systemctl status #{fetch :unicorn_service_name}) || journalctl --no-pager _SYSTEMD_INVOCATION_ID=`systemctl show -p InvocationID --value #{fetch :unicorn_service_name}`)
|
58
|
+
end
|
59
|
+
|
60
|
+
desc "Stop the Unicorn systemd service on the remote server"
|
61
|
+
task :stop do
|
62
|
+
elevate
|
63
|
+
command %((systemctl stop #{fetch :unicorn_service_name} && systemctl status #{fetch :unicorn_service_name}) || journalctl --no-pager _SYSTEMD_INVOCATION_ID=`systemctl show -p InvocationID --value #{fetch :unicorn_service_name}`)
|
64
|
+
end
|
65
|
+
|
66
|
+
desc "Restart the Unicorn systemd service on the remote server"
|
67
|
+
task :restart do
|
68
|
+
elevate
|
69
|
+
command %((systemctl restart #{fetch :unicorn_service_name} && systemctl status #{fetch :unicorn_service_name}) || journalctl --no-pager _SYSTEMD_INVOCATION_ID=`systemctl show -p InvocationID --value #{fetch :unicorn_service_name}`)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Returns the path to the template to use. Depending on whether the internal template was customized.
|
73
|
+
def template_path
|
74
|
+
|
75
|
+
custom_path = File.expand_path("./config/deploy/templates/unicorn.service.erb")
|
76
|
+
original_path = File.expand_path("../templates/unicorn.service.erb", __FILE__)
|
77
|
+
|
78
|
+
File.exist?(custom_path) ? custom_path : original_path
|
79
|
+
end
|
80
|
+
|
81
|
+
def elevate
|
82
|
+
|
83
|
+
user = fetch(:user)
|
84
|
+
setup_user = fetch(:setup_user, user)
|
85
|
+
if setup_user != user
|
86
|
+
comment %{Switching to setup_user (#{setup_user})}
|
87
|
+
set :user, setup_user
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
desc "Print Unicorn systemd service config expanded from the local template"
|
93
|
+
task :print do
|
94
|
+
run :local do
|
95
|
+
command %(echo '#{erb template_path}')
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
desc "Print current Unicorn systemd service config from remote"
|
100
|
+
task :print_remote do
|
101
|
+
unicorn_systemd_config_path = fetch :unicorn_systemd_config_path
|
102
|
+
command %(cat #{unicorn_systemd_config_path})
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mina/unicorn/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'mina-unicorn_systemd'
|
8
|
+
spec.version = Mina::Unicorn::VERSION
|
9
|
+
spec.authors = ['coezbek']
|
10
|
+
spec.email = ['c.oezbek@gmail.com']
|
11
|
+
spec.summary = %(Mina tasks for Unicorn setup and deployment.)
|
12
|
+
spec.description = %(Mina-deploy tasks to enable easy setup and deployment of unicorn application server managed via systemd)
|
13
|
+
spec.homepage = 'https://github.com/hbin/mina-unicorn_systemd.git'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($RS)
|
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_dependency 'mina', '~> 1.2'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
24
|
+
spec.add_development_dependency 'rake', '~> 0'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mina-unicorn_systemd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- coezbek
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-11-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mina
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
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
|
+
description: Mina-deploy tasks to enable easy setup and deployment of unicorn application
|
56
|
+
server managed via systemd
|
57
|
+
email:
|
58
|
+
- c.oezbek@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/mina/templates/unicorn.service.erb
|
69
|
+
- lib/mina/unicorn.rb
|
70
|
+
- lib/mina/unicorn/version.rb
|
71
|
+
- mina-unicorn_systemd.gemspec
|
72
|
+
homepage: https://github.com/hbin/mina-unicorn_systemd.git
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubygems_version: 3.1.4
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Mina tasks for Unicorn setup and deployment.
|
95
|
+
test_files: []
|