Commit dcc84f3e authored by Marc Vef's avatar Marc Vef
Browse files

gkfs runner script: bugfix pid file for proxy

parent 269b3802
Loading
Loading
Loading
Loading
Loading
+16 −14
Original line number Diff line number Diff line
@@ -49,20 +49,22 @@ wait_for_gkfs_daemons() {
# If valid, an additional line is added. Otherwise, the pid in the file is deleted.
# Globals:
#   SRUN_DAEMON_PID_FILE
#   SRUN_PROXY_PID_FILE
#   VERBOSE
# Arguments:
#   path to pid file
#   pid to write to pid file
# Outputs:
#   Writes status to stdout if VERBOSE is true
#######################################
create_pid_file() {
    local daemon_pid_file=${SRUN_DAEMON_PID_FILE}
    local pid=${1}
    local pid_file=${1}
    local pid=${2}
    if [[ ${VERBOSE} == true ]]; then
        echo -e "${C_AST_GREEN}Creating pid file at ${daemon_pid_file} with pid ${pid} ..."
        echo -e "${C_AST_GREEN}Creating pid file at ${pid_file} with pid ${pid} ..."
    fi
    # if PID file exists another daemon could run
    if [[ -e ${daemon_pid_file} ]]; then
    if [[ -e ${pid_file} ]]; then
        local pid_file_tmp=${SRUN_DAEMON_PID_FILE}.swp
        # create empty tmp file
        truncate -s 0 "${pid_file_tmp}"
@@ -72,11 +74,11 @@ create_pid_file() {
                # process with pid still running
                echo "${line}" >> "${pid_file_tmp}"
            fi
        done < "${daemon_pid_file}"
        done < "${pid_file}"
        # create pid file with only valid pids
        mv "${pid_file_tmp}" "${daemon_pid_file}"
        mv "${pid_file_tmp}" "${pid_file}"
    fi
    echo "${pid}" >> "${daemon_pid_file}"
    echo "${pid}" >> "${pid_file}"
}
#######################################
# Starts GekkoFS daemons.
@@ -219,8 +221,8 @@ start_daemon() {
            fi
        done
    else
        create_pid_file ${daemon_pid}
        create_pid_file ${proxy_pid}
        create_pid_file ${SRUN_DAEMON_PID_FILE} ${daemon_pid}
        create_pid_file ${SRUN_PROXY_PID_FILE} ${proxy_pid}
    fi
}
#######################################
@@ -233,10 +235,10 @@ start_daemon() {
#   Writes status to stdout
#######################################
stop_daemons() {
    local daemon_pid_file=${SRUN_DAEMON_PID_FILE}
    local pid_file=${SRUN_DAEMON_PID_FILE}
    local proxy_pid_file=${SRUN_PROXY_PID_FILE}
    # if no daemon or proxy pid file exists, exit
    if [[ ! -e ${daemon_pid_file} ]] && [[ ! -e ${proxy_pid_file} ]]; then
    if [[ ! -e ${pid_file} ]] && [[ ! -e ${proxy_pid_file} ]]; then
        echo -e "${C_AST_RED}No pid files found -> no daemon or proxy running. Exiting ..."
        exit 1
    fi
@@ -261,7 +263,7 @@ stop_daemons() {
        echo -e "${C_AST_GREEN}Shutdown time: ${elapsed} seconds"
    fi
    # attempt to shutdown daemon
    if [[ -e ${daemon_pid_file} ]]; then
    if [[ -e ${pid_file} ]]; then
        while IFS= read -r line
        do
            if ps -p "${line}" > /dev/null; then
@@ -274,8 +276,8 @@ stop_daemons() {
                fi
                timeout 1 tail --pid=${line} -f /dev/null
            fi
        done < "${daemon_pid_file}"
        rm "${daemon_pid_file}"
        done < "${pid_file}"
        rm "${pid_file}"
        stop_time="$(date -u +%s.%3N)"
        elapsed="$(bc <<<"$stop_time-$start_time")"
        echo -e "${C_AST_GREEN}Shutdown time: ${elapsed} seconds"