1

I have a PHP Deployer task to recursively change file owner of everything in the deploy path:

task('set_owner', function () { 
        run("chown -R someuser:www-data {{deploy_path}}");
    });

after('deploy:failed', 'deploy:unlock'); // Unlock after failed deploy

Deployer failed on this task since there are some Operation not permitted errors given by this commond. Fair enough, since those files don't need changing anyway. So I add 2>&1 | grep -v 'Operation not permitted' to prevent the errors from showing:

task('set_owner', function () {
        run("chown -R deployer:www-data {{deploy_path}} 2>&1 | grep -v 'Operation not permitted'");
    });

after('deploy:failed', 'deploy:unlock'); // Unlock after failed deploy

However when I run it Deployer still fails on this task:

➤ Executing task set_owner
[myapp.com] > chown -R someuser:www-data /var/www/myapp.com 2>&1 | grep -v 'Operation not permitted'
➤ Executing task deploy:failed
• done on [myapp.com]
✔ Ok [1ms]
➤ Executing task deploy:unlock
[myapp.com] > rm -f /var/www/myapp.com/.dep/deploy.lock
• done on [myapp.com]
✔ Ok [1s 364ms]
In Client.php line 103:
                                                                               
  [Deployer\Exception\RuntimeException (1)]                                    
  The command "chown -R someuser:www-data /var/www/myapp.com 2>&  
  1 | grep -v 'Operation not permitted'" failed.                               
                                                                               
  Exit Code: 1 (General error)

Is there a way to prevent Deployer from failing in this case?

Arno van Oordt
  • 2,912
  • 5
  • 33
  • 63

2 Answers2

0

You can add some directives first to your deployment file :

set('writable_mode', 'chmod');
set('writable_chmod_mode', '0755');

Or make a chown with your webapp user.

Check your vhost in /etc/apache2/sites-available/{your-webapp}.conf.

Check your php-fpm config in php{version}-fpm directory to set the rights to your webapps user or a specific webapp user : /etc/php/{version}/fpm/pool.d/{your-webapp-fpm}.conf.

BendaThierry.com
  • 2,080
  • 1
  • 15
  • 17
0

I ended up putting a try catch around the call so Deployer will just ignore and continue.

task('set_owner', function () {
        try {
            run("chown -R someuser:www-data {{deploy_path}} 2>&1 | grep -v 'Operation not permitted'");
        }
        catch(\Deployer\Exception\RuntimeException $e) {
            // For some reason a RuntimeException is triggered afeter executing the command even with 2>&1 | grep -v 'Operation not permitted'
        }
    });

Although I still don't get why Deployer throws this error even though the command line doesn't output anything.

Arno van Oordt
  • 2,912
  • 5
  • 33
  • 63