最近在玩 Jupyter Notebook ,想用这个来写学习 Python 的笔记!打算通过 Supervisor 来管理 Jupyter Notebook ,再加上一个 Nginx 进行反向代理(略显无聊,纯粹为了好玩)。
结果现在卡在 Supervisor 管理 Jupyter Notebook 上了。废话少说,贴代码:
# 这分别是 supervisord 和 Jupyter 程序的配置
[supervisord]
logfile=/home/supervisord/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/home/supervisord/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)
;umask=022 ; (process file creation umask;default 022)
;user=chrism ; (default is current user, required if root)
;identifier=supervisor ; (supervisord identifier, default is 'supervisor')
;directory=/tmp ; (default is not to cd during start)
;nocleanup=true ; (don't clean up tempfiles at start;default false)
;childlogdir=/tmp ; ('AUTO' child log dir, default $TEMP)
;environment=KEY="value" ; (key value pairs to add to environment)
;strip_ansi=false ; (strip ansi escape codes in logs; def. false)
[program:jupyter-notebook]
user=xff
command=bash /home/xff/bin/start_notebook.sh
process_name=ipython_notebook
environment=HOME="/home/xff/"
numprocs=1
numprocs_start=3
direcotory=/home/xff/Documents
stdout_logfile=/home/supervisord/jupyter-notebook.log ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=10 ; # of stdout logfile backups (default 10)
stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
stdout_events_enabled=false ; emit events on stdout writes (default false)
stderr_logfile=/home/supervisord/jupyter-notebook.err ; stderr log path, NONE for none; default AUTO
stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
stderr_logfile_backups=10 ; # of stderr logfile backups (default 10)
stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
stderr_events_enabled=false ; emit events on stderr writes (default false)
stopsignal=KILL
stopwaitsecs=5
;autostart=true
;autorestart=true
# /home/xff/bin/start_notebook.sh 文件, Jupyter Notebook 的启动脚本
#!/bin/bash
NOTEBOOK_CMD="/home/xff/.virtualenvs/jupyter/bin/jupyter-notebook --config=/home/xff/.jupyter/jupyter_notebook_config.py"
echo $NOTEBOOK_CMD >> /home/xff/log
$NOTEBOOK_CMD
通过 supervisorctl 启动 Jupyter Notebook 后,进程树是这样的:
root 5004 0.0 1.3 207632 13264 ? Ss 16:51 0:00 /usr/local/Python-2.7.11/bin/python2.7 /usr/local/Python-2.7.11/bin/supervisord -c /etc/supervisord.conf --user=root
xff 5142 0.1 0.1 106100 1220 ? S 17:00 0:00 \_ bash /home/xff/bin/start_notebook.sh
xff 5143 7.8 3.4 286876 35104 ? S 17:00 0:00 \_ /home/xff/.virtualenvs/jupyter/bin/python2.7 /home/xff/.virtualenvs/jupyter/bin/jupyter-notebook --config=/home/xff/.jupyter/jupyter_notebook_config.py
在 supervisorctl 上停止 Jupyter Notebook 之后,进程树就变成这样了,
root 3196 0.0 0.1 42708 1836 ? Ss 15:33 0:00 nginx: master process nginx
www 3728 0.0 0.2 43124 2196 ? S 16:03 0:02 \_ nginx: worker process
www 3729 0.0 0.2 43124 2196 ? S 16:03 0:01 \_ nginx: worker process
root 5004 0.0 1.3 207784 13336 ? Ss 16:51 0:00 /usr/local/Python-2.7.11/bin/python2.7 /usr/local/Python-2.7.11/bin/supervisord -c /etc/supervisord.conf --user=root
xff 5143 0.2 3.4 286876 35104 ? S 17:00 0:00 /home/xff/.virtualenvs/jupyter/bin/python2.7 /home/xff/.virtualenvs/jupyter/bin/jupyter-notebook --config=/home/xff/.jupyter/jupyter_notebook_config.py
很明显, Jupyter Notebook 的进程并没有被停止,它变成了孤儿进程,被 Init 收养了。
我开始以为是 supervisor 发送的停止信号不对,后来吧 supervisor 配置文件中,程序的停止信号stopsignal
变成了kill
还是不行,但如果我在命令行中执行
# Jupyter Notebook 默认监听的是 8888 端口
kill -9 `lsof -ti:8888`
是可以的!
万能的 V 友们,给点提示吧,这是什么原因啊,从哪里入手解决呀!
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.