mina-unicorn_systemd 0.0.1 → 0.9.0
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 +4 -4
- data/README.md +6 -3
- data/lib/mina/templates/unicorn.service.erb +8 -3
- data/lib/mina/unicorn.rb +94 -35
- data/lib/mina/unicorn/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6123396e12d908365364a32d70b1bb5d124a93b5eae7a63ed07d6bd42cffb2e9
|
4
|
+
data.tar.gz: e5b0aa4b22c8bd93775a4776e83ec03a4f2307c9723a7dadfc919d3a73305897
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de663882a915c36815baa6fbbcc007b44e3fd3fcb0833166b9d53398b9ea7358b88110660de72504bc8de3dce31ba68ca51296c1a8998f26ff7505f942024254
|
7
|
+
data.tar.gz: 9a293f8c095a30c878f2ab0489d6feac95e1331b59faa4ef79da2895321a68e4696b65d9652d059e71e93ed25d5d18f196006252ec0ebd77848149ee493f47b9
|
data/README.md
CHANGED
@@ -9,7 +9,6 @@ This gem assumes that you
|
|
9
9
|
* Are on a Linux system with systemd in /etc/systemd/
|
10
10
|
* Are using RVM to manage your Ruby version
|
11
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
12
|
|
14
13
|
## Basic installation instructions
|
15
14
|
|
@@ -32,14 +31,18 @@ require 'mina/nginx'
|
|
32
31
|
require 'mina/unicorn'
|
33
32
|
```
|
34
33
|
|
35
|
-
3. Manually run `'mina unicorn:setup'` or invoke from your own setup task.
|
34
|
+
3. Manually run `'mina unicorn:setup'` or invoke from your own setup task to enable all one time tasks.
|
36
35
|
|
37
|
-
4.
|
36
|
+
4. Once you are ready to enable unicorn run `'mina unicorn:enable'` to enable the systemd service (persists across reboots).
|
37
|
+
|
38
|
+
5. To manually restart unicorn after a deploy use `'mina unicorn:restart'`.
|
38
39
|
|
39
40
|
## Customization
|
40
41
|
|
41
42
|
To change the unicorn systemd service template and/or the `unicorn_conf.rb`, run `'mina unicorn:generate'`.
|
42
43
|
|
44
|
+
By default `mina-unicorn_systemd` is running unicorn as a user service (`systemd --user`), but the unicorn service template also includes settings for running as a system service. To enable this, add `set :unicorn_system_or_user, 'system'` to the top of your `deploy.rb`.
|
45
|
+
|
43
46
|
## Contributing
|
44
47
|
|
45
48
|
1. Fork it ( http://github.com/coezbek/mina-unicorn_systemd/fork )
|
@@ -9,10 +9,11 @@ After=network.target
|
|
9
9
|
[Service]
|
10
10
|
Type=forking
|
11
11
|
WorkingDirectory=/home/<%= application %>/app/
|
12
|
-
|
12
|
+
<% if !is_unicorn_user_installation? %>
|
13
13
|
<%# Use the defined user and fall back to the application name -%>
|
14
|
-
User=<%= fetch :user, application %>
|
14
|
+
User=<%= fetch :user, application %>
|
15
15
|
|
16
|
+
<% end %>
|
16
17
|
#
|
17
18
|
# How to actually start Unicorn?
|
18
19
|
#
|
@@ -40,4 +41,8 @@ RestartSec=1
|
|
40
41
|
PIDFile=/home/<%= application %>/app/shared/unicorn.pid
|
41
42
|
|
42
43
|
[Install]
|
43
|
-
|
44
|
+
<% if is_unicorn_user_installation? %>
|
45
|
+
WantedBy=default.target
|
46
|
+
<% else %>
|
47
|
+
WantedBy=multi-user.target
|
48
|
+
<% end %>
|
data/lib/mina/unicorn.rb
CHANGED
@@ -6,7 +6,16 @@ require "mina/unicorn/version"
|
|
6
6
|
namespace :unicorn do
|
7
7
|
|
8
8
|
set :unicorn_service_name, -> { "unicorn-#{fetch(:application_name)}.service" }
|
9
|
-
|
9
|
+
|
10
|
+
set :unicorn_system_or_user, -> { "user" }
|
11
|
+
|
12
|
+
set :unicorn_systemd_config_path, -> {
|
13
|
+
if is_unicorn_user_installation?
|
14
|
+
"$HOME/.config/systemd/user/#{fetch :unicorn_service_name}"
|
15
|
+
else
|
16
|
+
"/etc/systemd/system/#{fetch :unicorn_service_name}"
|
17
|
+
end
|
18
|
+
}
|
10
19
|
|
11
20
|
set :nginx_socket_path, -> { "#{fetch(:shared_path)}/unicorn.sock" }
|
12
21
|
|
@@ -27,48 +36,70 @@ namespace :unicorn do
|
|
27
36
|
end
|
28
37
|
end
|
29
38
|
|
30
|
-
desc "Setup Unicorn systemd service on the remote server"
|
39
|
+
desc "Setup Unicorn systemd service on the remote server (but doesn't start it)"
|
31
40
|
task :setup do
|
32
41
|
|
33
|
-
|
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
|
-
|
42
|
+
# Fetch these before elevation!
|
43
|
+
username = fetch(:user)
|
38
44
|
target_path = fetch :unicorn_systemd_config_path
|
45
|
+
template = erb template_path
|
46
|
+
|
47
|
+
unicorn_elevate do
|
48
|
+
run :remote do
|
49
|
+
|
50
|
+
comment %(Check for systemd on remote server)
|
51
|
+
command %([[ `systemctl` =~ -\.mount ]] || { echo 'Systemd not found, but mina-unicorn_systemd needs it.'; exit 1; }) # From https://unix.stackexchange.com/a/164092
|
52
|
+
|
53
|
+
if is_unicorn_user_installation?
|
54
|
+
comment %(Check for libpam on remote server)
|
55
|
+
command %(DEBIAN_FRONTEND=noninteractive apt -yqq install libpam-systemd)
|
56
|
+
|
57
|
+
comment %(Enable linger for systemd --user)
|
58
|
+
command %(loginctl enable-linger #{username} || { echo 'Could not enable linger for user #{username} but mina-unicorn_systemd needs it.'; exit 1; })
|
59
|
+
end
|
60
|
+
|
61
|
+
comment %(Installing unicorn systemd config file to #{target_path})
|
62
|
+
command %(mkdir -p $(dirname #{target_path}))
|
63
|
+
command %(echo '#{template}' > #{target_path})
|
39
64
|
|
40
|
-
|
41
|
-
|
65
|
+
comment %(Reloading systemd configuration)
|
66
|
+
command %(systemctl#{" --user" if is_unicorn_user_installation?} daemon-reload || { echo 'If this command fails in user mode then you likely have disabled UsePAM in your /etc/ssh/sshd_config which is needed'; exit 1; }) # https://superuser.com/a/1561345/32638
|
42
67
|
|
43
|
-
|
44
|
-
|
68
|
+
end
|
69
|
+
end
|
45
70
|
|
46
71
|
end
|
47
72
|
|
48
73
|
desc "Get the status of the Unicorn systemd service on the remote server"
|
49
74
|
task :status do
|
50
|
-
command
|
75
|
+
command command_systemd_raw("status")
|
51
76
|
end
|
52
77
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
78
|
+
%w(start stop restart enable disable).each { |verb|
|
79
|
+
desc "#{verb.capitalize} the Unicorn systemd service on the remote server"
|
80
|
+
|
81
|
+
task verb.to_sym do
|
82
|
+
|
83
|
+
if is_unicorn_user_installation?
|
84
|
+
|
85
|
+
run :remote do
|
86
|
+
command_systemd verb
|
87
|
+
end
|
88
|
+
|
89
|
+
else
|
90
|
+
|
91
|
+
unicorn_elevate do
|
92
|
+
run :remote do
|
93
|
+
command_systemd verb
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
}
|
102
|
+
|
72
103
|
# Returns the path to the template to use. Depending on whether the internal template was customized.
|
73
104
|
def template_path
|
74
105
|
|
@@ -77,14 +108,41 @@ namespace :unicorn do
|
|
77
108
|
|
78
109
|
File.exist?(custom_path) ? custom_path : original_path
|
79
110
|
end
|
111
|
+
|
112
|
+
def is_unicorn_user_installation?
|
113
|
+
case fetch(:unicorn_system_or_user)
|
114
|
+
when "user"
|
115
|
+
true
|
116
|
+
when "system"
|
117
|
+
false
|
118
|
+
else
|
119
|
+
raise "Undefined unicorn_system_or_user value. Must be 'user' or 'system'."
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def command_systemd_raw verb
|
124
|
+
return %(systemctl#{" --user" if is_unicorn_user_installation?} #{verb} #{fetch :unicorn_service_name})
|
125
|
+
end
|
126
|
+
|
127
|
+
# Execute the systemd verb action and if it fails print the error information
|
128
|
+
def command_systemd verb
|
129
|
+
c = %((#{command_systemd_raw(verb)} && #{command_systemd_raw("status")}) || journalctl #{" --user" if is_unicorn_user_installation?} --no-pager _SYSTEMD_INVOCATION_ID=`systemctl #{" --user" if is_unicorn_user_installation?} show -p InvocationID --value #{fetch :unicorn_service_name}`)
|
130
|
+
|
131
|
+
comment c
|
132
|
+
command c
|
133
|
+
end
|
80
134
|
|
81
|
-
def
|
82
|
-
|
135
|
+
def unicorn_elevate
|
136
|
+
|
83
137
|
user = fetch(:user)
|
84
138
|
setup_user = fetch(:setup_user, user)
|
85
|
-
if setup_user != user
|
139
|
+
if setup_user && setup_user != user
|
86
140
|
comment %{Switching to setup_user (#{setup_user})}
|
87
141
|
set :user, setup_user
|
142
|
+
yield
|
143
|
+
set :user, user
|
144
|
+
else
|
145
|
+
yield
|
88
146
|
end
|
89
147
|
|
90
148
|
end
|
@@ -99,7 +157,8 @@ namespace :unicorn do
|
|
99
157
|
desc "Print current Unicorn systemd service config from remote"
|
100
158
|
task :print_remote do
|
101
159
|
unicorn_systemd_config_path = fetch :unicorn_systemd_config_path
|
102
|
-
|
160
|
+
comment %(Printing content of #{unicorn_systemd_config_path} from remote server)
|
161
|
+
command %(cat #{unicorn_systemd_config_path} || echo "Hello")
|
103
162
|
end
|
104
163
|
|
105
164
|
end
|
data/lib/mina/unicorn/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mina-unicorn_systemd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- coezbek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mina
|