Linux下Jupyter开机启动设置

写在前面

  由于平时经常使用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 &
########################################################

  配置开机启动:

$ 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

方法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

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

$ cd /etc/init.d
$ chkconfig --add jupyter.sh
$ chkconfig jupyter.sh on
 
## 关闭开机启动 
$ chkconfig jupyter.sh off

方法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

  添加启动服务:

$ 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

  服务操作命令:

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

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

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

## 取消开机自启动
$ systemctl disable jupyter.service
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小爱玄策

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值