jupyter-lab設定開機自啟動,遠端連接配接開發環境
-
-
- 1 建立JupyterLab運作腳本
- 2 添加JupyterLab Service檔案
- 3 設定Jupyter Service自啟動
- 4 測試自啟動服務
-
1 建立JupyterLab運作腳本
首先找到jupyter-lab指令的位置,一般在~/.local/bin/下,可以建立shell腳本autoJupyterLab.sh:
#!/bin/sh
/home/myjetson/.local/bin/jupyter-lab
測試一下腳本的正确性::
./autoJupyterLab.sh
遠端連接配接JupyterLab成功,說明運作腳本沒問題。
2 添加JupyterLab Service檔案
Ubuntu18通過systemd管理服務,是以添加服務來開機運作JupyterLab腳本。
服務Service儲存在/lib/systemd/system和/etc/systemd/system下。在/etc/systemd/system下建立auto-jupyter.service服務:
[Unit]
Description=Auto Load JupyterLab
After=network.target
[Service]
Type=simple
User=your_username
ExecStart=/your_script_dir/autoJupyterLab.sh
Restart=on-failure
RestartSec=15s
[Install]
WantedBy=multi-user.target
3 設定Jupyter Service自啟動
讓systemd重新加載service檔案:
sudo systemctl daemon-reload
然後設定auto-jupyter.service開機自啟:
sudo systemctl enable auto-jupyter.service
這樣配置就完成了。
4 測試自啟動服務
試着手動運作auto-jupyter.service,看看服務寫的有沒有問題:
sudo systemctl start auto-jupyter.service
sudo systemctl status auto-jupyter.service
重新開機伺服器,遠端連接配接jupyterlab,大功告成!