default.rb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. include_recipe 'apt'
  2. include_recipe 'build-essential'
  3. user "huginn" do
  4. system true
  5. home "/home/huginn"
  6. password "$6$ZwO6b.6tij$SMa8UIwtESGDxB37NwHsct.gJfXWmmflNbH.oypwJ9y0KkzMkCdw7D14iK7GX9C4CWSEcpGOFUow7p01rQFu5."
  7. supports :manage_home => true
  8. shell "/bin/bash"
  9. gid "sudo"
  10. end
  11. group "huginn" do
  12. members ["huginn"]
  13. end
  14. %w("ruby1.9.1" "ruby1.9.1-dev" "libxslt-dev" "libxml2-dev" "curl" "libshadow-ruby1.8" "libmysqlclient-dev" "libffi-dev" "libssl-dev" "rubygems").each do |pkg|
  15. package("#{pkg}")
  16. end
  17. bash "Setting default ruby version to 1.9" do
  18. code <<-EOH
  19. update-alternatives --set ruby /usr/bin/ruby1.9.1
  20. update-alternatives --set gem /usr/bin/gem1.9.1
  21. EOH
  22. end
  23. gem_package("rake")
  24. gem_package("bundle")
  25. service "nginx" do
  26. supports :restart => true, :start => true, :stop => true, :reload => true
  27. action :nothing
  28. end
  29. bash "Setting huginn user with NOPASSWD option" do
  30. cwd "/etc/sudoers.d"
  31. code <<-EOH
  32. touch huginn && chmod 0440 huginn
  33. echo "huginn ALL=(ALL) NOPASSWD:ALL" >> huginn
  34. EOH
  35. end
  36. deploy "/home/huginn" do
  37. repo "https://github.com/cantino/huginn.git"
  38. branch "master"
  39. user "huginn"
  40. group "huginn"
  41. environment "RAILS_ENV" => "production"
  42. keep_releases 5
  43. create_dirs_before_symlink []
  44. symlinks "log" => "log"
  45. symlink_before_migrate({})
  46. rollback_on_error true
  47. notifies :enable, "service[nginx]"
  48. notifies :start, "service[nginx]"
  49. before_symlink do
  50. %w(config log tmp).each do |dir|
  51. directory "/home/huginn/shared/#{dir}" do
  52. owner "huginn"
  53. group "huginn"
  54. recursive true
  55. end
  56. end
  57. directory("/home/huginn/shared/tmp/pids")
  58. directory("/home/huginn/shared/tmp/sockets")
  59. %w(Procfile unicorn.rb nginx.conf).each do |file|
  60. cookbook_file "/home/huginn/shared/config/#{file}" do
  61. owner "huginn"
  62. action :create_if_missing
  63. end
  64. end
  65. cookbook_file "home/huginn/shared/config/.env" do
  66. source "env.example"
  67. mode "666"
  68. owner "huginn"
  69. action :create_if_missing
  70. end
  71. end
  72. before_restart do
  73. bash "huginn dependencies" do
  74. cwd "/home/huginn/current"
  75. user "huginn"
  76. group "huginn"
  77. code <<-EOH
  78. export LANG="en_US.UTF-8"
  79. export LC_ALL="en_US.UTF-8"
  80. ln -nfs /home/huginn/shared/config/Procfile ./Procfile
  81. ln -nfs /home/huginn/shared/config/.env ./.env
  82. ln -nfs /home/huginn/shared/config/unicorn.rb ./config/unicorn.rb
  83. sudo cp /home/huginn/shared/config/nginx.conf /etc/nginx/
  84. echo 'gem "unicorn", :group => :production' >> Gemfile
  85. sudo bundle install --without=development --without=test
  86. sed -i s/REPLACE_ME_NOW\!/$(sudo bundle exec rake secret)/ /home/huginn/shared/config/.env
  87. sudo RAILS_ENV=production bundle exec rake db:create
  88. sudo RAILS_ENV=production bundle exec rake db:migrate
  89. sudo RAILS_ENV=production bundle exec rake db:seed
  90. sudo RAILS_ENV=production bundle exec rake assets:precompile
  91. sudo foreman export upstart /etc/init -a huginn -u huginn -l log
  92. sudo start huginn
  93. EOH
  94. end
  95. end
  96. end