Capistrano not deleting old releases

Capistrano is not deleting the old releases. The deploy user (“deploy”) is a member of the group that owns the directories (“www”) and I have confirmed that the group owns and has write access to the entire releases tree.

This is the last part of the error output:

Tasks: TOP => deploy:cleanup
(See full trace by running task with --trace)
The deploy has failed with an error: #<SSHKit::Runner::ExecuteError: Exception while executing on host
[host fqdn]: rm exit status: 1
rm stdout: Nothing written
rm stderr: Nothing written

Can you try running that again with log level as debug? Usually Capistrano outsides the full command it’s running. The #1 rule to Cap debugging is to SSH onto your server and manually run the entire cmd and see what the output is.

I turned on debug. Here’s the command where it fails

INFOKeeping 5 of 6 deployed releases on stage.xxxxx.com
INFO[c23c04d4] Running /usr/bin/env rm -rf /var/www/xxxxx/releases/20141016213602 on stage.xxxxx.com
DEBUG[c23c04d4] Command: ( WP_ENV=staging /usr/bin/env rm -rf /var/www/xxxxx/releases/20141016213602 )
DEBUG[c23c04d4] 	rm: cannot remove ‘/var/www/xxxxx/releases/20141016213602/web/app/cache/config/master.php’
DEBUG[c23c04d4]  Permission denied

I confirmed that there is a permission issue:

drwxrwsr-x 3 deploy   www 4096 Oct 21 07:52 .  
drwxrwsr-x 3 deploy   www 4096 Oct 21 07:52 ..
drwxr-sr-x 2 www-data www 4096 Oct 16 17:36 config

The deploy user is a member of the www group, but this file doesn’t allow group+write.

You’ll need to get your permissions sorted so that the user deploying can perform each task Capistrano will run individually.

The problem seems to be with the W3 Total Cache plugin. The config/master.php file is created by the plugin and thus has the www-data:www ownership. I put the config folder path into the gitignore file to keep it in the deploy files. I checked the permissions after the latest deploy and the config directory is now owned by deploy:www so I should be able to rm -rf it when the cleanup runs again.

Thanks for the help.

To close the thread…

This worked! The ownership of the config folder is now deploy:www so capistrano can now delete the folder and keep releases to 5.