filesystem.rb
2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#
# Author:: Earth U (<sysadmin @ chromedia.com>)
# Cookbook Name:: cfe-server
# Recipes:: filesystem
#
# Copyright 2016, Chromedia Far East, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
swapfile = node[cookbook_name]['filesystem']['swapfile']
bash 'enable_swap' do
code <<-EOF.gsub(/^\s+/, '')
set -e
if [[ ! -f #{swapfile} ]] ; then
fallocate -l #{node[cookbook_name]['filesystem']['swapsize']} #{swapfile}
chmod 600 #{swapfile}
mkswap #{swapfile}
swapon #{swapfile}
echo "#{swapfile} none swap sw 0 0" >> /etc/fstab
fi
EOF
only_if { swapfile }
end
if node['backup-file2s3']['backups']
node['backup-file2s3']['backups'].each do |xback|
xbucket = xback[:bucket]
xregion = xback[:region]
xback[:paths].each do |xpath|
# Each path spec can have the following additional attributes:
# {
# :extract => true, # Default: true
# :ex_creates => 'filename' # Relative to path.
# }
unless xpath.has_key?(:extract) && xpath[:extract] == false
ptarget_dir = ::File.dirname(xpath[:path])
pcreates = "#{xpath[:path]}/#{xpath[:ex_creates]}"
pencrypted = xpath[:bak_encrypted]
pfname = xpath[:bak_filename] || ::File.basename(xpath[:path])
aws_tar_extract pfname do
target_dir ptarget_dir
creates pcreates
encrypted pencrypted
bucket xbucket
region xregion
end
end
end
end
end
include_recipe 'backup-file2s3'
node[cookbook_name]['filesystem']['perms'].each do |perm|
if perm[:owner] && perm[:group]
execute "chown -R #{perm[:owner]}:#{perm[:group]} #{perm[:path]}"
elsif perm[:owner]
execute "chown -R #{perm[:owner]} #{perm[:path]}"
elsif perm[:group]
execute "chgrp -R #{perm[:group]} #{perm[:path]}"
end
if perm[:mode]
execute "chmod -R #{perm[:mode]} #{perm[:path]}"
end
end
node[cookbook_name]['filesystem']['symlinks'].each do |xfrom, xto|
directory(::File.dirname(xfrom)) { recursive true }
link(xfrom) { to xto }
end