laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.51k stars 11.02k forks source link

[Question] Task schedule not working when specific user as crontab #25452

Closed keepchen closed 6 years ago

keepchen commented 6 years ago

Description:

When I use crontab to run laravel task schedule (as default user: root),everything works fine. However,When I specific www-data user as

crontab -e -u www-data

and configure task command

* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1

it doesn't work. I try to configure single task schedule such as

* * * * * php /path/to/artisan send_email >> /var/log/project/send_email.log

It also can be execute.

Steps To Reproduce:

1.open crontab as specific user crontab -e -u www-data 2.configure task schedule command * * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1

mfn commented 6 years ago
          • php /path/to/artisan schedule:run >> /dev/null 2>&1

Start by redirected to a file you can actually look at, there may be output indicating the problem, like so: * * * * * php /path/to/artisan schedule:run >> /tmp/debug_insecure.log 2>&1

You can also try:

keepchen commented 6 years ago

@mfn Thanks. I use an absolute path /usr/bin/php and redirect to a file /tmp/debug_task.log. tailf /tmp/debug_task.log and this is log below:

Running scheduled command: '/usr/bin/php7.0' 'artisan' send_verify_code >> '/var/disk/log/sms_log/sms_2018-09-05.log' 2>&1
Running scheduled command: '/usr/bin/php7.0' 'artisan' register_push_user >> '/var/disk/log/message/register_user_2018-09-05.log' 2>&1
Running scheduled command: '/usr/bin/php7.0' 'artisan' sync_info >> '/var/disk/log/live/sync_info_2018-09-05.log' 2>&1

But

None Task be called actually

sisve commented 6 years ago

Can you issue the command yourself using sudo -u www-data -- /usr/bin/php7.0 artisan ...? It does sound like a permission issue.

keepchen commented 6 years ago

@sisve Thank you for your advice. I also thought about whether it is really a permission issue, so I tried to start it manually with the same user rights, the task can be executed normally.

sudo -u www-data php /path/to/artisan schedule:run

It is strange to put it in the crontab, so I am confused.

laurencei commented 6 years ago

Hi there,

Welcome to Laravel and we are glad to have you as part of the community.

Unfortunately this GitHub area is not a support area for general application issues. This is only for issues/bugs with the framework code itself.

I will be closing your ticket here. Instead please try asking your question on one of the many great community support areas that will likely give you a better answer more quickly:

If you feel I've closed this issue in error, please provide more information about how this is a framework issue, and I'll reopen the ticket.

Thanks in advance.