python服务启动脚本

传递参数 status/start/stop

#!/bin/bash
# 检查传入的参数个数
if [ $# -eq 0 ]; then
    echo "请传递参数:status/start/stop"
    exit 1
fi

# 检查进程是否在运行
check_process() {
    pid=$(ps -ef | grep "prod_kill_query.py" | grep -v "grep" | grep -v "/bin/sh" | awk '{print $2}')
    if [ -n "$pid" ]; then
        echo "running"
    else
        echo "not running"
    fi
}

# 执行对应操作
case $1 in
    status)
        check_process
        ;;
    start)
        #nohup python3 /root/pre_py/pre_kill_query.py > /root/pre_py/log/pre_output_$(date +'%Y%m%d_%H').log 2>&1 &
        nohup  python3 /root/py/prod_kill_query.py    > /root/py/py_log/prod_output_$(date +'%Y%m%d_%H').log 2>&1 &
        ;;
    stop)
        pid=$(ps -ef | grep "prod_kill_query.py" | grep -v "grep" | grep -v "/bin/sh" | awk '{print $2}')
        if [ -n "$pid" ]; then
            kill $pid > /dev/null 2>&1
            echo "进程 $pid 已停止"
        else
            echo "没有找到运行中的进程"
        fi
        ;;
    *)
        echo "参数错误,请输入 status/start/stop 中的一个"
        ;;
esac
posted @ 2024-09-03 14:24  姬高波  阅读(17)  评论(0)    收藏  举报