django - Celery - 权限问题 - 创建文件夹
问题描述
我celery
在 centos7 服务器上的网站(Django)的 prod 模式下使用(作业管理器)。
我的问题是,在 celery 任务中,我的函数没有创建文件夹(请参阅 参考资料my_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)
芹菜任务
@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)
我使用 Supervisord 对 celery 进行守护进程。
芹菜初始化
[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
该文件夹path_1
是在何时创建的,user=root
但我希望它不是腐烂的,而是 apache 用户。
芹菜.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
编辑 1 os.makedirs
在芹菜任务中:
if not os.path.exists(path_1):
print("test")
# test
print(os.makedirs(path_1))
# None
os.makedirs(path_1)
os.makedirs
回报:None
/
解决方案
我不知道为什么,但是通过对这个问题的发布错误的更正,sudo chown -R apache:apache /usr/share/httpd/
解决了这个问题 oO
推荐阅读
- regex - 单击赛普拉斯中的完全匹配文本
- reactjs - 多个输入上的单个模糊事件
- python - 将字典转换为 Python 数据框
- xamarin - 如何为 RelativeLayout ConstraintExpression 编写 OnPlatform 代码
- java - 确保模拟调用时条件返回 false
- css - 如何简化引导菜单?
- javascript - 使用 Puppeteer 重新加载 Jest 后检查页面内容
- c# - asp.net css 在我的本地机器和远程机器上是不同的
- java - MediaCodec和MediaExtractor的理解
- javascript - 多维数组如何对列的值求和?