giraffesoft-chef 0.7.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. data/LICENSE +201 -0
  2. data/README.rdoc +135 -0
  3. data/bin/chef-client +26 -0
  4. data/bin/chef-solo +26 -0
  5. data/distro/debian/etc/init.d/chef-client +175 -0
  6. data/distro/debian/etc/init.d/chef-indexer +175 -0
  7. data/distro/debian/etc/init.d/chef-server +120 -0
  8. data/distro/debian/man/man1/chef-indexer.1 +42 -0
  9. data/distro/debian/man/man1/chef-server.1 +108 -0
  10. data/distro/debian/man/man8/chef-client.8 +61 -0
  11. data/distro/debian/man/man8/chef-solo.8 +58 -0
  12. data/distro/redhat/etc/chef/client.rb +16 -0
  13. data/distro/redhat/etc/chef/indexer.rb +10 -0
  14. data/distro/redhat/etc/chef/server.rb +22 -0
  15. data/distro/redhat/etc/init.d/chef-client +74 -0
  16. data/distro/redhat/etc/init.d/chef-indexer +76 -0
  17. data/distro/redhat/etc/init.d/chef-server +77 -0
  18. data/lib/chef.rb +49 -0
  19. data/lib/chef/application.rb +98 -0
  20. data/lib/chef/application/agent.rb +18 -0
  21. data/lib/chef/application/client.rb +209 -0
  22. data/lib/chef/application/indexer.rb +141 -0
  23. data/lib/chef/application/server.rb +18 -0
  24. data/lib/chef/application/solo.rb +214 -0
  25. data/lib/chef/client.rb +421 -0
  26. data/lib/chef/compile.rb +170 -0
  27. data/lib/chef/config.rb +141 -0
  28. data/lib/chef/cookbook.rb +171 -0
  29. data/lib/chef/cookbook/metadata.rb +407 -0
  30. data/lib/chef/cookbook/metadata/version.rb +87 -0
  31. data/lib/chef/cookbook_loader.rb +180 -0
  32. data/lib/chef/couchdb.rb +176 -0
  33. data/lib/chef/daemon.rb +170 -0
  34. data/lib/chef/exceptions.rb +36 -0
  35. data/lib/chef/file_cache.rb +205 -0
  36. data/lib/chef/log.rb +39 -0
  37. data/lib/chef/mixin/check_helper.rb +31 -0
  38. data/lib/chef/mixin/checksum.rb +37 -0
  39. data/lib/chef/mixin/command.rb +386 -0
  40. data/lib/chef/mixin/convert_to_class_name.rb +48 -0
  41. data/lib/chef/mixin/create_path.rb +56 -0
  42. data/lib/chef/mixin/deep_merge.rb +36 -0
  43. data/lib/chef/mixin/find_preferred_file.rb +92 -0
  44. data/lib/chef/mixin/from_file.rb +50 -0
  45. data/lib/chef/mixin/generate_url.rb +49 -0
  46. data/lib/chef/mixin/language.rb +79 -0
  47. data/lib/chef/mixin/params_validate.rb +197 -0
  48. data/lib/chef/mixin/recipe_definition_dsl_core.rb +77 -0
  49. data/lib/chef/mixin/template.rb +84 -0
  50. data/lib/chef/node.rb +406 -0
  51. data/lib/chef/node/attribute.rb +412 -0
  52. data/lib/chef/openid_registration.rb +181 -0
  53. data/lib/chef/platform.rb +254 -0
  54. data/lib/chef/provider.rb +101 -0
  55. data/lib/chef/provider/cron.rb +187 -0
  56. data/lib/chef/provider/deploy.rb +281 -0
  57. data/lib/chef/provider/deploy/revision.rb +70 -0
  58. data/lib/chef/provider/deploy/timestamped.rb +33 -0
  59. data/lib/chef/provider/directory.rb +72 -0
  60. data/lib/chef/provider/execute.rb +58 -0
  61. data/lib/chef/provider/file.rb +191 -0
  62. data/lib/chef/provider/git.rb +198 -0
  63. data/lib/chef/provider/group.rb +120 -0
  64. data/lib/chef/provider/group/gpasswd.rb +50 -0
  65. data/lib/chef/provider/group/groupadd.rb +78 -0
  66. data/lib/chef/provider/group/pw.rb +88 -0
  67. data/lib/chef/provider/group/usermod.rb +57 -0
  68. data/lib/chef/provider/http_request.rb +102 -0
  69. data/lib/chef/provider/ifconfig.rb +131 -0
  70. data/lib/chef/provider/link.rb +157 -0
  71. data/lib/chef/provider/mount.rb +117 -0
  72. data/lib/chef/provider/mount/mount.rb +208 -0
  73. data/lib/chef/provider/package.rb +160 -0
  74. data/lib/chef/provider/package/apt.rb +110 -0
  75. data/lib/chef/provider/package/dpkg.rb +109 -0
  76. data/lib/chef/provider/package/freebsd.rb +153 -0
  77. data/lib/chef/provider/package/macports.rb +105 -0
  78. data/lib/chef/provider/package/portage.rb +124 -0
  79. data/lib/chef/provider/package/rpm.rb +99 -0
  80. data/lib/chef/provider/package/rubygems.rb +136 -0
  81. data/lib/chef/provider/package/yum-dump.py +106 -0
  82. data/lib/chef/provider/package/yum.rb +175 -0
  83. data/lib/chef/provider/remote_directory.rb +126 -0
  84. data/lib/chef/provider/remote_file.rb +141 -0
  85. data/lib/chef/provider/route.rb +118 -0
  86. data/lib/chef/provider/ruby_block.rb +15 -0
  87. data/lib/chef/provider/script.rb +42 -0
  88. data/lib/chef/provider/service.rb +135 -0
  89. data/lib/chef/provider/service/debian.rb +64 -0
  90. data/lib/chef/provider/service/freebsd.rb +157 -0
  91. data/lib/chef/provider/service/gentoo.rb +54 -0
  92. data/lib/chef/provider/service/init.rb +71 -0
  93. data/lib/chef/provider/service/redhat.rb +62 -0
  94. data/lib/chef/provider/service/simple.rb +115 -0
  95. data/lib/chef/provider/subversion.rb +148 -0
  96. data/lib/chef/provider/template.rb +143 -0
  97. data/lib/chef/provider/user.rb +170 -0
  98. data/lib/chef/provider/user/pw.rb +113 -0
  99. data/lib/chef/provider/user/useradd.rb +107 -0
  100. data/lib/chef/queue.rb +145 -0
  101. data/lib/chef/recipe.rb +144 -0
  102. data/lib/chef/resource.rb +380 -0
  103. data/lib/chef/resource/apt_package.rb +34 -0
  104. data/lib/chef/resource/bash.rb +33 -0
  105. data/lib/chef/resource/cron.rb +179 -0
  106. data/lib/chef/resource/csh.rb +33 -0
  107. data/lib/chef/resource/deploy.rb +350 -0
  108. data/lib/chef/resource/deploy_revision.rb +35 -0
  109. data/lib/chef/resource/directory.rb +76 -0
  110. data/lib/chef/resource/dpkg_package.rb +34 -0
  111. data/lib/chef/resource/execute.rb +127 -0
  112. data/lib/chef/resource/file.rb +84 -0
  113. data/lib/chef/resource/gem_package.rb +41 -0
  114. data/lib/chef/resource/git.rb +36 -0
  115. data/lib/chef/resource/group.rb +70 -0
  116. data/lib/chef/resource/http_request.rb +52 -0
  117. data/lib/chef/resource/ifconfig.rb +134 -0
  118. data/lib/chef/resource/link.rb +78 -0
  119. data/lib/chef/resource/macports_package.rb +29 -0
  120. data/lib/chef/resource/mount.rb +135 -0
  121. data/lib/chef/resource/package.rb +80 -0
  122. data/lib/chef/resource/perl.rb +33 -0
  123. data/lib/chef/resource/portage_package.rb +33 -0
  124. data/lib/chef/resource/python.rb +33 -0
  125. data/lib/chef/resource/remote_directory.rb +91 -0
  126. data/lib/chef/resource/remote_file.rb +60 -0
  127. data/lib/chef/resource/route.rb +135 -0
  128. data/lib/chef/resource/ruby.rb +33 -0
  129. data/lib/chef/resource/ruby_block.rb +20 -0
  130. data/lib/chef/resource/scm.rb +129 -0
  131. data/lib/chef/resource/script.rb +51 -0
  132. data/lib/chef/resource/service.rb +134 -0
  133. data/lib/chef/resource/subversion.rb +33 -0
  134. data/lib/chef/resource/template.rb +60 -0
  135. data/lib/chef/resource/timestamped_deploy.rb +31 -0
  136. data/lib/chef/resource/user.rb +98 -0
  137. data/lib/chef/resource_collection.rb +204 -0
  138. data/lib/chef/resource_definition.rb +67 -0
  139. data/lib/chef/rest.rb +238 -0
  140. data/lib/chef/role.rb +231 -0
  141. data/lib/chef/run_list.rb +156 -0
  142. data/lib/chef/runner.rb +130 -0
  143. data/lib/chef/search.rb +88 -0
  144. data/lib/chef/search/result.rb +64 -0
  145. data/lib/chef/search_index.rb +77 -0
  146. data/lib/chef/tasks/chef_repo.rake +347 -0
  147. data/lib/chef/util/file_edit.rb +125 -0
  148. data/lib/chef/util/fileedit.rb +121 -0
  149. metadata +293 -0
@@ -0,0 +1,157 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2008 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef/config'
20
+ require 'chef/log'
21
+ require 'chef/mixin/command'
22
+ require 'chef/resource/link'
23
+ require 'chef/provider'
24
+
25
+ class Chef
26
+ class Provider
27
+ class Link < Chef::Provider
28
+ include Chef::Mixin::Command
29
+
30
+ def negative_complement(big)
31
+ if big > 1073741823 # Fixnum max
32
+ big -= (2**32) # diminished radix wrap to negative
33
+ end
34
+ big
35
+ end
36
+
37
+ private :negative_complement
38
+
39
+ def load_current_resource
40
+ @current_resource = Chef::Resource::Link.new(@new_resource.name)
41
+ @current_resource.target_file(@new_resource.target_file)
42
+ @current_resource.link_type(@new_resource.link_type)
43
+ if @new_resource.link_type == :symbolic
44
+ if ::File.exists?(@current_resource.target_file) && ::File.symlink?(@current_resource.target_file)
45
+ @current_resource.to(
46
+ ::File.expand_path(::File.readlink(@current_resource.target_file))
47
+ )
48
+ cstats = ::File.lstat(@current_resource.target_file)
49
+ @current_resource.owner(cstats.uid)
50
+ @current_resource.group(cstats.gid)
51
+ else
52
+ @current_resource.to("")
53
+ end
54
+ elsif @new_resource.link_type == :hard
55
+ if ::File.exists?(@current_resource.target_file) && ::File.exists?(@new_resource.to)
56
+ if ::File.stat(@current_resource.target_file).ino == ::File.stat(@new_resource.to).ino
57
+ @current_resource.to(@new_resource.to)
58
+ else
59
+ @current_resource.to("")
60
+ end
61
+ else
62
+ @current_resource.to("")
63
+ end
64
+ end
65
+ @current_resource
66
+ end
67
+
68
+ # Compare the ownership of a symlink. Returns true if they are the same, false if they are not.
69
+ def compare_owner
70
+ return false if @new_resource.owner.nil?
71
+
72
+ @set_user_id = case @new_resource.owner
73
+ when /^\d+$/, Integer
74
+ @new_resource.owner.to_i
75
+ else
76
+ # This raises an ArgumentError if you can't find the user
77
+ Etc.getpwnam(@new_resource.owner).uid
78
+ end
79
+
80
+ @set_user_id == @current_resource.owner
81
+ end
82
+
83
+ # Set the ownership on the symlink, assuming it is not set correctly already.
84
+ def set_owner
85
+ unless compare_owner
86
+ Chef::Log.info("Setting owner to #{@set_user_id} for #{@new_resource}")
87
+ @set_user_id = negative_complement(@set_user_id)
88
+ ::File.lchown(@set_user_id, nil, @new_resource.target_file)
89
+ @new_resource.updated = true
90
+ end
91
+ end
92
+
93
+ # Compares the group of a symlink. Returns true if they are the same, false if they are not.
94
+ def compare_group
95
+ return false if @new_resource.group.nil?
96
+
97
+ @set_group_id = case @new_resource.group
98
+ when /^\d+$/, Integer
99
+ @new_resource.group.to_i
100
+ else
101
+ Etc.getgrnam(@new_resource.group).gid
102
+ end
103
+
104
+ @set_group_id == @current_resource.group
105
+ end
106
+
107
+ def set_group
108
+ unless compare_group
109
+ Chef::Log.info("Setting group to #{@set_group_id} for #{@new_resource}")
110
+ @set_group_id = negative_complement(@set_group_id)
111
+ ::File.lchown(nil, @set_group_id, @new_resource.target_file)
112
+ @new_resource.updated = true
113
+ end
114
+ end
115
+
116
+ def action_create
117
+ if @current_resource.to != @new_resource.to
118
+ Chef::Log.info("Creating a #{@new_resource.link_type} link from #{@new_resource.to} -> #{@new_resource.target_file} for #{@new_resource}")
119
+ if @new_resource.link_type == :symbolic
120
+ run_command(
121
+ :command => "ln -nfs #{@new_resource.to} #{@new_resource.target_file}"
122
+ )
123
+ elsif @new_resource.link_type == :hard
124
+ ::File.link(@new_resource.to, @new_resource.target_file)
125
+ end
126
+ @new_resource.updated = true
127
+ end
128
+ if @new_resource.link_type == :symbolic
129
+ set_owner unless @new_resource.owner.nil?
130
+ set_group unless @new_resource.group.nil?
131
+ end
132
+ end
133
+
134
+ def action_delete
135
+ if @new_resource.link_type == :symbolic
136
+ if ::File.symlink?(@new_resource.target_file)
137
+ Chef::Log.info("Deleting #{@new_resource} at #{@new_resource.target_file}")
138
+ ::File.delete(@new_resource.target_file)
139
+ @new_resource.updated = true
140
+ elsif ::File.exists?(@new_resource.target_file)
141
+ raise Chef::Exceptions::Link, "Cannot delete #{@new_resource} at #{@new_resource.target_file}! Not a symbolic link."
142
+ end
143
+ elsif @new_resource.link_type == :hard
144
+ if ::File.exists?(@new_resource.target_file)
145
+ if ::File.exists?(@new_resource.to) && ::File.stat(@current_resource.target_file).ino == ::File.stat(@new_resource.to).ino
146
+ Chef::Log.info("Deleting #{@new_resource} at #{@new_resource.target_file}")
147
+ ::File.delete(@new_resource.target_file)
148
+ @new_resource.updated = true
149
+ else
150
+ raise Chef::Exceptions::Link, "Cannot delete #{@new_resource} at #{@new_resource.target_file}! Not a hard link."
151
+ end
152
+ end
153
+ end
154
+ end
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,117 @@
1
+ #
2
+ # Author:: Joshua Timberman (<joshua@opscode.com>)
3
+ # Copyright:: Copyright (c) 2009 Opscode, Inc
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef/log'
20
+ require 'chef/mixin/command'
21
+ require 'chef/provider'
22
+
23
+ class Chef
24
+ class Provider
25
+ class Mount < Chef::Provider
26
+
27
+ include Chef::Mixin::Command
28
+
29
+ def action_mount
30
+ unless @current_resource.mounted
31
+ Chef::Log.debug("#{@new_resource}: attempting to mount")
32
+ status = mount_fs()
33
+ if status
34
+ @new_resource.updated = true
35
+ Chef::Log.info("#{@new_resource}: mounted successfully")
36
+ end
37
+ else
38
+ Chef::Log.debug("#{@new_resource}: not mounting, already mounted")
39
+ end
40
+ end
41
+
42
+ def action_umount
43
+ if @current_resource.mounted
44
+ Chef::Log.debug("#{@new_resource}: attempting to unmount")
45
+ status = umount_fs()
46
+ if status
47
+ @new_resource.updated = true
48
+ Chef::Log.info("#{@new_resource}: unmounted successfully")
49
+ end
50
+ else
51
+ Chef::Log.debug("#{@new_resource}: not unmounting, already unmounted")
52
+ end
53
+ end
54
+
55
+ def action_remount
56
+ unless @new_resource.supports[:remount]
57
+ raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :remount"
58
+ else
59
+ if @current_resource.mounted
60
+ Chef::Log.debug("#{@new_resource}: attempting to remount")
61
+ status = remount_fs()
62
+ if status
63
+ @new_resource.updated = true
64
+ Chef::Log.info("#{@new_resource}: remounted successfully")
65
+ end
66
+ else
67
+ Chef::Log.debug("#{@new_resource}: not mounted, not remounting")
68
+ end
69
+ end
70
+ end
71
+
72
+ def action_enable
73
+ unless @current_resource.enabled
74
+ status = enable_fs
75
+ if status
76
+ @new_resource.updated = true
77
+ Chef::Log.info("#{@new_resource}: enabled successfully")
78
+ else
79
+ Chef::Log.debug("#{@new_resource}: not enabling, already enabled")
80
+ end
81
+ end
82
+ end
83
+
84
+ def action_disable
85
+ if @current_resource.enabled
86
+ status = disable_fs
87
+ if status
88
+ @new_resource.updated = true
89
+ Chef::Log.info("#{@new_resource}: disabled successfully")
90
+ else
91
+ Chef::Log.debug("#{@new_resource}: not disabling, already disabled")
92
+ end
93
+ end
94
+ end
95
+
96
+ def mount_fs
97
+ raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :mount"
98
+ end
99
+
100
+ def umount_fs
101
+ raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :umount"
102
+ end
103
+
104
+ def remount_fs
105
+ raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :remount"
106
+ end
107
+
108
+ def enable_fs
109
+ raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :enable"
110
+ end
111
+
112
+ def disable_fs
113
+ raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :disable"
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,208 @@
1
+ #
2
+ # Author:: Joshua Timberman (<joshua@opscode.com>)
3
+ # Copyright:: Copyright (c) 2009 Opscode, Inc
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef/provider/mount'
20
+ require 'chef/log'
21
+ require 'chef/mixin/command'
22
+
23
+ class Chef
24
+ class Provider
25
+ class Mount
26
+ class Mount < Chef::Provider::Mount
27
+
28
+ include Chef::Mixin::Command
29
+
30
+ def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil)
31
+ super(node, new_resource, collection, definitions, cookbook_loader)
32
+ @real_device = nil
33
+ end
34
+ attr_accessor :real_device
35
+
36
+ def load_current_resource
37
+ @current_resource = Chef::Resource::Mount.new(@new_resource.name)
38
+ @current_resource.mount_point(@new_resource.mount_point)
39
+ @current_resource.device(@new_resource.device)
40
+ Chef::Log.debug("Checking for mount point #{@current_resource.mount_point}")
41
+
42
+ # only check for existence of non-remote devices
43
+ if(@new_resource.device !~ /:/ && !::File.exists?(@new_resource.device) )
44
+ raise Chef::Exceptions::Mount, "Device #{@new_resource.device} does not exist"
45
+ elsif( !::File.exists?(@new_resource.mount_point) )
46
+ raise Chef::Exceptions::Mount, "Mount point #{@new_resource.mount_point} does not exist"
47
+ end
48
+
49
+ # Check to see if the volume is mounted. Last volume entry wins.
50
+ mounted = false
51
+ popen4("mount") do |pid, stdin, stdout, stderr|
52
+ stdout.each do |line|
53
+ case line
54
+ when /^#{device_mount_regex}\s+on\s+#{@new_resource.mount_point}/
55
+ mounted = true
56
+ Chef::Log.debug("Special device #{device_logstring} mounted as #{@new_resource.mount_point}")
57
+ when /^([\/\w])+\son\s#{@new_resource.mount_point}\s+/
58
+ mounted = false
59
+ Chef::Log.debug("Special device #{$~[1]} mounted as #{@new_resource.mount_point}")
60
+ end
61
+ end
62
+ end
63
+ @current_resource.mounted(mounted)
64
+
65
+ # Check to see if there is a entry in /etc/fstab. Last entry for a volume wins.
66
+ enabled = false
67
+ ::File.read("/etc/fstab").each do |line|
68
+ case line
69
+ when /^[#\s]/
70
+ next
71
+ when /^#{device_fstab_regex}\s+#{@new_resource.mount_point}/
72
+ enabled = true
73
+ Chef::Log.debug("Found mount #{device_fstab} to #{@new_resource.mount_point} in /etc/fstab")
74
+ when /^[\/\w]+\s+#{@new_resource.mount_point}/
75
+ enabled = false
76
+ Chef::Log.debug("Found conflicting mount point #{@new_resource.mount_point} in /etc/fstab")
77
+ end
78
+ end
79
+ @current_resource.enabled(enabled)
80
+ end
81
+
82
+ def mount_fs
83
+ unless @current_resource.mounted
84
+ command = "mount -t #{@new_resource.fstype}"
85
+ command << " -o #{@new_resource.options.join(',')}" unless @new_resource.options.nil? || @new_resource.options.empty?
86
+ command << " #{device_real}"
87
+ command << " #{@new_resource.mount_point}"
88
+ run_command(:command => command)
89
+ Chef::Log.info("Mounted #{@new_resource.mount_point}")
90
+ else
91
+ Chef::Log.debug("#{@new_resource.mount_point} is already mounted.")
92
+ end
93
+ end
94
+
95
+ def umount_fs
96
+ if @current_resource.mounted
97
+ command = "umount #{@new_resource.mount_point}"
98
+ run_command(:command => command)
99
+ Chef::Log.info("Unmounted #{@new_resource.mount_point}")
100
+ else
101
+ Chef::Log.debug("#{@new_resource.mount_point} is not mounted.")
102
+ end
103
+ end
104
+
105
+ def remount_fs
106
+ if @current_resource.mounted and @new_resource.supports[:remount]
107
+ command = "mount -o remount #{@new_resource.mount_point}"
108
+ run_command(:command => command)
109
+
110
+ @new_resource.updated = true
111
+ Chef::Log.info("Remounted #{@new_resource.mount_point}")
112
+ elsif @current_resource.mounted
113
+ umount_fs
114
+ sleep 1
115
+ mount_fs
116
+ else
117
+ Chef::Log.debug("#{@new_resource.mount_point} is not mounted.")
118
+ end
119
+ end
120
+
121
+ def enable_fs
122
+ unless @current_resource.enabled
123
+ ::File.open("/etc/fstab", "a") do |fstab|
124
+ fstab.puts("#{device_fstab} #{@new_resource.mount_point} #{@new_resource.fstype} #{@new_resource.options.nil? ? "defaults" : @new_resource.options.join(",")} #{@new_resource.dump} #{@new_resource.pass}")
125
+ Chef::Log.info("Enabled #{@new_resource.mount_point}")
126
+ end
127
+ else
128
+ Chef::Log.debug("#{@new_resource.mount_point} is already enabled.")
129
+ end
130
+ end
131
+
132
+ def disable_fs
133
+ if @current_resource.enabled
134
+ contents = []
135
+
136
+ found = false
137
+ ::File.readlines("/etc/fstab").reverse_each do |line|
138
+ if !found && line =~ /^#{device_fstab_regex}\s+#{@new_resource.mount_point}/
139
+ found = true
140
+ Chef::Log.debug("Removing #{@new_resource.mount_point} from fstab")
141
+ next
142
+ else
143
+ contents << line
144
+ end
145
+ end
146
+
147
+ ::File.open("/etc/fstab", "w") do |fstab|
148
+ contents.reverse_each { |line| fstab.puts line}
149
+ end
150
+ else
151
+ Chef::Log.debug("#{@new_resource.mount_point} is not enabled")
152
+ end
153
+ end
154
+
155
+ private
156
+ def device_fstab
157
+ case @new_resource.device_type
158
+ when :device
159
+ @new_resource.device
160
+ when :label
161
+ "LABEL=#{@new_resource.device}"
162
+ when :uuid
163
+ "UUID=#{@new_resource.device}"
164
+ end
165
+ end
166
+
167
+ def device_real
168
+ if @real_device == nil
169
+ if @new_resource.device_type == :device
170
+ @real_device = @new_resource.device
171
+ else
172
+ status = popen4("/sbin/findfs #{device_fstab}") do |pid, stdin, stdout, stderr|
173
+ @real_device = stdout.first.chomp
174
+ end
175
+ unless status.exitstatus == 0
176
+ @real_device = "/dev/null"
177
+ end
178
+ end
179
+ end
180
+ @real_device
181
+ end
182
+
183
+ def device_logstring
184
+ case @new_resource.device_type
185
+ when :device
186
+ "#{device_real}"
187
+ when :label
188
+ "#{device_real} with label #{@new_resource.device}"
189
+ when :uuid
190
+ "#{device_real} with uuid #{@new_resource.device}"
191
+ end
192
+ end
193
+
194
+ def device_mount_regex
195
+ ::File.symlink?(device_real) ? "(?:#{device_real})|(?:#{::File.readlink(device_real)})" : device_real
196
+ end
197
+
198
+ def device_fstab_regex
199
+ if @new_resource.device_type == :device
200
+ device_mount_regex
201
+ else
202
+ device_fstab
203
+ end
204
+ end
205
+ end
206
+ end
207
+ end
208
+ end