Celery - Permission Problem - Create folder

China☆狼群 提交于 2019-12-13 03:57:14

问题


I use celery (jobs manager) on prod mode for a website (Django) on a centos7 server.

My problem is that in a celery task my function did not create folder (see my_function).

the function

def my_fucntion():

    parent_folder = THE_PARENT_PATH

    if not os.path.exists(centrifuge_recentrifuge_work_dir_path):
        os.makedirs(centrifuge_recentrifuge_work_dir_path)
    # The folder THE_PARENT_PATH is created

    celery_task(parent_folder)

the celery task

@app.task(name='a task')
def celery_task(parent_folder):
    import getpass; print("permission : ", getpass.getuser())
    # permission : apache

    path_1 = os.path.join(parent_folder, "toto")

    if not os.path.exists(path_1):
        os.makedirs(path_1)
    # The folder path_1 is NOT created
    ..... some others instructions...
    # Singularity image run (needed the path_1 folder)

I use Supervisord for daemonization of celery.

 celery.init

[program:sitecelery]
command=/etc/supervisord.d/celery.sh
directory=/mnt/site/
user=apache
numprocs=1
stdout_logfile=/var/log/celery/worker.log
stderr_logfile=/var/log/celery/worker.log
autostart=true
autorestart=true
priority=999

The folder path_1 is created when user=root but i want that it was not rot but apache user.

celery.sh

#!/bin/bash
cd /mnt/site/

exec ../myenv/bin/python3 -m celery -A site.celery_settings worker -l info --autoscale 20

sudo systemctl status supervisord

● supervisord.service - Process Monitoring and Control Daemon
   Loaded: loaded (/usr/lib/systemd/system/supervisord.service; disabled; vendor preset: disabled)
   Active: active (running) since lun. 2018-10-15 09:09:05 CEST; 4min 59s ago
  Process: 61477 ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf (code=exited, status=0/SUCCESS)
 Main PID: 61480 (supervisord)
   CGroup: /system.slice/supervisord.service
           ├─61480 /usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf
           └─61491 ../myenv/bin/python3 -m celery -A Site_CNR.celery_settings worker -l info --autoscale 20

oct. 15 09:09:05 web01 systemd[1]: Starting Process Monitoring and Control Daemon...
oct. 15 09:09:05 web01 systemd[1]: Started Process Monitoring and Control Daemon.
oct. 15 09:09:17 web01 Singularity[61669]: action-suid (U=48,P=61669)> Home directory is not owned by calling user: /usr/share/httpd
oct. 15 09:09:17 web01 Singularity[61669]: action-suid (U=48,P=61669)> Retval = 255
oct. 15 09:09:17 web01 Singularity[61678]: action-suid (U=48,P=61678)> Home directory is not owned by calling user: /usr/share/httpd
oct. 15 09:09:17 web01 Singularity[61678]: action-suid (U=48,P=61678)> Retval = 255

EDIT 1 os.makedirs

In the celery tasks :

if not os.path.exists(path_1):
    print("test")
    # test
    print(os.makedirs(path_1))
    # None
    os.makedirs(path_1)

The os.makedirs return None :/


回答1:


I dont know why but with this correction on a post error of this problem with a sudo chown -R apache:apache /usr/share/httpd/ resolve this problem oO



来源:https://stackoverflow.com/questions/52812152/celery-permission-problem-create-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!