Systemd jupyter 服务仅在服务重启后才起作用

Systemd jupyter 服务仅在服务重启后才起作用

使用 systemd,我正在尝试设置我的Ubuntu 20.04工作站托管Jupyter 实验室我的 LAN 环境。

这在某种程度上是可行的。如果我手动发出命令在端口 8888 上启动 Jupyter,jupyter lab --ip pcc.local则它可以正常工作。

为了实现此自动化,我创建了一个 systemd 服务:

/etc/systemd/system/jupyter.service

[Unit]
Description=Jupyter Lab service on port 8888
After=network.target
StartLimitIntervalSec=0

[Service]
Type=idle
#Restart=always
#RestartSec=1
User=wsuser
ExecStart= /home/wsuser/local/bin/jupyter lab --ip pcc.local
WorkingDirectory=/home/wsuser/


[Install]
WantedBy=multi-user.target

如果我发出命令sudo systemctl start jupyter,我可以通过 LAN 访问 jupyter 笔记本,方法是导航到https://pcc.local:8888在浏览器中。

测试完之后,我启用了该服务(sudo systemctl enable jupyter)并重新启动。

我检查了该服务的状态并发现它正在运行且没有错误:

jupyter.service - 端口 8888 上的 Jupyter Lab 服务
     已加载:已加载(/etc/systemd/system/jupyter.service;已启用;供应商预设:已启用)
     活跃:自 2020-06-21 周日 21:17:01 CEST;4 分钟 22 秒前开始活跃(运行)
   主 PID:1019(jupyter-lab)
      任务:1(限制:19035)
     内存:74.3M
     CGroup:/system.slice/jupyter.service
             └─1019 /usr/bin/python3 /home/wsuser/.local/bin/jupyter-lab --ip pcc.local

6月21日 21:17:01 PCC systemd[1]: 在端口 8888 上启动 Jupyter Lab 服务。
jun 21 21:17:06 PCC jupyter[1019]: [W 21:17:06.871 LabApp] JupyterLab 服务器扩展未启用,手动加载...
jun 21 21:17:06 PCC jupyter[1019]: [I 21:17:06.876 LabApp] JupyterLab 扩展从 /home/wsuser/.local/lib/python3.8/site-packages/jupyterlab 加载
jun 21 21:17:06 PCC jupyter[1019]: [I 21:17:06.876 LabApp] JupyterLab 应用程序目录为 /home/wsuser/.local/share/jupyter/lab
jun 21 21:17:06 PCC jupyter[1019]: [I 21:17:06.877 LabApp] 从本地目录提供笔记本:/home/wsuser
jun 21 21:17:06 PCC jupyter[1019]: [I 21:17:06.877 LabApp] Jupyter Notebook 正在运行:
6月21日 21:17:06 PCC jupyter[1019]: [I 21:17:06.877 LabApp] https://pcc.local:8888/
jun 21 21:17:06 PCC jupyter[1019]: [I 21:17:06.877 LabApp] 使用 Control-C 停止此服务器并关闭所有内核(两次以跳过确认)。

看起来很好,但是如果我导航到https://pcc.local:8888/在我的另一台机器上,我无法连接(Firefox 说“无法连接 Firefox 无法与 pcc.local:8888 的服务器建立连接。”)

一旦我重新启动服务,sudo systemctl restart jupyterjupyter 笔记本就可以通过 LAN 使用了。

我尝试将服务类型从简单设置为空闲,以确保它是最后启动的服务之一。

为什么我需要在启动后重新启动服务,我该怎么做才能解决这个问题?

答案1

这是通过改变 After=network.target 来 解决的After=syslog.target network.target

相关内容