Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use symbols (but allow strings) for foreman_init_system setting #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require 'capistrano/foreman'
# Default settings
set :foreman_use_sudo, false # Set to :rbenv for rbenv sudo, :rvm for rvmsudo or true for normal sudo
set :foreman_roles, :all
set :foreman_init_system, 'upstart'
set :foreman_init_system, :upstart
set :foreman_export_path, ->{ File.join(Dir.home, '.init') }
set :foreman_app, -> { fetch(:application) }
set :foreman_app_name_systemd, -> { "#{ fetch(:foreman_app) }.target" }
Expand Down
24 changes: 12 additions & 12 deletions lib/capistrano/tasks/foreman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
opts.map { |opt, value| "--#{opt}=\"#{value}\"" }.join(' ')
end

if fetch(:foreman_init_system) == 'systemd'
if fetch(:foreman_init_system).to_sym == :systemd
foreman_exec :systemctl, :'daemon-reload'
end
end
Expand All @@ -32,8 +32,8 @@
desc 'Start the application services'
task :start do
on roles fetch(:foreman_roles) do
case fetch(:foreman_init_system)
when 'systemd'
case fetch(:foreman_init_system).to_sym
when :systemd
foreman_exec :systemctl, :enable, fetch(:foreman_app_name_systemd)
foreman_exec :systemctl, :start, fetch(:foreman_app_name_systemd)
else
Expand All @@ -45,8 +45,8 @@
desc 'Stop the application services'
task :stop do
on roles fetch(:foreman_roles) do
case fetch(:foreman_init_system)
when 'systemd'
case fetch(:foreman_init_system).to_sym
when :systemd
foreman_exec :systemctl, :stop, fetch(:foreman_app_name_systemd)
foreman_exec :systemctl, :disable, fetch(:foreman_app_name_systemd)
else
Expand All @@ -58,8 +58,8 @@
desc 'Restart the application services'
task :restart do
on roles fetch(:foreman_roles) do
case fetch(:foreman_init_system)
when 'systemd'
case fetch(:foreman_init_system).to_sym
when :systemd
foreman_exec :systemctl, :restart, fetch(:foreman_app_name_systemd)
else
foreman_exec :restart, fetch(:foreman_app)
Expand All @@ -69,15 +69,15 @@

def foreman_exec(*args)
sudo_type = fetch(:foreman_use_sudo)
case sudo_type.to_s
when 'rbenv'
case sudo_type.to_sym
when :rbenv
# this is required because 'rbenv sudo'
# is not recognized by bundle_bins
args.unshift(:bundle, :exec) if args[0].to_s == "foreman"
execute(:rbenv, :sudo, *args)
when 'rvm'
when :rvm
execute(:rvmsudo, *args)
when 'chruby'
when :chruby
execute(:sudo, 'chruby-exec', fetch(:chruby_ruby), '--', *args)
else
sudo_type ? sudo(*args) : execute(*args)
Expand All @@ -89,7 +89,7 @@ def foreman_exec(*args)
task :defaults do
set :bundle_bins, fetch(:bundle_bins, []).push(:foreman)
set :foreman_use_sudo, false
set :foreman_init_system, 'upstart'
set :foreman_init_system, :upstart
set :foreman_export_path, '/etc/init/sites'
set :foreman_roles, :all
set :foreman_app, -> { fetch(:application) }
Expand Down