Question

I want to have new instances use an S3 bucket for uploaded files/images. I am using s3fs and the target folder is mounted on the instance. I would like to:

1- Delete the /srv/www/myapp/current/public/system (which is currently pointing to shared/public/system)

2- Link /srv/www/myapp/current/public/system to /s3mounted/bucket/public/system

So all instances point to the same shared and permanent s3 location.

the link is owned by www-data, i tried to manually sudo su and rm and didn't work. My question is, if i were to do this in a chef recipe as a deploy hook (before_restart.rb) how can i get this link deleted so i can point to a different location.

Was it helpful?

Solution

In your current before_restart.rb do the following :

current_release = release_path
deploy_node = node

deploy_resource = new_resource
deploy_to = deploy_resource.deploy_to
app_name = deploy_to.split('/')[-1]

deploy_user = deploy_node[:deploy][app_name][:user]
deploy_group = deploy_node[:deploy][app_name][:group]

link "#{current_release}/public/system" do
  to "/s3mounted/bucket/public/system"
  owner deploy_user
  group deploy_group
end

The first part setups the variables I use . If you use something like deploy[] you can end up getting the machines into a deploy loop.

This essentially does the removal of the file for you. When you symlink it automatically does the delete for you.

OTHER TIPS

Apache process had the files/folder locked. It was not a permissions issue. I had to stop apache, then "sudo rm" then i was able to link to new location and restart apache and all worked well.

This may not be the best solution and would love to hear other thoughts on how to do this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top