Skip to content

Commit 54449f8

Browse files
committed
add hacker_news_clients jupyter
1 parent 314318c commit 54449f8

File tree

3 files changed

+525
-1
lines changed

3 files changed

+525
-1
lines changed

daemon_control.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,46 @@
11
#!/bin/bash
2-
# Control script for a Python daemon
2+
# 守护进程控制脚本
33

4+
# 定义守护进程 Python 脚本的路径
45
DAEMON_PATH="./src/daemon_process.py"
6+
# 定义守护进程的名称
57
DAEMON_NAME="DaemonProcess"
8+
# 定义日志文件的路径
69
LOG_FILE="./logs/$DAEMON_NAME.log"
10+
# 定义守护进程的 PID 文件路径,用于存储进程号
711
PID_FILE="./run/$DAEMON_NAME.pid"
812

13+
# 启动守护进程的函数
914
start() {
1015
echo "Starting $DAEMON_NAME..."
16+
# 使用 nohup 命令在后台运行 Python 脚本,并将输出重定向到日志文件
1117
nohup python3 $DAEMON_PATH > $LOG_FILE 2>&1 &
18+
# 将守护进程的 PID 写入文件
1219
echo $! > $PID_FILE
1320
echo "$DAEMON_NAME started."
1421
}
1522

23+
# 停止守护进程的函数
1624
stop() {
1725
if [ -f $PID_FILE ]; then
26+
# 如果 PID 文件存在,读取 PID
1827
PID=$(cat $PID_FILE)
1928
echo "Stopping $DAEMON_NAME..."
29+
# 使用 kill 命令停止进程
2030
kill $PID
2131
echo "$DAEMON_NAME stopped."
32+
# 删除 PID 文件
2233
rm $PID_FILE
2334
else
2435
echo "$DAEMON_NAME is not running."
2536
fi
2637
}
2738

39+
# 检查守护进程状态的函数
2840
status() {
2941
if [ -f $PID_FILE ]; then
3042
PID=$(cat $PID_FILE)
43+
# 检查进程是否在运行
3144
if ps -p $PID > /dev/null
3245
then
3346
echo "$DAEMON_NAME is running."
@@ -39,6 +52,7 @@ status() {
3952
fi
4053
}
4154

55+
# 根据输入参数选择执行哪个函数
4256
case "$1" in
4357
start)
4458
start
@@ -50,10 +64,12 @@ case "$1" in
5064
status
5165
;;
5266
restart)
67+
# 重启守护进程
5368
stop
5469
start
5570
;;
5671
*)
72+
# 如果参数不符合预期,显示用法
5773
echo "Usage: $0 {start|stop|status|restart}"
5874
exit 1
5975
esac

0 commit comments

Comments
 (0)