Module: Moonshadow::Manifest::Rails::Os

Included in:
Moonshadow::Manifest::Rails
Defined in:
lib/moonshadow/manifest/rails/os.rb

Instance Method Summary collapse

Instance Method Details

#cron_packagesObject

Set up cron and enable the service. You can create cron jobs in your manifests like so:

cron :run_me_at_three
  :command => "/usr/sbin/something",
  :user => root,
  :hour => 3

cron 'rake:task',
    :command => "cd #{rails_root} && RAILS_ENV=#{ENV['RAILS_ENV']} rake rake:task",
    :user => configuration[:user],
    :minute => 15


14
15
16
17
# File 'lib/moonshadow/manifest/rails/os.rb', line 14

def cron_packages
  service "cron", :require => package("cron"), :ensure => :running
  package "cron", :ensure => :installed
end

#motdObject

Create a MOTD to remind those logging in via SSH that things are managed with Moonshadow



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/moonshadow/manifest/rails/os.rb', line 21

def motd
  motd_contents ="""-----------------
Moonshadow Managed
-----------------

Application:  #{configuration[:application]}
Repository:   #{configuration[:repository]}
Deploy Path:  #{configuration[:deploy_to]}

----------------
A Reminder
----------------
As the configuration of this server is managed with Moonshadow, please refrain
from installing any gems, packages, or dependencies directly on the server.
----------------
"""
  file '/var/run/motd',
    :mode => '644',
    :content => `uname -snrvm`+motd_contents
  file '/etc/motd.tail',
    :mode => '644',
    :content => motd_contents
end

#ntpObject

Install ntp and enables the ntp service.



51
52
53
54
# File 'lib/moonshadow/manifest/rails/os.rb', line 51

def ntp
  package 'ntp', :ensure => :latest
  service 'ntp', :ensure => :running, :require => package('ntp'), :pattern => 'ntpd'
end

#postfixObject

Install postfix.



46
47
48
# File 'lib/moonshadow/manifest/rails/os.rb', line 46

def postfix
  package 'postfix', :ensure => :latest
end

#security_updatesObject

Configure automatic security updates. Output regarding errors will be sent to configuration[:user]. To exclude specific packages from these upgrades, create an array of packages on configuration[:unattended_upgrade][:package_blacklist]



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/moonshadow/manifest/rails/os.rb', line 73

def security_updates
  configure(:unattended_upgrade => {})
  unattended_config = <<-CONFIG
APT::Periodic::Update-Package-Lists "#{configuration[:unattended_upgrade][:package_lists]||1}";
APT::Periodic::Unattended-Upgrade "#{configuration[:unattended_upgrade][:interval]||1}";
CONFIG

  package 'unattended-upgrades', :ensure => :latest
  file '/etc/apt/apt.conf.d/10periodic',
    :ensure => :present,
    :mode => '644',
    :content => unattended_config
  file '/etc/apt/apt.conf.d/50unattended-upgrades',
    :ensure => :present,
    :mode => '644',
    :content => template(File.join(File.dirname(__FILE__), "templates", "unattended_upgrades.erb"))
end

#time_zoneObject

Set the system timezone to configuration[:time_zone] or ‘UTC’ by default.



58
59
60
61
62
63
64
65
66
67
# File 'lib/moonshadow/manifest/rails/os.rb', line 58

def time_zone
  zone = configuration[:time_zone] || 'UTC'
  zone = 'UTC' if zone.nil? || zone.strip == ''
  file "/etc/timezone",
    :content => zone+"\n",
    :ensure => :present
  file "/etc/localtime",
    :ensure => "/usr/share/zoneinfo/#{zone}",
    :notify => service('ntp')
end