File size: 936 Bytes
bac19c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash

# 更新系统包
sudo apt update

# 使用现有的 Python 安装 JupyterLab
pip install jupyterlab

# 为 JupyterLab 生成配置文件(如果不存在)
if [ ! -f ~/.jupyter/jupyter_lab_config.py ]; then
    jupyter lab --generate-config
fi

# 设置 JupyterLab 服务文件
SERVICE_FILE=/etc/systemd/system/jupyterlab.service

sudo bash -c "cat > $SERVICE_FILE" <<EOL
[Unit]
Description=JupyterLab
After=network.target

[Service]
Type=simple
User=$(whoami)
ExecStart=$(which jupyter) lab --ip=0.0.0.0 --port=8888 --no-browser
WorkingDirectory=$HOME
Restart=always

[Install]
WantedBy=multi-user.target
EOL

# 重新加载 systemd 并启动 JupyterLab 服务
sudo systemctl daemon-reload
sudo systemctl start jupyterlab
sudo systemctl enable jupyterlab

# 输出服务状态
sudo systemctl status jupyterlab

echo "JupyterLab 已安装并配置为后台服务,您可以通过 http://<服务器IP>:8888 访问它。"