default.rb 3.1 KB

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