在 Ubuntu 上启动时运行 Jupyter-notebook [英] Run Jupyter-notebook on boot on Ubuntu
问题描述
我有一个安装了 anaconda 的 Ubuntu 16.04 虚拟机,我希望它在启动时使用正确的配置文件(IP 地址、端口、密码等)启动 Jupyter-notebook
I have an Ubuntu 16.04 Virtual Machine with anaconda installed, And I want it to launch Jupyter-notebook on startup with the correct configuration file (ip address, port, password,...)
这个配置在/home/user/.jupyter/jupyter_notebook_config.py中指定
This configuration is specified in /home/user/.jupyter/jupyter_notebook_config.py
当我以 user 身份登录并在主目录 (/home/user/) 中时,它确实会启动正确的配置文件.
When I'm logged as user and in the home directory(/home/user/) it does launch the correct config file.
但是当使用命令时
jupyter-notebook
在使用 rc.local 或使用 crontab 启动期间,它不会加载我的配置文件,并且没有正确的运行目录.
During startup with rc.local or using crontab it's doesn't load my configuration file, and have not the correct running directory.
推荐答案
非常相似的问答:如何在启动时作为守护进程启动 ipython notebook 服务器
您可以将以下行添加到您的 /etc/rc.local
文件
You could add the following line to your /etc/rc.local
file
su <username> -c "jupyter notebook --config=/location/of/your/config/file/.jupyter/jupyter_notebook_config.py --no-browser --notebook-dir=/location/of/yournotebooks" &
例如
su simon -c "jupyter notebook --config=/home/simon/.jupyter/jupyter_notebook_config.py --no-browser --notebook-dir=/home/simon/notebooks" &
<小时>
su <用户名>-c
确保笔记本不是以 root 身份执行,而是使用指定的用户帐户执行.``
su <username> -c
makes sure that the notebook is not executed as root but with the specified user account.``
--config
和 --notebook-dir
指定配置文件和笔记本文件夹的位置(http://jupyter-notebook.readthedocs.io/en/latest/config.html)
--config
and --notebook-dir
specify the location of your config file and your notebook folder (http://jupyter-notebook.readthedocs.io/en/latest/config.html)
对于使用 systemd
(Ubuntu 16 及更高版本)的系统,以下方法也适用:
For systems using systemd
(Ubuntu 16 and later) the following approach also works:
在
/etc/systemd/system/
中创建一个服务文件,例如jupyter.service
使用以下内容(将YourUserName
替换为您的用户名)
Create a service file in
/etc/systemd/system/
, e.g.jupyter.service
with the following content (replaceYourUserName
with your username)
[Unit]
After=network.service
[Service]
ExecStart=jupyter notebook
User=YourUserName
[Install]
WantedBy=default.target
使用 sudo systemctl enable jupyter.service
您应该为 Jupyter 服务器设置密码,因为您将无法访问令牌.
You should set a password for your Jupyter server because you won't have access to the token.
这篇关于在 Ubuntu 上启动时运行 Jupyter-notebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!