今天早上我升级了我的PHP版本到7.1,并且在cron试图运行php /var/www/html/artisan schedule:run时看到一个问题php /var/www/html/artisan schedule:run (一个简单的PHP命令)我看到输出:
3/3/2017 10:39:00 AMcrond: can't set groups: Operation not permitted 3/3/2017 10:39:00 AMcrond: USER www-data pid 1562 cmd php /var/www/html/artisan schedule:run 3/3/2017 10:40:00 AMcrond: can't set groups: Operation not permitted 3/3/2017 10:40:00 AMcrond: USER www-data pid 1563 cmd php /var/www/html/artisan schedule:run 3/3/2017 10:41:00 AMcrond: can't set groups: Operation not permitted 3/3/2017 10:41:00 AMcrond: USER www-data pid 1564 cmd php /var/www/html/artisan schedule:run 3/3/2017 10:42:00 AMcrond: can't set groups: Operation not permitted 3/3/2017 10:42:00 AMcrond: USER www-data pid 1565 cmd php /var/www/html/artisan schedule:run 3/3/2017 10:43:00 AMcrond: can't set groups: Operation not permitted 3/3/2017 10:43:00 AMcrond: USER www-data pid 1566 cmd php /var/www/html/artisan schedule:run
正在运行的命令是Laravel工匠命令。 它每分钟运行一次,允许在应用程序本身内完成其他预定的工作。 这个命令没有写入任何文件或类似的东西。 预定的工作会谈到一个数据库,并发送一些电子邮件。 应用程序日志被发送到stdout,因为它是一个Docker容器。
cron使用命令crond -f -d 8在一个容器中运行。 这里是Dockerfile:
# This container should be used for any/all CLI processes # including cron, queues, etc. FROM php:7.1-alpine # Copy the application files to the container ADD . /var/www/html WORKDIR /var/www/html # fix permissions in CI RUN sed -ri 's/^www-data:x:82:82:/www-data:x:1000:1000:/' /etc/passwd \ && sed -ri 's/^www-data:x:82:/www-data:x:1000:/' /etc/group # Install Composer dependencies RUN apk add --update --no-cache git zip unzip \ # needed for spatie/laravel-backup mysql-client \ # needed for gd libpng-dev libjpeg-turbo-dev \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* RUN docker-php-ext-install pdo_mysql gd \ # needed for forking processes in laravel queues as of Laravel 5.3 pcntl # Ownership of the app dir for www-data RUN chown -R www-data:www-data /var/www/html /home/www-data/ # Put php artisan schedule:run in a crontab RUN echo "* * * * * php /var/www/html/artisan schedule:run" > /etc/crontabs/www-data # Make sure when users get into the container they aren't root USER www-data
我已经排除了php artisan schedule:run是原因,因为我可以手动运行,一切都很好。 这意味着它是在cron内的东西。
什么是cron做的下可能会导致这个错误?
这是因为根据man 2 setgroups这两个条件之一
EPERM The calling process has insufficient privilege (the caller does not have the CAP_SETGID capability in the user namespace in which it resides). EPERM (since Linux 3.19) The use of setgroups() is denied in this user namespace. See the description of /proc/[pid]/setgroups in user_namespaces(7).
我想象你没有使用用户命名空间,在这种情况下,docker容器中不允许使用CAP_SETGIDfunction。 您将需要更改容器function集来修复它。
你正在运行cron,只是让这个命令在后台运行:
RUN echo "* * * * * php /var/www/html/artisan schedule:run" > /etc/crontabs/www-data
用creplacecron应该让你/不要/增加容器大小写:
artisan_schedule_run: image: your-app-image command: /dumb-init /bin/sh -c "while true; do su www-data -c \"php /var/www/html/artisan schedule:run\" & sleep 60; done"