Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I redirect Output to STDOUT with Laravel Scheduler command?

I have my scheduler application running into a Docker container.

Laravel scheduler is managed and executed into the container with supervisor (I managed the output redirection by following http://veithen.github.io/2015/01/08/supervisord-redirecting-stdout.html):

[supervisord]
nodaemon = true
loglevel = info
stderr_logfile = /dev/stderr
stderr_logfile_maxbytes = 0
stdout_logfile = /dev/stdout
stdout_logfile_maxbytes = 0
umask = 022
pidfile = /tmp/supervisord.pid,
logfile = /tmp/supervisord.log

[program:scheduler]
directory = /var/www
command = sh -c 'php artisan schedule:run && sleep 60'
autorestart = true
redirect_stderr = true
stdout_logfile = /dev/stdout
stdout_logfile_maxbytes = 0
stderr_logfile = /dev/stderr
stderr_logfile_maxbytes = 0

Adjusted My Kernel.php code to append output to stdout_logfile:

 $fileCronLog = '/dev/stdout'; 
 $schedule->command('test')->everyMinute()->appendOutputTo($fileCronLog);

test command is simply dumping a string to STDOUT.

If I set my $fileCronLog to a local storage file Writes correctly to file $filepath my command output.

But with $fileCronLog = '/dev/stdout';

I cant see my log. I also tried to enter the container to look at this file and it's always empty.

like image 368
koalaok Avatar asked Oct 05 '17 13:10

koalaok


1 Answers

I possibly found a solution for my own question. This was the resource: https://github.com/moby/moby/issues/19616

By adding this line in the Dockerfile where supervisor will run:

 RUN ln -sf /proc/1/fd/1 /var/log/laravel-scheduler.log

And then in Laravel app/console/Kernel.php

$fileCronLog = '/var/log/laravel-scheduler.log'; 
$schedule->command('test')->everyMinute()->appendOutputTo($fileCronLog); 

This is making the difference:

/var/log/laravel-scheduler.log shouldn't be a symlink to /proc/self/fd/1,

but to /proc/1/fd/1.

"Subtle, but very significant difference."

like image 180
koalaok Avatar answered Oct 18 '22 09:10

koalaok