forked from libuliduobuqiuqiu/Jupyter_Control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjupyter.sh
executable file
·79 lines (69 loc) · 1.6 KB
/
jupyter.sh
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/bash
#-----------------------------------------------------------------
# Author: linshukai
# Filename: jupyter.sh
# Datetime: 2020-05-08
# Description: 有关于jupyter服务控制:启动,重启,停止,检查
#-----------------------------------------------------------------
workPath=$(cd $(dirname $0)/; pwd)
pidFile=$workPath/jupyter.pid
logFile=$workPath/jupyter.log
function check_pid(){
if [ -f $pidFile ];then
pid=$(cat $pidFile)
if [ -n $pid ];then
tasks=$(ps -p $pid | grep -v "PID TTY" | wc -l)
return $tasks
fi
fi
return 0
} # 通过PID检查正在运行进程
function start(){
check_pid
tasks=$?
if [ $tasks -gt 0 ];then
echo -n "The jupyter Service is running already, PID="
$(cat $pidFile)
return 1
fi
nohup /usr/local/bin/jupyter lab >> $logFile 2>&1 &
echo $! > $pidFile
echo "The Jupyter Service start to run, PID=$!"
} # 首先检查是否正常启动,然后在判断是否启动jupyter
function stop(){
check_pid
tasks=$?
pid=$(cat $pidFile)
if [ $tasks -gt 0 ];then
kill -9 $pid
echo "Jupyter Service stoped...."
else
echo "Jupyter Service not running....."
fi
} # 检查是否正在运行,关闭指定PID
function restart(){
stop
sleep 2
start
}
function status(){
check_pid
tasks=$?
if [ $tasks -gt 0 ];then
echo -n "Jupyter Service is running, PID="
cat $pidFile
echo "Please check the log for details:"$logFile
else
echo "Jupyter Service has stopped"
fi
} # 输出进程PID
function help(){
echo "$0 start|stop|restart|status"
}
case $1 in
start) start;;
stop) stop;;
restart) restart;;
status) status;;
*) help;;
esac