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

Added CentOS 6.x support. #45

Open
wants to merge 3 commits 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
20 changes: 18 additions & 2 deletions lib/capistrano/tasks/unicorn.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -34,11 +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
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

Expand Down Expand Up @@ -68,6 +75,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

Expand Down
16 changes: 16 additions & 0 deletions lib/scripts/detect_os.sh
Original file line number Diff line number Diff line change
@@ -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