jupyter自启动脚本

作用:Linux系统启动并自动运行jupyter服务,可查看运行状态、启动或停止。


在/etc/init.d/下创建一个脚本文件,名称自拟。

#! /bin/bash

# jupyter      Bring up/down/#

# chkconfig: 2345 10 90

# description: jupyter controller

[ -f /etc/init.d/functions ] && . /etc/init.d/functions

case $1 in

    start)

        jus=$(netstat -luntp| grep 8888 |grep -v grep|awk '{print $7}'|awk -F "/" '{print $1}'|wc -l)

        if [ $jus -eq 1 ];then

            echo -e "\njupyter is already run\n"

            exit 0

        else

            su - python -c "cd /tmp/test1 && jupyter notebook --ip=0.0.0.0 &"

            action "jupyter >>>\t$1 " /bin/true

        fi

        ;;

    stop)

        pkill jupyter && action "jupyter >>>\t$1 " /bin/true

        ;;

    status)

        stat=$(netstat -luntp|grep 8888|wc -l)

        if [ $stat -eq 1 ];then

            echo -e "\njupyter already run\n"

        fi

        ;; 

    *)

        echo "please use [start|stop|status]"

        exit 0

esac


最后将该脚本加入到系统启动服务。linux内核3.x与linux内核2.x服务启动方式不同,需注意。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容