而不是使用屏幕,也许您可以切换到一个 init 脚本或supervisord来保持 IPython notebook 正常运行。
假设你走 supervisord 路线:
安装supervisord
使用你的包管理器安装 supervisord。对于 ubuntu,它被命名为supervisor
.
apt-get install supervisor
如果你决定通过 pip 安装 supervisor,你必须自己设置它的 init.d 脚本。
为 IPython 编写主管配置文件
配置文件告诉主管要运行什么以及如何运行。
安装 supervisor 后,它应该已经创建了/etc/supervisor/supervisord.conf
. 这些行应该存在于文件中:
[include]
files = /etc/supervisor/conf.d/*.conf
如果它们包含这些线条,则说明您的状态良好。我只向他们展示它需要新配置文件的位置。你的配置文件可以去那里,命名为/etc/supervisor/conf.d/ipynb.conf
.
以下是 Chef 由ipython-notebook-cookbook生成的示例配置,该 ipython-notebook-cookbook 在 virtualenv中运行笔记本:
[program:ipynb]
command=/home/ipynb/.ipyvirt/bin/ipython notebook --profile=cooked
process_name=%(program_name)s
numprocs=1
numprocs_start=0
autostart=true
autorestart=true
startsecs=1
startretries=3
exitcodes=0,2
stopsignal=QUIT
stopwaitsecs=10
user=ipynb
redirect_stderr=false
stdout_logfile=AUTO
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=10
stdout_capture_maxbytes=0
stdout_events_enabled=false
stderr_logfile=AUTO
stderr_logfile_maxbytes=50MB
stderr_logfile_backups=10
stderr_capture_maxbytes=0
stderr_events_enabled=false
environment=HOME="/home/ipynb",SHELL="/bin/bash",USER="ipynb",PATH="/home/ipynb/.ipyvirt/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games",VIRTUAL_ENV="/home/ipynb/.ipyvirt"
directory=/home/ipynb
serverurl=AUTO
上述主管配置还依赖于 IPython 笔记本配置(位于/home/ipynb/.ipython/profile_cooked/ipython_notebook_config.py
)。这使配置变得更加容易(因为您还可以设置密码哈希和许多其他可配置项)。:
c = get_config()
# Kernel config
# Make matplotlib plots inline
c.IPKernelApp.pylab = 'inline'
# The IP address the notebook server will listen on.
# If set to '*', will listen on all interfaces.
# c.NotebookApp.ip= '127.0.0.1'
c.NotebookApp.ip='*'
# Port to host on (e.g. 8888, the default)
c.NotebookApp.port = 8888 # If you want it on 80, I recommend iptables rules
# Open browser (probably want False)
c.NotebookApp.open_browser = False
重新阅读和更新,现在你有了配置文件
supervisorctl reread
supervisorctl update
现实
实际上,我曾经使用Chef 食谱来完成整个安装和配置。但是,将配置管理与像这样的小东西一起使用有点矫枉过正(除非您在自动化中编排这些)。
现在我为 IPython notebook 使用 Docker 镜像,通过 JupyterHub 或 tmpnb 进行编排。