【问题标题】:Run IPython Notebook server in background in Ubuntu using "service"-style commands使用“服务”式命令在 Ubuntu 后台运行 IPython Notebook 服务器
【发布时间】:2014-03-12 13:37:50
【问题描述】:

我已经在我的机器上(在 virtualenv 中)设置了 IPython Notebook。我已经建立了一个适合我需要的配置文件(称为myserver)。现在,我通过执行以下命令启动该服务器:

cd path/to/folder/containing/virtualenv
source virtualenvfolder/bin/activate
ipython notebook --profile=myserver

我想在后台运行同样的进程,并且我想像在我的 Ubuntu 安装中管理其他事情一样管理它...使用像 sudo service ngninx startsudo service uwsgi restart 或 @987654327 这样的命令@。 IE。我希望能够输入 sudo service myipythonserver start|stop|restart 并让它以预期的方式运行。

四个问题。

  1. 当我调用sudo service something action 时使用的框架的名称是什么。是Supervisor 吗?还有什么?
  2. 无论该框架叫什么,我如何创建一个新的“事物”来管理它?哪个用户拥有以这种方式启动的进程,您如何管理后台进程的文件权限(等)?
  3. 一旦我创建了那个新的“命令”(比如说现在可以输入sudo service myipythonserver start|stop|restart),我该如何设置它以使进程在系统启动时自动启动?
  4. 有没有办法控制这些后台进程之一消耗的系统资源量?例如,如果我想限制我的 IPython 服务器使用不超过 3gb 的 RAM,这可能吗?不超过 50% 的 CPU?

【问题讨论】:

  • 我不是 linux 专家,但我认为如果你把你的脚本变成一个 Upstart 工作,你可能会更好(ubuntu 正在远离系统初始化服务" /etc/init.d/ 之类的)。This 看起来是一个好的开始。This 是完整的文档。
  • 您的第一个链接已损坏。还有其他建议吗?

标签: ubuntu ipython daemon background-process ipython-notebook


【解决方案1】:

我能够使用 Ubuntu 附带的 upstart 完成这项工作。要使用 upstart 创建工作,请在 /etc/init 中创建一个 .conf 文件。不带 .conf 的文件名是服务的名称。这是我创建的文件:

exec sudo /usr/local/bin/ipython notebook --notebook-dir=/your/notebook/path   
start on filesystem and net-device-up IFACE!=lo 

第一行包含 ipython 二进制文件的路径,--notebook-dir 包含存储我的笔记本的路径。可以使用iPython Profile 指定更详细的配置。 Upstart 系统文件可以包括scripts,它可以激活你的virtualenv。

当有可用的文件系统和网络接口时,第二行启动 iPython。可以使用sudo start ipythonsudo stop ipython 手动启动和停止服务。

【讨论】:

    猜你喜欢
    • 2016-05-26
    • 2022-07-27
    • 2013-06-06
    • 2020-03-15
    • 2020-11-23
    • 2015-11-29
    • 2023-04-01
    • 2018-07-27
    • 1970-01-01
    相关资源
    最近更新 更多