the resource_directory
has only 2 actions available: create
and delete
I need to update the owner and group of a directory recursively.
How do I do that?
using a simple resource_execute
?
execute "chown-data-www" do
command "chown -R www-data:www-data /var/www/myfoler"
user "root"
action :run
end
The easiest way to use the chown recursive command is to execute “chown” with the “-R” option for recursive and specify the new owner and the folders that you want to change.
You can change permissions of files using numeric or symbolic mode with the chmod command. Use the chmod command with the R (recursive) option to work on all directories and files under a given directory. The permissions of a file can be changed only with the user with sudo priviledges, or the file owner.
It is common to use the basic chmod command to change the permission of a single file. However, you may need to modify the permission recursively for all files within a directory. In such cases, the chmod recursive option ( -R or --recursive ) sets the permission for a directory (and the files it contains).
Changing permissions with chmod To modify the permission flags on existing files and directories, use the chmod command ("change mode"). It can be used for individual files or it can be run recursively with the -R option to change permissions for all of the subdirectories and files within a directory.
You can set the default action to nothing then have resources that may screw things up notify the perm fixer:
execute "chown-data-www" do
command "chown -R www-data:www-data /var/www/myfoler"
user "root"
action :nothing
end
resource "that may screw up perms" do
stuff "one two three"
notifies :run, execute "chown-data-www"
end
with more options you could have the action :run but not if the parent folder is already the correct perms. You could alter this to include a deeper/problem file/directory, or with a find command similar to this
execute "chown-data-www" do
command "chown -R www-data:www-data /var/www/myfoler"
user "root"
action :run
not_if '[ $(stat -c %U /var/www/myfolder) = "www-data" ]'
end
Edit: fix to reflect comment below
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With