当前位置:   article > 正文

Linux下Jupyter开机启动设置_jupyter linux 开机启动

jupyter linux 开机启动

写在前面

  由于平时经常使用Jupyter,于是在Linux上设置了开机启动,网上找了些常用的方法,此贴记录了操作过程,尝试了3种方法,对于没有成功的2种方法后续进行跟进和更新。

  为了方便查看启动情况,将操作日志写到了jupyter_notebook的目录下。

方法1:rc.local(未生效)

  编写开机启动脚本:

vim /home/jupyter.sh
########################################################
#!/bin/bash
/bin/echo $(/bin/date +%F %T) >> /home/startup.log
# jupyter
nohup jupyter notebook > /home/jupyter_notebook/jupyter.log &
########################################################
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

  配置开机启动:

$ ll /etc/rc.local 
lrwxrwxrwx. 1 root root 13 Feb  5 10:03 /etc/rc.local -> rc.d/rc.local

$ tail -n 1 /etc/rc.local
/bin/bash /home/jupyter.sh >/dev/null 2>/dev/null
  • 1
  • 2
  • 3
  • 4
  • 5

方法2:chkconfig(未生效)

  编写开机启动脚本:

$ vim /etc/init.d/jupyter.sh
#!/bin/sh
#chkconfig: 35 20 80        分别代表运行级别,启动优先权,关闭优先权
#description: http server
/bin/echo $(/bin/date +%F_%T) >> /home/startup.log
nohup jupyter notebook > /home/jupyter_notebook/jupyter.log &

$ chmod +x /etc/init.d/jupyter.sh
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

  添加脚本到开机自动启动项目中,添加到chkconfig,开机自启动。

$ cd /etc/init.d
$ chkconfig --add jupyter.sh
$ chkconfig jupyter.sh on
 
## 关闭开机启动 
$ chkconfig jupyter.sh off
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

方法3:systemctl(成功)

  编写启动脚本:

$ vim /opt/jupyter.sh

#!/bin/sh
/bin/echo $(/bin/date +%F_%T) >> /home/startup.log
/root/anaconda3/bin/jupyter notebook > /home/jupyter_notebook/jupyter.log
  • 1
  • 2
  • 3
  • 4
  • 5

  添加启动服务:

$ vim /etc/systemd/system/jupyter.service

[Unit]
Description=jupyter.sh
After=network.target

[Service]
Type=simple
ExecStart=/opt/jupyter.sh
ExecReload=/bin/kill -s HUP $MAINPID
RestartSec=2s
Restart=on-failure

[Install]
WantedBy=multi-user.target
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

  服务操作命令:

## 查看服务状态
$ systemctl status jupyter.service

## 启动服务
$ systemctl start jupyter.service

## 设置开机自启动
$ systemctl enable jupyter.service

## 取消开机自启动
$ systemctl disable jupyter.service
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/245110
推荐阅读
相关标签
  

闽ICP备14008679号