nebula icon indicating copy to clipboard operation
nebula copied to clipboard

nebula.service start all时如果重启前的进程id已被其他进程使用时,会导致启动失败

Open sillylly opened this issue 10 months ago • 0 comments

nebula.service file function stop_daemon中没有将文件里的pid进行清理,当进程停止后,pid文件保留的还是重启前的pid号

function stop_daemon {
    local daemon_name=nebula-${1}
    local config=${2}
    local executable=${INSTALL_ROOT}/bin/${daemon_name}
    if [[ $daemon_name == *-listener ]]; then
        executable=${INSTALL_ROOT}/bin/${daemon_name%-listener*}
    fi

    [[ -e ${executable} ]] || ERROR_AND_EXIT "${executable} not found"

    [[ -z ${config} ]] && config=${INSTALL_ROOT}/etc/${daemon_name}.conf

    [[ -f ${config} ]] || ERROR_AND_EXIT "${config} not found"

    INFO "Stopping ${daemon_name}..."
    stop_by_pid_file $(get_pid_file_from_config ${config})
    code=$? 
    INFO "Done"
    [[ ${code} -ne 0 ]] && exit ${code}
}

function stop_by_pid_file {
    local pid_file=${1}
    local signame=${2}
    [[ -z ${signame} ]] && signame=TERM

    if is_process_running ${pid_file}; then
        [[ ${VERBOSE} -ne 0 ]] && INFO "Send SIG${signame} to $(cat ${pid_file})"
        kill -s ${signame} $(cat ${pid_file})
    else
        [[ ${VERBOSE} -ne 0 ]] && INFO "No such process" || code=$?
    fi
}

function start_daemon中有如下判断,如果进程存在就会报错并返回

pid_file=$(get_pid_file_from_config ${config})
    if [[ -f ${pid_file} ]]; then
        if is_process_running ${pid_file}; then
            ERROR "${daemon_name} already running: $(cat ${pid_file})"
            exit 1
        fi
    fi

这样导致了当进程停止后,一旦原来的pid被其他进程占用,就会导致nebula服务启动失败,只能通过手动清空pid文件修复;

sillylly avatar Feb 05 '25 03:02 sillylly