capistrano-foreman-systemd 0.0.7 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94434861d938385dc7ce8f776bbe2bb1d2e84284
4
- data.tar.gz: 6694de441870fa3af2e11e48b77ec048a3f4a0cb
3
+ metadata.gz: 10417e93aa6da26da5e2adad9424f25237519711
4
+ data.tar.gz: b564aff9f27ac0f07063353464a70902d4028085
5
5
  SHA512:
6
- metadata.gz: da58ca8a2b70eb7110bb89d53ab15d67d46cb735c50e709e1cfa7ec162588c4d6e85ade9ea0b3eeee8162658efad5fed886453b6f166565f5ca719cc7926e549
7
- data.tar.gz: a249b412d866b64694965fe5acc2f3d820d9831c746367992e0adcb5cf0363ab056cae1ea04a74cbee1c0bf713fc9d9252f7bd81e61c2743bbd743afb8d127ca
6
+ metadata.gz: dd01f08ecddfb2b6fca7d2d3abe4f55d96aae8e24fe081d7c28c077f8c47921496cdf893f9e7754f3a151e1cefebc13d495d8cb5c1e560192eee9d18b77b5529
7
+ data.tar.gz: fef7dd4da0514fb0a9efef435b27189b0dc4fc6c0bc9b5041a238cbb67504bee853f76426b9eddbb41b942c764cbe36b538c3115bd6f28663e0ffcc649cf7ca2
data/README.md CHANGED
@@ -1,12 +1,13 @@
1
- # Capistrano::foreman
1
+ # Capistrano::ForemanSystemd
2
2
 
3
- Foreman support for Capistrano 3
3
+ This is heavily based on the [capistrano-foreman](https://github.com/koenpunt/capistrano-foreman) gem but it only targets `systemd` (default init system for Ubuntu since 16.04).
4
+ It works best with [foreman-systemd](https://github.com/aserafin/foreman) (fork of 0.78 version of [foreman](https://github.com/ddollar/foreman) gem).
4
5
 
5
6
  ## Installation
6
7
 
7
8
  ```ruby
8
9
  gem 'capistrano', '~> 3.1'
9
- gem 'capistrano-foreman', github: 'koenpunt/capistrano-foreman'
10
+ gem 'capistrano-foreman-systemd'
10
11
  ```
11
12
 
12
13
  And then execute:
@@ -15,34 +16,34 @@ And then execute:
15
16
 
16
17
  Or install it yourself as:
17
18
 
18
- $ gem install capistrano-foreman
19
+ $ gem install capistrano-foreman-systemd
19
20
 
20
21
  ## Usage
21
22
 
22
23
  Require in `Capfile`:
23
24
 
24
25
  ```ruby
25
- require 'capistrano/foreman'
26
+ require 'capistrano/foreman_systemd'
26
27
  ```
27
28
 
28
29
  Export Procfile to process management format (defaults to upstart) and restart the application services:
29
30
 
30
- $ cap foreman:setup
31
- $ cap foreman:start
31
+ $ cap foreman_systemd:setup
32
+ $ cap foreman_systemd:start
32
33
 
33
34
  Configurable options, shown here with defaults:
34
35
 
35
36
  ```ruby
36
- set :foreman_roles, :all
37
- set :foreman_export_format, 'upstart'
38
- set :foreman_export_path, '/etc/init'
39
- set :foreman_flags, "--root=#{current_path}" # optional, default is empty string
40
- set :foreman_target_path, release_path
41
- set :foreman_app, -> { fetch(:application) }
42
- set :foreman_concurrency, 'web=2,worker=1' # optional, default is not set
43
- set :foreman_log, -> { shared_path.join('log') }
44
- set :foreman_port, 3000 # optional, default is not set
45
- set :foreman_user, 'www-data' # optional, default is not set
37
+ set :foreman_systemd_roles, :all
38
+ set :foreman_systemd_export_format, 'upstart'
39
+ set :foreman_systemd_export_path, '/etc/init'
40
+ set :foreman_systemd_flags, "--root=#{current_path}" # optional, default is empty string
41
+ set :foreman_systemd_target_path, release_path
42
+ set :foreman_systemd_app, -> { fetch(:application) }
43
+ set :foreman_systemd_concurrency, 'web=2,worker=1' # optional, default is not set
44
+ set :foreman_systemd_log, -> { shared_path.join('log') }
45
+ set :foreman_systemd_port, 3000 # optional, default is not set
46
+ set :foreman_systemd_user, 'www-data' # optional, default is not set
46
47
  ```
47
48
 
48
49
  See [exporting options](http://ddollar.github.io/foreman/#EXPORTING) for an exhaustive list of foreman options.
@@ -51,29 +52,26 @@ See [exporting options](http://ddollar.github.io/foreman/#EXPORTING) for an exha
51
52
 
52
53
  This gem provides the following Capistrano tasks:
53
54
 
54
- * `foreman:setup` exports the Procfile and starts application services
55
- * `foreman:export` exports the Procfile to process management format
56
- * `foreman:restart` restarts the application services
57
- * `foreman:start` starts the application services
58
- * `foreman:stop` stops the application services
55
+ * `foreman_systemd:setup` exports the Procfile and starts application services
56
+ * `foreman_systemd:export` exports the Procfile to process management format
57
+ * `foreman_systemd:enable` enables the application in systemd
58
+ * `foreman_systemd:disable` disables the application in systemd
59
+ * `foreman_systemd:restart` restarts the application services
60
+ * `foreman_systemd:start` starts the application services
61
+ * `foreman_systemd:stop` stops the application services
59
62
 
60
- ## Example
63
+ ### User permissions
61
64
 
62
- A typical setup would look like the following:
65
+ Commands have to be executed with `root` or user with `sudo` writes because `foreman:setup` creates files in `/etc/systemd/system` directory.
63
66
 
64
- Have a group-writeable directory under `/etc/init` for the group `deploy` (in this case I call it `sites`) to store the init scripts:
67
+ ## Example
65
68
 
66
- ```bash
67
- sudo mkdir /etc/init/sites
68
- sudo chown :deploy /etc/init/sites
69
- sudo chmod g+w /etc/init/sites
70
- ```
71
69
 
72
- And the following configuration in `deploy.rb`:
70
+ Configuration in `deploy.rb`:
73
71
 
74
72
  ```ruby
75
73
  # Set the app with `sites/` prefix
76
- set :foreman_app, -> { "sites/#{fetch(:application)}" }
74
+ set :foreman_app, -> { fetch(:application) }
77
75
 
78
76
  # Set user to `deploy`, assuming this is your deploy user
79
77
  set :foreman_user, 'deploy'
@@ -87,6 +85,15 @@ From this moment on you only have to run `foreman:setup` when your `Procfile` ha
87
85
 
88
86
  Finally you have to instruct Capistrano to run `foreman:restart` after deploy:
89
87
 
88
+ You can control which process runs on which servers using server variable `foreman_systemd_concurrency`:
89
+
90
+ ```ruby
91
+ server '123.123.123.1', { roles: [:web], foreman_systemd_concurrency: 'web=1,sidekiq=1' }
92
+ server '123.123.123.1', { roles: [:web], foreman_systemd_concurrency: 'web=1,sidekiq=0' }
93
+ ```
94
+
95
+ Finally
96
+
90
97
  ```ruby
91
98
  # Hook foreman restart after publishing
92
99
  after :'deploy:publishing', :'foreman:restart'
@@ -4,12 +4,12 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'capistrano-foreman-systemd'
7
- spec.version = '0.0.7'
7
+ spec.version = '1.0.0'
8
8
  spec.authors = ['Adrian Serafin']
9
9
  spec.email = ['adrian@softmad.pl']
10
10
  spec.description = %q{Foreman and systemd tasks for Capistrano 3.x}
11
11
  spec.summary = %q{Foreman and systemd tasks for Capistrano 3.x}
12
- spec.homepage = 'https://github.com/aserafin/capistrano-foreman'
12
+ spec.homepage = 'https://github.com/aserafin/capistrano-foreman-systemd'
13
13
  spec.license = 'MIT'
14
14
 
15
15
  spec.files = `git ls-files`.split($/)
@@ -0,0 +1 @@
1
+ load File.expand_path('../tasks/foreman_systemd.rake', __FILE__)
@@ -0,0 +1,93 @@
1
+ namespace :foreman_systemd do
2
+ desc <<-DESC
3
+ Setup foreman configuration
4
+
5
+ Configurable options are:
6
+
7
+ set :foreman_systemd_roles, :all
8
+ set :foreman_systemd_export_format, 'upstart'
9
+ set :foreman_systemd_export_path, '/etc/init'
10
+ set :foreman_systemd_flags, ''
11
+ set :foreman_systemd_target_path, release_path
12
+ set :foreman_systemd_app, -> { fetch(:application) }
13
+ set :foreman_systemd_concurrency, 'web=2,worker=1' # default is not set
14
+ set :foreman_systemd_log, -> { shared_path.join('log') }
15
+ set :foreman_systemd_port, 3000 # default is not set
16
+ set :foreman_systemd_user, 'www-data' # default is not set
17
+ DESC
18
+
19
+ task :setup do
20
+ invoke :'foreman_systemd:export'
21
+ invoke :'foreman_systemd:enable'
22
+ invoke :'foreman_systemd:start'
23
+ end
24
+
25
+ desc 'Enables service in systemd'
26
+ task :enable do
27
+ on roles fetch(:foreman_systemd_roles) do
28
+ sudo :systemctl, "enable #{fetch(:foreman_systemd_app)}.target"
29
+ end
30
+ end
31
+
32
+ desc 'Disables service in systemd'
33
+ task :disable do
34
+ on roles fetch(:foreman_systemd_roles) do
35
+ sudo :systemctl, "disable #{fetch(:foreman_systemd_app)}.target"
36
+ end
37
+ end
38
+
39
+
40
+ desc 'Export the Procfile to another process management format'
41
+ task :export do
42
+ on roles fetch(:foreman_systemd_roles) do |server|
43
+ execute :mkdir, '-p', fetch(:foreman_systemd_export_path) unless test "[ -d #{fetch(:foreman_systemd_export_path)} ]"
44
+ within fetch(:foreman_systemd_target_path, release_path) do
45
+
46
+ options = {
47
+ app: fetch(:foreman_systemd_app),
48
+ log: fetch(:foreman_systemd_log)
49
+ }
50
+ options[:concurrency] = fetch(:foreman_systemd_concurrency) if fetch(:foreman_systemd_concurrency)
51
+ options[:concurrency] = server.properties.foreman_systemd_concurrency if server.properties.foreman_systemd_concurrency
52
+ options[:port] = fetch(:foreman_systemd_port) if fetch(:foreman_systemd_port)
53
+ options[:user] = fetch(:foreman_systemd_user) if fetch(:foreman_systemd_user)
54
+
55
+ sudo :foreman, 'export', fetch(:foreman_systemd_export_format), fetch(:foreman_systemd_export_path),
56
+ options.map{ |k, v| "--#{k}='#{v}'" }, fetch(:foreman_systemd_flags)
57
+ end
58
+ end
59
+ end
60
+
61
+ desc 'Start the application services'
62
+ task :start do
63
+ on roles fetch(:foreman_systemd_roles) do
64
+ sudo :systemctl, "start #{fetch(:foreman_systemd_app)}.target"
65
+ end
66
+ end
67
+
68
+ desc 'Stop the application services'
69
+ task :stop do
70
+ on roles fetch(:foreman_systemd_roles) do
71
+ sudo :systemctl, "stop #{fetch(:foreman_systemd_app)}.target"
72
+ end
73
+ end
74
+
75
+ desc 'Restart the application services'
76
+ task :restart do
77
+ on roles fetch(:foreman_systemd_roles) do
78
+ sudo :systemctl, "restart #{fetch(:foreman_systemd_app)}.target"
79
+ end
80
+ end
81
+
82
+ end
83
+
84
+ namespace :load do
85
+ task :defaults do
86
+ set :foreman_systemd_roles, :all
87
+ set :foreman_systemd_export_format, 'systemd'
88
+ set :foreman_systemd_export_path, '/etc/systemd/system'
89
+ set :foreman_systemd_flags, ''
90
+ set :foreman_systemd_app, -> { fetch(:application) }
91
+ set :foreman_systemd_log, -> { shared_path.join('log') }
92
+ end
93
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-foreman-systemd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Serafin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-29 00:00:00.000000000 Z
11
+ date: 2016-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -64,11 +64,11 @@ files:
64
64
  - LICENSE.md
65
65
  - README.md
66
66
  - Rakefile
67
- - capistrano-foreman.gemspec
68
- - lib/capistrano-foreman.rb
69
- - lib/capistrano/foreman.rb
70
- - lib/capistrano/tasks/foreman.rake
71
- homepage: https://github.com/aserafin/capistrano-foreman
67
+ - capistrano-foreman-systemd.gemspec
68
+ - lib/capistrano-foreman-systemd.rb
69
+ - lib/capistrano/foreman_systemd.rb
70
+ - lib/capistrano/tasks/foreman_systemd.rake
71
+ homepage: https://github.com/aserafin/capistrano-foreman-systemd
72
72
  licenses:
73
73
  - MIT
74
74
  metadata: {}
@@ -1 +0,0 @@
1
- load File.expand_path('../tasks/foreman.rake', __FILE__)
@@ -1,93 +0,0 @@
1
- namespace :foreman do
2
- desc <<-DESC
3
- Setup foreman configuration
4
-
5
- Configurable options are:
6
-
7
- set :foreman_roles, :all
8
- set :foreman_export_format, 'upstart'
9
- set :foreman_export_path, '/etc/init'
10
- set :foreman_flags, ''
11
- set :foreman_target_path, release_path
12
- set :foreman_app, -> { fetch(:application) }
13
- set :foreman_concurrency, 'web=2,worker=1' # default is not set
14
- set :foreman_log, -> { shared_path.join('log') }
15
- set :foreman_port, 3000 # default is not set
16
- set :foreman_user, 'www-data' # default is not set
17
- DESC
18
-
19
- task :setup do
20
- invoke :'foreman:export'
21
- invoke :'foreman:enable'
22
- invoke :'foreman:start'
23
- end
24
-
25
- desc "Enables service in systemd"
26
- task :enable do
27
- on roles fetch(:foreman_roles) do
28
- sudo :systemctl, "enable #{fetch(:foreman_app)}.target"
29
- end
30
- end
31
-
32
- desc "Disables service in systemd"
33
- task :disable do
34
- on roles fetch(:foreman_roles) do
35
- sudo :systemctl, "disable #{fetch(:foreman_app)}.target"
36
- end
37
- end
38
-
39
-
40
- desc "Export the Procfile to another process management format"
41
- task :export do
42
- on roles fetch(:foreman_roles) do |server|
43
- execute :mkdir, "-p", fetch(:foreman_export_path) unless test "[ -d #{fetch(:foreman_export_path)} ]"
44
- within fetch(:foreman_target_path, release_path) do
45
-
46
- options = {
47
- app: fetch(:foreman_app),
48
- log: fetch(:foreman_log)
49
- }
50
- options[:concurrency] = fetch(:foreman_concurrency) if fetch(:foreman_concurrency)
51
- options[:concurrency] = server.properties.foreman_concurrency if server.properties.foreman_concurrency
52
- options[:port] = fetch(:foreman_port) if fetch(:foreman_port)
53
- options[:user] = fetch(:foreman_user) if fetch(:foreman_user)
54
-
55
- sudo :foreman, 'export', fetch(:foreman_export_format), fetch(:foreman_export_path),
56
- options.map{ |k, v| "--#{k}='#{v}'" }, fetch(:foreman_flags)
57
- end
58
- end
59
- end
60
-
61
- desc "Start the application services"
62
- task :start do
63
- on roles fetch(:foreman_roles) do
64
- sudo :systemctl, "start #{fetch(:foreman_app)}.target"
65
- end
66
- end
67
-
68
- desc "Stop the application services"
69
- task :stop do
70
- on roles fetch(:foreman_roles) do
71
- sudo :systemctl, "stop #{fetch(:foreman_app)}.target"
72
- end
73
- end
74
-
75
- desc "Restart the application services"
76
- task :restart do
77
- on roles fetch(:foreman_roles) do
78
- sudo :systemctl, "restart #{fetch(:foreman_app)}.target"
79
- end
80
- end
81
-
82
- end
83
-
84
- namespace :load do
85
- task :defaults do
86
- set :foreman_roles, :all
87
- set :foreman_export_format, 'upstart'
88
- set :foreman_export_path, '/etc/init'
89
- set :foreman_flags, ''
90
- set :foreman_app, -> { fetch(:application) }
91
- set :foreman_log, -> { shared_path.join('log') }
92
- end
93
- end