Supervisor 无法停止 Jupyter Notebook - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
bwangel
V2EX    Jupyter

Supervisor 无法停止 Jupyter Notebook

  •  
  •   bwangel 2016-03-31 22:09:26 +08:00 9011 次点击
    这是一个创建于 3533 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近在玩 Jupyter Notebook ,想用这个来写学习 Python 的笔记!打算通过 Supervisor 来管理 Jupyter Notebook ,再加上一个 Nginx 进行反向代理(略显无聊,纯粹为了好玩)。

    结果在卡在 Supervisor 管理 Jupyter Notebook 上了。废话少说,贴代码:

    相关配置

    Supervisor 的配置

    # 这分别是 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 

    Jupyter Notebook 的启动脚本

    # /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 友们,给点提示吧,这是什么原因啊,从哪里入手解决呀!

    5 条回复    2016-04-01 07:32:56 +08:00
    bwangel
        1
    bwangel  
    OP
       2016-03-31 23:03:09 +08:00
    刚刚配置好了 Nginx 对 Jupyter Notebook 的反向代理, Nginx 还需要设置上对于 WebSocket 的支持( Jupyter Notebook 的 Python Notebook 还用到了 WebSocket 。。)。

    我在朋友的帮助下,找到了这篇文章 https://www.nginx.com/blog/websocket-nginx/,解决了 WebSocket 的配置。

    还有这个文章 http://www.jianshu.com/p/4ecdc166f968 ,是我的一点小笔记。。
    bwangel
        2
    bwangel  
    OP
       2016-03-31 23:03:28 +08:00
    不过 Supervisor 的问题还是没有解决。。
    bwangel
        3
    bwangel  
    OP
       2016-03-31 23:04:20 +08:00
    @bwangel 坑爹啊,文件链接错误。。

    参考文章是这个:

    https://www.nginx.com/blog/websocket-nginx/
    fcicq
        4
    fcicq  
       2016-04-01 02:32:49 +08:00   1
    bash 里面用 exec 来替换 shell 进程. 也就是你脚本最后一句应该是 exec $NOTEBOOK_CMD. 楼主如果用 runit 来抄脚本的话就不会错了.
    bwangel
        5
    bwangel  
    OP
       2016-04-01 07:32:56 +08:00
    @fcicq 好吧,懂了!

    原来只是停止了 Bash 进程, Jupyter 没有被停止,成了孤儿进程,被收养了。。

    谢谢谢谢,这么久解决了,你这么一说,突然秒懂了!
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     5062 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 36ms UTC 08:19 PVG 16:19 LAX 00:19 JFK 03:19
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86