在特使脚本控制台命令中引发错误

时间:2019-09-10 15:48:49

标签: laravel-envoy

使用laravel 5.8 envoy命令,我将更改部署在服务器上,并且需要运行一些控制台命令,我的脚本 我遇到错误

Could not open input file: artisan

在第二个控制台命令上

在我的脚本中:

@task( 'update_symlinks' )
ln -nfs {{ $release_number_dir }} {{ $current_dir }};

@foreach($writableDirs as $file)
    chmod -R 777 {{ $release_number_dir }}/{{ $file }}

    chown -R {{ $server_login_user }}:www-data {{ $release_number_dir }}/{{ $file }}

@endforeach

cd {{ $release_number_dir }}

php artisan envoy:write-app-version app_version  // THAT WORKS OK

@endtask



@task('clean_old_releases')

php artisan envoy:delete-old-versions  Hostels2Deployed  // BUT THAT raise error

@endtask

@macro('Hostels2Deploy',['on'=>'dev'])
    ...
    update_symlinks
    clean_old_releases
@endmacro

envoy:删除app / Console / Commands / envoyDeleteoldVersions.php中定义的旧版本:

<?php

namespace App\Console\Commands;

use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
use Illuminate\Console\Command;

class envoyDeleteoldVersions extends Command
{
    protected $signature = 'envoy:delete-old-versions {directory_to_clear}';

    protected $description = 'Command description';

    public function __construct()
    {
        parent::__construct();
    }

    public function handle()     
    {       // php artisan envoy:delete-old-versions  "/_wwwroot/lar/Hostels2/storage/app/public/hostels"

        $arguments = $this->arguments();
        if ( !empty($arguments['directory_to_clear']) ) {
            $directory_name = $arguments['directory_to_clear'];
        }
        $directoriesList = File::directories($directory_name);

        $sortedDirectories = collect($directoriesList)
            ->sortBy(function ($dir) {
                return filemtime( $dir );
            })
        echo '<pre>+++ 222 $sortedDirectories::'.print_r($sortedDirectories,true).'</pre>';
        die("-1 XXZ");
    }
}

为什么出错以及如何解决?

1 个答案:

答案 0 :(得分:0)

我发现必须首先选择应用程序根目录:

@task('clean_old_releases')     cd {{$ release_number_dir}}

php artisan envoy:delete-old-versions  Hostels2Deployed