Skip to content

Commit

Permalink
Added CentOS 6.x support. capistrano-plugins#45
Browse files Browse the repository at this point in the history
  • Loading branch information
riseshia committed Jun 17, 2015
1 parent c6069ed commit fc92469
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
19 changes: 18 additions & 1 deletion 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,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
Expand Down Expand Up @@ -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

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

0 comments on commit fc92469

Please sign in to comment.