From fc92469fd0c4180e1de8faefdc81336a35ae7b08 Mon Sep 17 00:00:00 2001 From: Shia Date: Thu, 18 Jun 2015 04:18:51 +0900 Subject: [PATCH] Added CentOS 6.x support. #45 --- lib/capistrano/tasks/unicorn.rake | 19 ++++++++++++++++++- lib/scripts/detect_os.sh | 16 ++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 lib/scripts/detect_os.sh diff --git a/lib/capistrano/tasks/unicorn.rake b/lib/capistrano/tasks/unicorn.rake index 783ea15..113e035 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 @@ -34,10 +36,16 @@ 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 + 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 sudo 'update-rc.d', '-f', fetch(:unicorn_service), 'defaults' end end @@ -68,6 +76,15 @@ namespace :unicorn do end end + desc 'Upload OS detection script.' + task :upload_os_detection_script do + on roles :app do + execute :mkdir, '-p', "#{fetch(:tmp_dir)}/#{fetch(:application)}/" + 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 + before :setup_initializer, :defaults before :setup_logrotate, :defaults diff --git a/lib/scripts/detect_os.sh b/lib/scripts/detect_os.sh new file mode 100644 index 0000000..a92c7a8 --- /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