赞
踩
由于平时经常使用Jupyter,于是在Linux上设置了开机启动,网上找了些常用的方法,此贴记录了操作过程,尝试了3种方法,对于没有成功的2种方法后续进行跟进和更新。
为了方便查看启动情况,将操作日志写到了jupyter_notebook的目录下。
编写开机启动脚本:
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
编写开机启动脚本:
$ 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
编写启动脚本:
$ 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
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。