以非root用户身份执行gunicron,但是python说它是root用户

时间:2016-05-13 03:02:38

标签: django root gunicorn supervisor

所以在top

PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND    
11329 gunicor+  20   0  177236  51472   7888 S  0.0  8.5   0:00.49 gunicorn                                                    
11326 gunicor+  20   0  164408  44456   7392 S  0.0  7.4   0:00.40 gunicorn                                                    
11318 gunicor+  20   0   56428  16960   6368 S  0.0  2.8   0:00.14 gunicorn                                                    
16735 root      20   0   60952   9044   3972 S  0.0  1.5   7:27.77 supervisord    

我们可以看到gunicorn由用户gunicorn_user运行。

但是在python代码中

# Below prints gunicorn_user
import commands
commands.getoutput("echo $(whoami)") 
>>> gunicorn_user

# This reports root
import getpass
getpass.getuser()
>>> root

当我引用〜/ .file时,此文件将转到root,但我需要gunicorn_user

为什么会出现不一致?我该如何解决,以便~/引用/home/gunicorn_user/

附加我的主管配置

[program:app] command=/webapp/bin/gunicorn_start user=gunicorn_user autostart=true autorestart=true redirect_stderr=true

我的gunicorn_start文件

exec gunicorn \ --name $NAME \ --workers $NUM_WORKERS \ --max-requests $MAX_REQUESTS \ --timeout 30 \ --user gunicorn_user --group webapp \ --log-level debug \ --bind unix:$SOCKFILE \ app.wsgi

0 个答案:

没有答案