最新消息:20181230 VPS服务器已从Linode换到腾讯云香港,主题仍用朋友推荐的大前端D8

【已解决】supervisor去启动gunicorn的Flask出错:supervisor couldn’t setuid to 0 Can’t drop privilege as nonroot user

Flask crifan 396浏览 0评论

折腾:

【未解决】supervisord的普通stdout的log却输出到表示错误的stderr的log中

期间,对于之前的supervisor去管理gunicorn的flask,是好的。

但是加了点log方面的配置:

<code>
;2MB=2*1024*1024=2097152
stdout_logfile=/Users/crifan/dev/dev_root/company/naturling/projects/robotDemo/logs/supervisord_out.log
stdout_logfile_maxbytes=2097152
stdout_logfile_backups=10

stderr_logfile=/Users/crifan/dev/dev_root/company/naturling/projects/robotDemo/logs/supervisord_err.log
stderr_logfile_maxbytes=2097152
stderr_logfile_backups=10

redirect_stderr=true
</code>

结果运行:

<code>➜  robotDemo supervisorctl status all
robotDemo                        STARTING
➜  robotDemo supervisorctl status all
robotDemo                        RUNNING   pid 11132, uptime 0:00:00
➜  robotDemo which python
/usr/bin/python
➜  robotDemo supervisorctrl stop all
zsh: command not found: supervisorctrl
➜  robotDemo supervisorctl stop all
robotDemo: stopped
➜  robotDemo supervisorctl start all
robotDemo: started
➜  robotDemo supervisorctl status all
robotDemo                        STARTING
➜  robotDemo supervisorctl status all
robotDemo                        STARTING
➜  robotDemo supervisorctl status all
robotDemo                        STARTING
➜  robotDemo supervisorctl status all
robotDemo                        STARTING
➜  robotDemo supervisorctl status all
robotDemo                        STARTING
➜  robotDemo supervisorctl status all
robotDemo                        STARTING
</code>

出错了:

err中空了:

out中:

全是:

<code>supervisor: couldn't setuid to 0: Can't drop privilege as nonroot user
supervisor: child process was not spawned
supervisor: couldn't setuid to 0: Can't drop privilege as nonroot user
supervisor: child process was not spawned
</code>

去掉

redirect_stderr=true

试试

结果问题依旧:

另外和之前一样,去调用get接口时出错:

<code>org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:32851 [/127.0.0.1] failed: Connection refused (Connection refused)
</code>

难道是没有指定配置文件?

那为何其可以找得到我之前的app的名字呢?

去试试指定配置文件:

<code>➜  robotDemo supervisorctl -c supervisord.conf
robotDemo                        STOPPED   Apr 20 06:05 PM
supervisor&gt; ^D
➜  robotDemo supervisorctl -c supervisord.conf
robotDemo                        STOPPED   Apr 20 06:05 PM
supervisor&gt; ^D
➜  robotDemo supervisord -c supervisord.conf
Error: Another program is already listening on a port that one of our HTTP servers is configured to use.  Shut this program down first before starting supervisord.
For help, use /Users/crifan/Library/Python/2.7/bin/supervisord -h
➜  robotDemo supervisorctl stop all
➜  robotDemo supervisord -c supervisord.conf
Error: Another program is already listening on a port that one of our HTTP servers is configured to use.  Shut this program down first before starting supervisord.
For help, use /Users/crifan/Library/Python/2.7/bin/supervisord -h
</code>

supervisor: couldn’t setuid to 0: Can’t drop privilege as nonroot user

CRIT Can’t drop privilege as nonroot user · Issue #695 · Supervisor/supervisor

难道是之前给

supervisord.conf

加了配置:

<code>user=root
</code>

导致的?

supervisor的安装与配置 – CSDN博客

“*、不通过root启动

    修改用户

    [supervisord]

    user=user1    ; (default is current user, required if root)

    

    [supervisorctl]

    username=user1   ; should be same as http_username if set”

python – An Error about supervisor – Stack Overflow

Supervisord不能够启动进程的问题 – Liujianqiao Tech Talk

[Supervisor-users] CRIT Can’t drop privilege as nonroot user

<code>➜  robotDemo supervisord -n -edebug
Error: Another program is already listening on a port that one of our HTTP servers is configured to use.  Shut this program down first before starting supervisord.
For help, use /Users/crifan/Library/Python/2.7/bin/supervisord -h
</code>

supervisor – 直立行走的猿

去用sudo用户去停止掉supervisor

<code>➜  robotDemo sudo supervisorctl stop all
Password:
robotDemo: stopped
➜  robotDemo sudo supervisorctl status all
robotDemo                        STOPPED   Apr 23 09:06 AM
</code>

然后把之前自己加到:

supervisord.conf

中的user去掉:

然后再去(默认用当前用户去)启动:

<code>➜  robotDemo supervisorctl status all
robotDemo                        STARTING
➜  robotDemo supervisorctl status all
robotDemo                        RUNNING   pid 1041, uptime 0:00:00
➜  robotDemo supervisorctl status all
robotDemo                        STARTING
➜  robotDemo supervisorctl status all
robotDemo                        RUNNING   pid 1059, uptime 0:00:00
➜  robotDemo supervisorctl status all
robotDemo                        RUNNING   pid 1069, uptime 0:00:00
</code>

结果问题依旧。

【已解决】supervisord启动出错:Error Another program is already listening on a port that one of our HTTP servers is configured to use

再去停止掉,继续试试supervisorctl是否正常。

结果又提示:

<code>➜  robotDemo supervisorctl status all
unix:///tmp/supervisor.sock no such file
➜  robotDemo supervisorctl start all
unix:///tmp/supervisor.sock no such file
</code>

搜:

supervisorctl unix:///tmp/supervisor.sock no such file

supervisorctl报错unix:///tmp/supervisor.sock no s… – 简书

python – Supervisor – Can’t start supervisorctl as root or user (User is set in config) – Stack Overflow

去看看,是否存在此文件

<code>➜  robotDemo ll /tmp/supervisord.log
-rw-r--r--  1 crifan  wheel    19M  4 23 09:18 /tmp/supervisord.log
➜  robotDemo ll /tmp/supervisor*
-rw-r--r--  1 crifan  wheel    19M  4 23 09:18 /tmp/supervisord.log
</code>

只有一个log

没有这个sock文件

“unix:///tmp/supervisor.sock no such file” 错误处理 – CashQian Blog

此处不用去改,先去update,表示更新配置文件,试试如何

<code>➜  robotDemo supervisorctl update
</code>

error: <class ‘socket.error’>, [Errno 2] No such file or directory: file: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py line: 228

结果找不到socket

还是去换个路径吧

但是感觉随便换还是不太好。

解决unix:///tmp/supervisor.sock no such file的问题 – CSDN博客

嗯,去touch一下

<code>➜  robotDemo touch /tmp/supervisor.sock
➜  robotDemo ll /tmp/supervisor*
-rw-r--r--  1 crifan  wheel     0B  4 23 09:28 /tmp/supervisor.sock
-rw-r--r--  1 crifan  wheel    19M  4 23 09:18 /tmp/supervisord.log
➜  robotDemo rm /tmp/supervisord.log
➜  robotDemo ll /tmp/supervisor*
-rw-r--r--  1 crifan  wheel     0B  4 23 09:28 /tmp/supervisor.sock
</code>

然后再去运行看看

结果又提示,不是socket文件:

<code>➜  robotDemo supervisorctl status all
error: &lt;class 'socket.error'&gt;, [Errno 38] Socket operation on non-socket: file: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py line: 228
</code>

刚发现此处一个小问题:

配置文件中,没看到之前就有:

[supervisord]

后面自己加了:

[supervisord]

所以去掉最后的,使用前面的。

另外参考:

http://www.cashqian.net/blog/001472975510127673ea63db9234c4e8293cf43cefcafde000

去改为:

把所有的

/tmp/

都改为

/var/run/

<code>[unix_http_server]
;file=/tmp/supervisor.sock   ; the path to the socket file
file=/var/run/supervisor.sock   ; the path to the socket file
chmod=0766                 ; socket file mode (default 0700)
;chown=nobody:nogroup       ; socket file uid:gid owner
;username=user              ; default is no username (open server)
;password=123               ; default is no password (open server)

;[inet_http_server]         ; inet (TCP) server disabled by default
;port=127.0.0.1:9001        ; ip_address:port specifier, *:port for all iface
;username=user              ; default is no username (open server)
;password=123               ; default is no password (open server)

[supervisord]
;logfile=/tmp/supervisord.log ; main log file; default $CWD/supervisord.log
logfile=/var/run/supervisord.log ; main log file; default $CWD/supervisord.log
logfile_maxbytes=50MB        ; max main logfile bytes b4 rotation; default 50MB
logfile_backups=10           ; # of main logfile backups; 0 means none, default 10
loglevel=info                ; log level; default info; others: debug,warn,trace
;pidfile=/tmp/supervisord.pid ; supervisord pidfile; default supervisord.pid
pidfile=/var/run/supervisord.pid ; supervisord pidfile; default supervisord.pid

[supervisorctl]
;serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket
;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
;username=chris              ; should be same as in [*_http_server] if set
;password=123                ; should be same as in [*_http_server] if set
;prompt=mysupervisor         ; cmd line prompt (default "supervisor")
;history_file=~/.sc_history  ; use readline history if available
</code>

然后更新一下配置文件,结果还是报错:

<code>➜  robotDemo supervisorctl update
error: &lt;class 'socket.error'&gt;, [Errno 2] No such file or directory: file: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py line: 228
</code>

supervisorctl error: <class ‘socket.error’>, [Errno 2] No such file or directory

“supervisorctl reload” fails to re-start program · Issue #121 · Supervisor/supervisor

<code>➜  robotDemo supervisorctl reload
error: &lt;class 'socket.error'&gt;, [Errno 2] No such file or directory: file: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py line: 228
</code>

解决 supevisor 提示 socket error 错误

然后去新建,给权限,弄了一半,算了放弃吧:

<code>➜  robotDemo supervisord -c supervisord.conf
Traceback (most recent call last):
  File "/Users/crifan/Library/Python/2.7/bin/supervisord", line 11, in &lt;module&gt;
    sys.exit(main())
  File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/supervisor/supervisord.py", line 357, in main
    go(options)
  File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/supervisor/supervisord.py", line 367, in go
    d.main()
  File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/supervisor/supervisord.py", line 71, in main
    self.options.make_logger()
  File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/supervisor/options.py", line 1423, in make_logger
    stdout = self.nodaemon,
  File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/supervisor/loggers.py", line 346, in getLogger
    handlers.append(RotatingFileHandler(filename,'a',maxbytes,backups))
  File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/supervisor/loggers.py", line 172, in __init__
    FileHandler.__init__(self, filename, mode)
  File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/supervisor/loggers.py", line 98, in __init__
    self.stream = open(filename, mode)
IOError: [Errno 13] Permission denied: '/var/run/supervisord.log'
➜  robotDemo ll /var/run/supervisor*
ls: /var/run/supervisor*: No such file or directory
➜  robotDemo touch /var/run/supervisord.log
touch: /var/run/supervisord.log: Permission denied
➜  robotDemo sudo touch /var/run/supervisord.log
Password:
➜  robotDemo ll /var/run/supervisor*
-rw-r--r--  1 root  daemon     0B  4 23 09:42 /var/run/supervisord.log
➜  robotDemo sudo chown crifan:wheel /var/run/supervisord.log
➜  robotDemo ll /var/run/supervisor*
-rw-r--r--  1 crifan  wheel     0B  4 23 09:42 /var/run/supervisord.log
➜  robotDemo supervisord -c supervisord.conf
Error: Cannot open an HTTP server: socket.error reported errno.EACCES (13)
For help, use /Users/crifan/Library/Python/2.7/bin/supervisord -h
➜  robotDemo touch /var/run/supervisor.sock
touch: /var/run/supervisor.sock: Permission denied
➜  robotDemo sudo touch /var/run/supervisor.sock
➜  robotDemo sudo touch /var/run/supervisord.log
➜  robotDemo sudo touch /var/run/supervisord.pid
➜  robotDemo sudo chown crifan:wheel /var/run/supervisor*
➜  robotDemo ll /var/run/supervisor*
-rw-r--r--  1 crifan  wheel     0B  4 23 09:44 /var/run/supervisor.sock
-rw-r--r--  1 crifan  wheel     0B  4 23 09:47 /var/run/supervisord.log
-rw-r--r--  1 crifan  wheel     0B  4 23 09:47 /var/run/supervisord.pid
➜  robotDemo supervisord -c supervisord.conf
Error: Cannot open an HTTP server: socket.error reported errno.EACCES (13)
For help, use /Users/crifan/Library/Python/2.7/bin/supervisord -h
➜  robotDemo ll
total 80
-rw-r--r--  1 crifan  staff   212B  4 20 10:15 Pipfile
-rw-r--r--  1 crifan  staff   7.8K  4 20 10:16 Pipfile.lock
drwxr-xr-x  3 crifan  staff    96B  4 20 16:55 __pycache__
-rw-r--r--  1 crifan  staff   8.3K  4 20 13:46 app.py
-rw-r--r--  1 crifan  staff   1.6K  4 20 13:45 gunicorn_config.py
drwxr-xr-x  7 crifan  staff   224B  4 23 09:17 logs
-rw-r--r--  1 crifan  staff   9.8K  4 23 09:36 supervisord.conf
➜  robotDemo sudo chown crifan:staff /var/run/supervisor*
➜  robotDemo ll /var/run/supervisor*
-rw-r--r--  1 crifan  staff     0B  4 23 09:44 /var/run/supervisor.sock
-rw-r--r--  1 crifan  staff     0B  4 23 09:47 /var/run/supervisord.log
-rw-r--r--  1 crifan  staff     0B  4 23 09:47 /var/run/supervisord.pid
➜  robotDemo supervisord -c supervisord.conf
Error: Cannot open an HTTP server: socket.error reported errno.EACCES (13)
For help, use /Users/crifan/Library/Python/2.7/bin/supervisord -h
</code>

 

supervisord Error: Cannot open an HTTP server: socket.error reported errno.EACCES (13)

web:supervisor 安装 – CSDN博客

<code>➜  robotDemo sudo chmod 777 /var/run
➜  robotDemo supervisord -c supervisord.conf
Unlinking stale socket /var/run/supervisor.sock
➜  robotDemo ps -ef | grep supervisor
  501  1788     1   0  9:50上午 ??         0:00.03 /usr/bin/python /Users/crifan/Library/Python/2.7/bin/supervisord -c supervisord.conf
  501  1825  4796   0  9:51上午 ttys007    0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn supervisor
➜  robotDemo kill -9 1788
➜  robotDemo ps -ef | grep supervisor
  501  1836  4796   0  9:51上午 ttys007    0:00.01 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn supervisor
➜  robotDemo kill -9 1836
kill: kill 1836 failed: no such process
➜  robotDemo supervisord -c supervisord.conf
Unlinking stale socket /var/run/supervisor.sock
</code>

再去搜:

supervisord Unlinking stale socket /var/run/supervisor.sock

supervisord安装使用简记 – wswang – 博客园

Stopping supervisord: Shut down – Stack Overflow

Supervisor进程管理工具 – 简书

然后发现:

此处虽然显示出:

<code>➜  robotDemo supervisord -c supervisord.conf
Unlinking stale socket /var/run/supervisor.sock
</code>

但是实际上是已经正常运行了

所以再去运行就提示:

<code>➜  robotDemo supervisord -c supervisord.conf
Error: Another program is already listening on a port that one of our HTTP servers is configured to use.  Shut this program down first before starting supervisord.
For help, use /Users/crifan/Library/Python/2.7/bin/supervisord -h
</code>

以及去测试自己的Flask接口,也是OK的了,也可以看到对应的log:

【总结】

此处,最终是去修改配置文件:

supervisord.conf

把:

/tmp/

都改为

/var/run/

变成:

<code>[unix_http_server]
;file=/tmp/supervisor.sock   ; the path to the socket file
file=/var/run/supervisor.sock   ; the path to the socket file
chmod=0766                 ; socket file mode (default 0700)

</code>

[supervisord]

;logfile=/tmp/supervisord.log ; main log file; default $CWD/supervisord.log

logfile=/var/run/supervisord.log ; main log file; default $CWD/supervisord.log

logfile_maxbytes=50MB        ; max main logfile bytes b4 rotation; default 50MB

logfile_backups=10           ; # of main logfile backups; 0 means none, default 10

loglevel=info                ; log level; default info; others: debug,warn,trace

;pidfile=/tmp/supervisord.pid ; supervisord pidfile; default supervisord.pid

pidfile=/var/run/supervisord.pid ; supervisord pidfile; default supervisord.pid

[supervisorctl]

;serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket

serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket

然后再去对应的文件夹中创建对应文件,且更改为当前用的权限:

<code>➜  robotDemo sudo touch /var/run/supervisor.sock
➜  robotDemo sudo touch /var/run/supervisord.log
➜  robotDemo sudo touch /var/run/supervisord.pid
➜  robotDemo sudo chown crifan:staff /var/run/supervisor*
➜  robotDemo ll /var/run/supervisor*
-rw-r--r--  1 crifan  staff     0B  4 23 09:44 /var/run/supervisor.sock
-rw-r--r--  1 crifan  staff     0B  4 23 09:47 /var/run/supervisord.log
-rw-r--r--  1 crifan  staff     0B  4 23 09:47 /var/run/supervisord.pid
</code>

其中crifan:staff是参考:

<code>➜  robotDemo ll
total 80
-rw-r--r--  1 crifan  staff   212B  4 20 10:15 Pipfile
-rw-r--r--  1 crifan  staff   7.8K  4 20 10:16 Pipfile.lock
drwxr-xr-x  3 crifan  staff    96B  4 20 16:55 __pycache__
-rw-r--r--  1 crifan  staff   8.3K  4 20 13:46 app.py
-rw-r--r--  1 crifan  staff   1.6K  4 20 13:45 gunicorn_config.py
drwxr-xr-x  7 crifan  staff   224B  4 23 09:17 logs
-rw-r--r--  1 crifan  staff   9.8K  4 23 09:36 supervisord.conf
</code>

看到的。

以及再去给此处的/var/run允许当前用户访问的权限:

<code>➜  robotDemo sudo chmod 777 /var/run
</code>

最终才能正常运行supervisord:

<code>➜  robotDemo supervisord -c supervisord.conf
Unlinking stale socket /var/run/supervisor.sock
</code>

注意:

此处输出:

Unlinking stale socket /var/run/supervisor.sock

不是错误 -》实践上supervisord已经正常运行了。

-〉后来发现是:

其实log已经都输出到:

supervisord.conf

中配置的:

<code>[supervisord]
logfile=/Users/crifan/dev/dev_root/company/naturling/projects/robotDemo/logs/supervisord.log
</code>

中了:

转载请注明:在路上 » 【已解决】supervisor去启动gunicorn的Flask出错:supervisor couldn’t setuid to 0 Can’t drop privilege as nonroot user

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
57 queries in 0.086 seconds, using 10.03MB memory