使用 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:delete-old-versions 在 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");
}
}
为什么会出错以及如何解决?