dreamcat4-moonshadow 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. data/LICENSE +165 -0
  2. data/app_generators/moonshine/moonshine_generator.rb +154 -0
  3. data/app_generators/moonshine/templates/Capfile +3 -0
  4. data/app_generators/moonshine/templates/rails/deploy.rb +3 -0
  5. data/app_generators/moonshine/templates/rails/gems.yml +1 -0
  6. data/app_generators/moonshine/templates/rails/manifest.rb +55 -0
  7. data/app_generators/moonshine/templates/rails/moonshine.rake +83 -0
  8. data/app_generators/moonshine/templates/rails/moonshine.yml +43 -0
  9. data/app_generators/moonshine/templates/readme.templates +5 -0
  10. data/app_generators/moonshine_plugin/USAGE +8 -0
  11. data/app_generators/moonshine_plugin/moonshine_plugin_generator.rb +39 -0
  12. data/app_generators/moonshine_plugin/templates/README.rdoc +14 -0
  13. data/app_generators/moonshine_plugin/templates/init.rb +3 -0
  14. data/app_generators/moonshine_plugin/templates/plugin.rb +19 -0
  15. data/app_generators/moonshine_plugin/templates/spec.rb +24 -0
  16. data/app_generators/moonshine_plugin/templates/spec_helper.rb +8 -0
  17. data/bin/moonshine +17 -0
  18. data/bin/moonshine_plugin +17 -0
  19. data/lib/moonshine.rb +7 -0
  20. data/lib/moonshine/bootstrap/bootstrap.mri.sh +21 -0
  21. data/lib/moonshine/bootstrap/bootstrap.ree.sh +34 -0
  22. data/lib/moonshine/capistrano.rb +242 -0
  23. data/lib/moonshine/manifest.rb +151 -0
  24. data/lib/moonshine/manifest/rails.rb +54 -0
  25. data/lib/moonshine/manifest/rails/apache.rb +99 -0
  26. data/lib/moonshine/manifest/rails/apt_gems.yml +32 -0
  27. data/lib/moonshine/manifest/rails/mysql.rb +79 -0
  28. data/lib/moonshine/manifest/rails/os.rb +115 -0
  29. data/lib/moonshine/manifest/rails/passenger.rb +93 -0
  30. data/lib/moonshine/manifest/rails/postgresql.rb +83 -0
  31. data/lib/moonshine/manifest/rails/rails.rb +237 -0
  32. data/lib/moonshine/manifest/rails/sqlite3.rb +8 -0
  33. data/lib/moonshine/manifest/rails/templates/innodb.cnf.erb +6 -0
  34. data/lib/moonshine/manifest/rails/templates/logrotate.conf.erb +15 -0
  35. data/lib/moonshine/manifest/rails/templates/moonshine.cnf.erb +63 -0
  36. data/lib/moonshine/manifest/rails/templates/passenger.conf.erb +106 -0
  37. data/lib/moonshine/manifest/rails/templates/passenger.vhost.erb +273 -0
  38. data/lib/moonshine/manifest/rails/templates/pg_hba.conf.erb +83 -0
  39. data/lib/moonshine/manifest/rails/templates/postgresql.conf.erb +493 -0
  40. data/lib/moonshine/manifest/rails/templates/unattended_upgrades.erb +18 -0
  41. data/lib/moonshine_setup_manifest.rb +39 -0
  42. metadata +135 -0
@@ -0,0 +1,151 @@
1
+ # This is the base Moonshine Manifest class, which provides a simple system
2
+ # for loading moonshine recpies from plugins, a template helper, and parses
3
+ # several configuration files:
4
+ #
5
+ # config/moonshine.yml
6
+ #
7
+ # The contents of <tt>config/moonshine.yml</tt> are expected to serialize into
8
+ # a hash, and are loaded into the manifest's Configatron::Store.
9
+ #
10
+ # config/database.yml
11
+ #
12
+ # The contents of your database config are parsed and are available at
13
+ # <tt>configuration[:database]</tt>.
14
+ #
15
+ # If you'd like to create another 'default rails stack' using other tools that
16
+ # what Moonshine::Manifest::Rails uses, subclass this and go nuts.
17
+ class Moonshine::Manifest < ShadowPuppet::Manifest
18
+ # Load a Moonshine Plugin
19
+ #
20
+ # class MyManifest < Moonshine::Manifest
21
+ #
22
+ # # Evals vendor/plugins/moonshine_my_app/moonshine/init.rb
23
+ # plugin :moonshine_my_app
24
+ #
25
+ # # Evals lib/my_recipe.rb
26
+ # plugin 'lib/my_recipe.rb'
27
+ #
28
+ # ...
29
+ # end
30
+ def self.plugin(name = nil)
31
+ if name.is_a?(Symbol)
32
+ path = File.join(rails_root, 'vendor', 'plugins', 'moonshine_' + name.to_s, 'moonshine', 'init.rb')
33
+ else
34
+ path = name
35
+ end
36
+ Kernel.eval(File.read(path), binding, path)
37
+ true
38
+ end
39
+
40
+ # The working directory of the Rails application this manifests describes.
41
+ def self.rails_root
42
+ @rails_root ||= File.expand_path(ENV["RAILS_ROOT"] || Dir.getwd)
43
+ end
44
+
45
+ def rails_root
46
+ self.class.rails_root
47
+ end
48
+
49
+ # The current Rails environment
50
+ def self.rails_env
51
+ ENV["RAILS_ENV"] || 'production'
52
+ end
53
+
54
+ # The current Rails environment
55
+ def rails_env
56
+ self.class.rails_env
57
+ end
58
+
59
+ # The current environment's database configuration
60
+ def database_environment
61
+ configuration[:database][rails_env.to_sym]
62
+ end
63
+
64
+ # The current deployment target. Best when used with capistrano-ext's multistage settings.
65
+ def self.deploy_stage
66
+ ENV['DEPLOY_STAGE'] || 'undefined'
67
+ end
68
+
69
+ # The current deployment target. Best when used with capistrano-ext's multistage settings.
70
+ def deploy_stage
71
+ self.class.deploy_stage
72
+ end
73
+
74
+ # Only run tasks on the specified deploy_stage.
75
+ #
76
+ # You can call it with the exact stage you want to run on:
77
+ #
78
+ # on_stage(:my_stage) do
79
+ # puts "I'm on my_stage"
80
+ # end
81
+ #
82
+ # Or you can pass an array of stages to run on:
83
+ #
84
+ # on_stage(:my_stage, :my_other_stage) do
85
+ # puts "I'm on one of my stages"
86
+ # end
87
+ #
88
+ # Or you can run a task unless it is on a stage:
89
+ #
90
+ # on_stage(:unless => :my_stage) do
91
+ # puts "I'm not on my_stage"
92
+ # end
93
+ #
94
+ # Or you can run a task unless it is on one of several stages:
95
+ #
96
+ # on_stage(:unless => [:my_stage, :my_other_stage]) do
97
+ # puts "I'm not on my stages"
98
+ # end
99
+ def on_stage(*args)
100
+ options = args.extract_options!
101
+ if_opt = options[:if]
102
+ unless_opt = options[:unless]
103
+
104
+ unless if_opt || unless_opt
105
+ if_opt = args
106
+ end
107
+
108
+ if if_opt && if_opt.is_a?(Array) && if_opt.map {|x| x.to_s}.include?(deploy_stage)
109
+ yield
110
+ elsif if_opt && (if_opt.is_a?(String) || if_opt.is_a?(Symbol)) && deploy_stage == if_opt.to_s
111
+ yield
112
+ elsif unless_opt && unless_opt.is_a?(Array) && !unless_opt.map {|x| x.to_s}.include?(deploy_stage)
113
+ yield
114
+ elsif unless_opt && (unless_opt.is_a?(String) || unless_opt.is_a?(Symbol)) && deploy_stage != unless_opt.to_s
115
+ yield
116
+ end
117
+ end
118
+
119
+ # Render the ERB template located at <tt>pathname</tt>. If a template exists
120
+ # with the same basename at <tt>RAILS_ROOT/app/manifests/templates</tt>, it
121
+ # is used instead. This is useful to override templates provided by plugins
122
+ # to customize application configuration files.
123
+ def template(pathname, b = binding)
124
+ template_contents = nil
125
+ basename = pathname.index('/') ? pathname.split('/').last : pathname
126
+ if File.exist?(File.expand_path(File.join(rails_root, 'app', 'manifests', 'templates', basename)))
127
+ template_contents = File.read(File.expand_path(File.join(rails_root, 'app', 'manifests', 'templates', basename)))
128
+ elsif File.exist?(File.expand_path(pathname))
129
+ template_contents = File.read(File.expand_path(pathname))
130
+ else
131
+ raise LoadError, "Can't find template #{pathname}"
132
+ end
133
+ ERB.new(template_contents).result(b)
134
+ end
135
+
136
+ def self.initial_configuration
137
+ # config/moonshine.yml
138
+ moonshine_yml = IO.read(File.join(rails_root, 'config', 'moonshine.yml')) rescue nil
139
+ configure(YAML::load(ERB.new(moonshine_yml).result)) if moonshine_yml
140
+
141
+ # database config
142
+ database_yml = IO.read(File.join(rails_root, 'config', 'database.yml')) rescue nil
143
+ configure(:database => YAML::load(ERB.new(database_yml).result)) if database_yml
144
+
145
+ # gems
146
+ configure(:gems => (YAML.load_file(File.join(rails_root, 'config', 'gems.yml')) rescue nil))
147
+ end
148
+
149
+ initial_configuration
150
+
151
+ end
@@ -0,0 +1,54 @@
1
+ #The Rails Manifest includes recipes for Apache, Mysql, Sqlite3 and Rails
2
+ #running on Ubuntu 8.04 or greater.
3
+ class Moonshine::Manifest::Rails < Moonshine::Manifest
4
+ def validate_platform
5
+ unless Facter.lsbdistid == 'Ubuntu' && Facter.lsbdistrelease.to_f >= 8.04
6
+ error = <<-ERROR
7
+
8
+
9
+ Moonshine::Manifest::Rails is currently only supported on Ubuntu 8.04
10
+ or greater. If you'd like to see your favorite distro supported, fork
11
+ Moonshine on GitHub!
12
+ ERROR
13
+ raise NotImplementedError, error
14
+ end
15
+ end
16
+ recipe :validate_platform
17
+
18
+ configure(:apt_gems => YAML.load_file(File.join(File.dirname(__FILE__), 'rails', 'apt_gems.yml')))
19
+
20
+ require File.join(File.dirname(__FILE__), 'rails', 'passenger.rb')
21
+ include Moonshine::Manifest::Rails::Passenger
22
+ require File.join(File.dirname(__FILE__), 'rails', 'mysql.rb')
23
+ include Moonshine::Manifest::Rails::Mysql
24
+ require File.join(File.dirname(__FILE__), 'rails', 'postgresql.rb')
25
+ include Moonshine::Manifest::Rails::Postgresql
26
+ require File.join(File.dirname(__FILE__), 'rails', 'sqlite3.rb')
27
+ include Moonshine::Manifest::Rails::Sqlite3
28
+ require File.join(File.dirname(__FILE__), 'rails', 'apache.rb')
29
+ include Moonshine::Manifest::Rails::Apache
30
+ require File.join(File.dirname(__FILE__), 'rails', 'rails.rb')
31
+ include Moonshine::Manifest::Rails::Rails
32
+ require File.join(File.dirname(__FILE__), 'rails', 'os.rb')
33
+ include Moonshine::Manifest::Rails::Os
34
+
35
+ # A super recipe for installing Apache, Passenger, a database,
36
+ # Rails, NTP, Cron, Postfix. To customize your stack, call the
37
+ # individual recipes you want to include rather than default_stack.
38
+ #
39
+ # The database installed is based on the adapter in database.yml.
40
+ def default_stack
41
+ self.class.recipe :apache_server
42
+ self.class.recipe :passenger_gem, :passenger_configure_gem_path, :passenger_apache_module, :passenger_site
43
+ case database_environment[:adapter]
44
+ when 'mysql'
45
+ self.class.recipe :mysql_server, :mysql_gem, :mysql_database, :mysql_user, :mysql_fixup_debian_start
46
+ when 'postgresql'
47
+ self.class.recipe :postgresql_server, :postgresql_gem, :postgresql_user, :postgresql_database
48
+ when 'sqlite' || 'sqlite3'
49
+ self.class.recipe :sqlite3
50
+ end
51
+ self.class.recipe :rails_rake_environment, :rails_gems, :rails_directories, :rails_bootstrap, :rails_migrations, :rails_logrotate
52
+ self.class.recipe :ntp, :time_zone, :postfix, :cron_packages, :motd, :security_updates
53
+ end
54
+ end
@@ -0,0 +1,99 @@
1
+ module Moonshine::Manifest::Rails::Apache
2
+
3
+ # Installs Apache 2.2 and enables mod_rewrite and mod_status. Enables mod_ssl
4
+ # if <tt>configuration[:ssl]</tt> is present
5
+ def apache_server
6
+ package "apache2-mpm-worker", :ensure => :installed
7
+ service "apache2", :require => package("apache2-mpm-worker"), :restart => '/etc/init.d/apache2 restart', :ensure => :running
8
+ a2enmod('rewrite')
9
+ a2enmod('status')
10
+ if configuration[:ssl]
11
+ a2enmod('headers')
12
+ a2enmod('ssl')
13
+ end
14
+ if configuration[:apache] && configuration[:apache][:users]
15
+ htpasswd = configuration[:apache][:htpasswd] || "#{configuration[:deploy_to]}/shared/config/htpasswd"
16
+
17
+ file htpasswd, :ensure => :file, :owner => 'rails', :mode => '644'
18
+
19
+ configuration[:apache][:users].each do |user,pass|
20
+ exec "htpasswd #{user}",
21
+ :command => "htpasswd -b #{htpasswd} #{user} #{pass}",
22
+ :unless => "grep '#{user}' #{htpasswd}"
23
+ end
24
+ end
25
+ status = <<-STATUS
26
+ <IfModule mod_status.c>
27
+ ExtendedStatus On
28
+ <Location /server-status>
29
+ SetHandler server-status
30
+ order deny,allow
31
+ deny from all
32
+ allow from 127.0.0.1
33
+ </Location>
34
+ </IfModule>
35
+ STATUS
36
+ file '/etc/apache2/mods-available/status.conf',
37
+ :ensure => :present,
38
+ :mode => '644',
39
+ :require => exec('a2enmod status'),
40
+ :content => status,
41
+ :notify => service("apache2")
42
+ file '/etc/logrotate.d/varlogapachelog.conf', :ensure => :absent
43
+ end
44
+
45
+ private
46
+
47
+ # Symlinks a site from <tt>/etc/apache2/sites-enabled/site</tt> to
48
+ #<tt>/etc/apache2/sites-available/site</tt>. Creates
49
+ #<tt>exec("a2ensite #{site}")</tt>.
50
+ def a2ensite(site, options = {})
51
+ exec("a2ensite #{site}", {
52
+ :command => "/usr/sbin/a2ensite #{site}",
53
+ :unless => "ls /etc/apache2/sites-enabled/#{site}",
54
+ :require => package("apache2-mpm-worker"),
55
+ :notify => service("apache2")
56
+ }.merge(options)
57
+ )
58
+ end
59
+
60
+ # Removes a symlink from <tt>/etc/apache2/sites-enabled/site</tt> to
61
+ #<tt>/etc/apache2/sites-available/site</tt>. Creates
62
+ #<tt>exec("a2dissite #{site}")</tt>.
63
+ def a2dissite(site, options = {})
64
+ exec("a2dissite #{site}", {
65
+ :command => "/usr/sbin/a2dissite #{site}",
66
+ :onlyif => "ls /etc/apache2/sites-enabled/#{site}",
67
+ :require => package("apache2-mpm-worker"),
68
+ :notify => service("apache2")
69
+ }.merge(options)
70
+ )
71
+ end
72
+
73
+ # Symlinks a module from <tt>/etc/apache2/mods-enabled/mod</tt> to
74
+ #<tt>/etc/apache2/mods-available/mod</tt>. Creates
75
+ #<tt>exec("a2enmod #{mod}")</tt>.
76
+ def a2enmod(mod, options = {})
77
+ exec("a2enmod #{mod}", {
78
+ :command => "/usr/sbin/a2enmod #{mod}",
79
+ :unless => "ls /etc/apache2/mods-enabled/#{mod}.load",
80
+ :require => package("apache2-mpm-worker"),
81
+ :notify => service("apache2")
82
+ }.merge(options)
83
+ )
84
+ end
85
+
86
+ # Removes a symlink from <tt>/etc/apache2/mods-enabled/mod</tt> to
87
+ #<tt>/etc/apache2/mods-available/mod</tt>. Creates
88
+ #<tt>exec("a2dismod #{mod}")</tt>.
89
+ def a2dismod(mod, options = {})
90
+ exec("a2dismod #{mod}", {
91
+ :command => "/usr/sbin/a2enmod #{mod}",
92
+ :onlyif => "ls /etc/apache2/mods-enabled/#{mod}.load",
93
+ :require => package("apache2-mpm-worker"),
94
+ :notify => service("apache2")
95
+ }.merge(options)
96
+ )
97
+ end
98
+
99
+ end
@@ -0,0 +1,32 @@
1
+ curb:
2
+ - libcurl4-openssl-dev
3
+ mysql:
4
+ - libmysqlclient15-dev
5
+ sqlite3-ruby:
6
+ - sqlite3
7
+ - libsqlite3-dev
8
+ nokogiri:
9
+ - libxml2-dev
10
+ - libxslt1-dev
11
+ rmagick:
12
+ - imagemagick
13
+ - libmagick9-dev
14
+ paperclip:
15
+ - imagemagick
16
+ - libmagick9-dev
17
+ thoughtbot-paperclip:
18
+ - imagemagick
19
+ - libmagick9-dev
20
+ mini_magick:
21
+ - imagemagick
22
+ - libmagick9-dev
23
+ postgres:
24
+ - postgresql-client
25
+ - postgresql-contrib
26
+ - libpq-dev
27
+ libxml-ruby:
28
+ - libxml2
29
+ - libxml2-dev
30
+ image_science:
31
+ - libfreeimage3
32
+ - libfreeimage-dev
@@ -0,0 +1,79 @@
1
+ module Moonshine::Manifest::Rails::Mysql
2
+
3
+ # Installs <tt>mysql-server</tt> from apt and enables the <tt>mysql</tt>
4
+ # service. Also creates a configuration file at
5
+ # <tt>/etc/mysql/conf.d/moonshine.cnf</tt>. See
6
+ # <tt>templates/moonshine.cnf</tt> for configuration options.
7
+ def mysql_server
8
+ package 'mysql-server', :ensure => :installed
9
+ service 'mysql', :ensure => :running, :require => [
10
+ package('mysql-server'),
11
+ package('mysql')
12
+ ]
13
+ #ensure the mysql key is present on the configuration hash
14
+ configure(:mysql => {})
15
+ file '/etc/mysql', :ensure => :directory
16
+ file '/etc/mysql/conf.d', :ensure => :directory
17
+ file '/etc/mysql/conf.d/innodb.cnf',
18
+ :ensure => :present,
19
+ :content => template(File.join(File.dirname(__FILE__), 'templates', 'innodb.cnf.erb')),
20
+ :before => package('mysql-server')
21
+ file '/etc/mysql/conf.d/moonshine.cnf',
22
+ :ensure => :present,
23
+ :content => template(File.join(File.dirname(__FILE__), 'templates', 'moonshine.cnf.erb')),
24
+ :require => package('mysql-server'),
25
+ :notify => service('mysql')
26
+ file '/etc/logrotate.d/varlogmysql.conf', :ensure => :absent
27
+ end
28
+
29
+ # Install the <tt>mysql</tt> rubygem and dependencies
30
+ def mysql_gem
31
+ gem('mysql')
32
+ end
33
+
34
+ # GRANT the database user specified in the current <tt>database_environment</tt>
35
+ # permisson to access the database with the supplied password
36
+ def mysql_user
37
+ grant =<<EOF
38
+ GRANT ALL PRIVILEGES
39
+ ON #{database_environment[:database]}.*
40
+ TO #{database_environment[:username]}@localhost
41
+ IDENTIFIED BY \\"#{database_environment[:password]}\\";
42
+ FLUSH PRIVILEGES;
43
+ EOF
44
+
45
+ exec "mysql_user",
46
+ :command => mysql_query(grant),
47
+ :unless => "mysqlshow -u#{database_environment[:username]} -p#{database_environment[:password]} #{database_environment[:database]}",
48
+ :require => exec('mysql_database'),
49
+ :before => exec('rake tasks')
50
+ end
51
+
52
+ # Create the database from the current <tt>database_environment</tt>
53
+ def mysql_database
54
+ exec "mysql_database",
55
+ :command => mysql_query("create database #{database_environment[:database]};"),
56
+ :unless => mysql_query("show create database #{database_environment[:database]};"),
57
+ :require => service('mysql'),
58
+ :notify => exec('rails_bootstrap')
59
+ end
60
+
61
+ # Noop <tt>/etc/mysql/debian-start</tt>, which does some nasty table scans on
62
+ # MySQL start.
63
+ def mysql_fixup_debian_start
64
+ file '/etc/mysql/debian-start',
65
+ :ensure => :present,
66
+ :content => "#!/bin/bash\nexit 0",
67
+ :mode => '755',
68
+ :owner => 'root',
69
+ :require => package('mysql-server')
70
+ end
71
+
72
+ private
73
+
74
+ # Internal helper to shell out and run a query. Doesn't select a database.
75
+ def mysql_query(sql)
76
+ "su -c \'/usr/bin/mysql -u root -e \"#{sql}\"\'"
77
+ end
78
+
79
+ end
@@ -0,0 +1,115 @@
1
+ module Moonshine::Manifest::Rails::Os
2
+ # Set up cron and enable the service. You can create cron jobs in your
3
+ # manifests like so:
4
+ #
5
+ # cron :run_me_at_three
6
+ # :command => "/usr/sbin/something",
7
+ # :user => root,
8
+ # :hour => 3
9
+ #
10
+ # cron 'rake:task',
11
+ # :command => "cd #{rails_root} && RAILS_ENV=#{ENV['RAILS_ENV']} rake rake:task",
12
+ # :user => configuration[:user],
13
+ # :minute => 15
14
+ def cron_packages
15
+ service "cron", :require => package("cron"), :ensure => :running
16
+ package "cron", :ensure => :installed
17
+ end
18
+
19
+ # Create a MOTD to remind those logging in via SSH that things are managed
20
+ # with Moonshine
21
+ def motd
22
+ motd_contents ="""-----------------
23
+ Moonshine Managed
24
+ -----------------
25
+
26
+ Application: #{configuration[:application]}
27
+ Repository: #{configuration[:repository]}
28
+ Deploy Path: #{configuration[:deploy_to]}
29
+
30
+ ----------------
31
+ A Reminder
32
+ ----------------
33
+ As the configuration of this server is managed with Moonshine, please refrain
34
+ from installing any gems, packages, or dependencies directly on the server.
35
+ ----------------
36
+ """
37
+ file '/var/run/motd',
38
+ :mode => '644',
39
+ :content => `uname -snrvm`+motd_contents
40
+ file '/etc/motd.tail',
41
+ :mode => '644',
42
+ :content => motd_contents
43
+ end
44
+
45
+ # Install postfix.
46
+ def postfix
47
+ package 'postfix', :ensure => :latest
48
+ end
49
+
50
+ # Install ntp and enables the ntp service.
51
+ def ntp
52
+ package 'ntp', :ensure => :latest
53
+ service 'ntp', :ensure => :running, :require => package('ntp'), :pattern => 'ntpd'
54
+ end
55
+
56
+ # Set the system timezone to <tt>configuration[:time_zone]</tt> or 'UTC' by
57
+ # default.
58
+ def time_zone
59
+ zone = configuration[:time_zone] || 'UTC'
60
+ zone = 'UTC' if zone.nil? || zone.strip == ''
61
+ file "/etc/timezone",
62
+ :content => zone+"\n",
63
+ :ensure => :present
64
+ file "/etc/localtime",
65
+ :ensure => "/usr/share/zoneinfo/#{zone}",
66
+ :notify => service('ntp')
67
+ end
68
+
69
+ # Configure automatic security updates. Output regarding errors
70
+ # will be sent to <tt>configuration[:user]</tt>. To exclude specific
71
+ # packages from these upgrades, create an array of packages on
72
+ # <tt>configuration[:unattended_upgrade][:package_blacklist]</tt>
73
+ def security_updates
74
+ configure(:unattended_upgrade => {})
75
+ unattended_config = <<-CONFIG
76
+ APT::Periodic::Update-Package-Lists "#{configuration[:unattended_upgrade][:package_lists]||1}";
77
+ APT::Periodic::Unattended-Upgrade "#{configuration[:unattended_upgrade][:interval]||1}";
78
+ CONFIG
79
+
80
+ package 'unattended-upgrades', :ensure => :latest
81
+ file '/etc/apt/apt.conf.d/10periodic',
82
+ :ensure => :present,
83
+ :mode => '644',
84
+ :content => unattended_config
85
+ file '/etc/apt/apt.conf.d/50unattended-upgrades',
86
+ :ensure => :present,
87
+ :mode => '644',
88
+ :content => template(File.join(File.dirname(__FILE__), "templates", "unattended_upgrades.erb"))
89
+ end
90
+
91
+ private
92
+
93
+ #Provides a helper for creating logrotate config for various parts of your
94
+ #stack. For example:
95
+ #
96
+ # logrotate('/srv/theapp/shared/logs/*.log', {
97
+ # :options => %w(daily missingok compress delaycompress sharedscripts),
98
+ # :postrotate => 'touch /srv/theapp/current/tmp/restart.txt'
99
+ # })
100
+ #
101
+ def logrotate(log_or_glob, options = {})
102
+ options = options.respond_to?(:to_hash) ? options.to_hash : {}
103
+
104
+ package "logrotate", :ensure => :installed, :require => package("cron"), :notify => service("cron")
105
+
106
+ safename = log_or_glob.gsub(/[^a-zA-Z]/, '')
107
+
108
+ file "/etc/logrotate.d/#{safename}.conf",
109
+ :ensure => :present,
110
+ :content => template(File.join(File.dirname(__FILE__), "templates", "logrotate.conf.erb"), binding),
111
+ :notify => service("cron"),
112
+ :alias => "logrotate_#{safename}"
113
+ end
114
+
115
+ end