From e4e9d6000651a843421a1d9c553d20bbb8e251b7 Mon Sep 17 00:00:00 2001 From: "Eric D. Reichert" Date: Sun, 11 Jan 2015 16:54:38 -0500 Subject: [PATCH 1/3] Created the detect_os script. Made the redhat flavor returned by the detect_os script more accurate for CentOS. --- lib/scripts/detect_os.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lib/scripts/detect_os.sh diff --git a/lib/scripts/detect_os.sh b/lib/scripts/detect_os.sh new file mode 100644 index 0000000..fce8619 --- /dev/null +++ b/lib/scripts/detect_os.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +#Refer to https://github.com/puppetlabs/facter/blob/master/lib/facter/operatingsystem/linux.rb if additional +#operating systems need to be supported or more specific information about the operating system is required. + +if [[ $(lsb_release -is 2>/dev/null) == "Ubuntu" ]]; then + echo "Ubuntu" + exit 0 +else + if [[ -e "/etc/redhat-release" ]]; then + echo "$(cat /etc/redhat-release | cut -d " " -f1)" + exit 0 + fi +fi + +exit 1 \ No newline at end of file From 465ebac55f50ed83a519eb3460bb82879fb07ffb Mon Sep 17 00:00:00 2001 From: "Eric D. Reichert" Date: Sun, 11 Jan 2015 21:12:34 -0500 Subject: [PATCH 2/3] Created the upload_os_detection_script task. Fixed the path to the detect_os script in the upload task. Corrected the roles for which the upload_os_detection_script task will be run. Made the upload_os_detection_script task a dependency of the setup_initializer. --- lib/capistrano/tasks/unicorn.rake | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/capistrano/tasks/unicorn.rake b/lib/capistrano/tasks/unicorn.rake index dd68c23..37c7489 100644 --- a/lib/capistrano/tasks/unicorn.rake +++ b/lib/capistrano/tasks/unicorn.rake @@ -34,7 +34,7 @@ namespace :unicorn do end desc 'Setup Unicorn initializer' - task :setup_initializer do + task :setup_initializer => :upload_os_detection_script do on roles :app do sudo_upload! template('unicorn_init.erb'), unicorn_initd_file execute :chmod, '+x', unicorn_initd_file @@ -68,6 +68,17 @@ namespace :unicorn do end end + desc 'Upload OS detection script.' + task :upload_os_detection_script do + on roles :app do + script_name = 'detect_os.sh' + remote_script_path = "#{fetch(:tmp_dir)}/#{fetch(:application)}/#{script_name}" + execute :mkdir, '-p', "#{fetch(:tmp_dir)}/#{fetch(:application)}/" + upload! File.join(File.dirname(__FILE__), "../../scripts/#{script_name}"), remote_script_path + execute :chmod, '+x', remote_script_path + end + end + before :setup_initializer, :defaults before :setup_logrotate, :defaults From bbcb31506a2988d9017e662e6b14e22aee6ddf34 Mon Sep 17 00:00:00 2001 From: "Eric D. Reichert" Date: Sun, 11 Jan 2015 22:01:50 -0500 Subject: [PATCH 3/3] Rewrote the setup_initializer to invoke the correct service manager based on whether the deployment is targeting Ubuntu or CentOS. Corrected a path that was broken during refactoring. --- lib/capistrano/tasks/unicorn.rake | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/capistrano/tasks/unicorn.rake b/lib/capistrano/tasks/unicorn.rake index 37c7489..1ced9fa 100644 --- a/lib/capistrano/tasks/unicorn.rake +++ b/lib/capistrano/tasks/unicorn.rake @@ -22,6 +22,8 @@ namespace :load do set :unicorn_logrotate_enabled, false # by default, don't use logrotate to rotate unicorn logs set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids') + set :detect_os_script_name, 'detect_os.sh' + set :detect_os_remote_script_path, "#{fetch(:tmp_dir)}/#{fetch(:application)}/detect_os.sh" end end @@ -38,7 +40,12 @@ namespace :unicorn do on roles :app do sudo_upload! template('unicorn_init.erb'), unicorn_initd_file execute :chmod, '+x', unicorn_initd_file - sudo 'update-rc.d', '-f', fetch(:unicorn_service), 'defaults' + case capture(fetch(:detect_os_remote_script_path)).downcase + when 'centos' + sudo 'chkconfig', fetch(:unicorn_service), 'on' + when 'ubuntu' + sudo 'update-rc.d', '-f', fetch(:unicorn_service), 'defaults' + end end end @@ -71,11 +78,9 @@ namespace :unicorn do desc 'Upload OS detection script.' task :upload_os_detection_script do on roles :app do - script_name = 'detect_os.sh' - remote_script_path = "#{fetch(:tmp_dir)}/#{fetch(:application)}/#{script_name}" execute :mkdir, '-p', "#{fetch(:tmp_dir)}/#{fetch(:application)}/" - upload! File.join(File.dirname(__FILE__), "../../scripts/#{script_name}"), remote_script_path - execute :chmod, '+x', remote_script_path + upload! File.join(File.dirname(__FILE__), "../../scripts/#{fetch(:detect_os_script_name)}"), fetch(:detect_os_remote_script_path) + execute :chmod, '+x', fetch(:detect_os_remote_script_path) end end