1

我有一个 PHP Deployer 任务来递归地更改部署路径中所有内容的文件所有者:

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

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

Operation not permittedDeployer 未能完成此任务,因为此 commond 给出了一些错误。很公平,因为这些文件无论如何都不需要更改。所以我添加2>&1 | grep -v 'Operation not permitted'以防止错误显示:

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

但是,当我运行它时,Deployer 仍然无法完成此任务:

➤ 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)

在这种情况下,有没有办法防止 Deployer 失败?

4

2 回答 2

0

我最终try catch在电话周围打了一个电话,所以 Deployer 将忽略并继续。

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'
        }
    });

尽管我仍然不明白为什么 Deployer 会抛出此错误,即使命令行没有输出任何内容。

于 2022-02-08T13:28:26.550 回答
0

您可以先在部署文件中添加一些指令:

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

或者和你的 webapp 用户一起做一个 chown。

检查您的虚拟主机/etc/apache2/sites-available/{your-webapp}.conf

检查目录中的 php-fpm 配置php{version}-fpm以设置您的 webapps 用户或特定 webapp 用户的权限:/etc/php/{version}/fpm/pool.d/{your-webapp-fpm}.conf

于 2022-02-08T12:11:24.560 回答