replicator/lib/ruby/pg-wal-plugin.rb
# Checks the status of PostgreSQL server and informs the user
# if it's not an expected one.
# Use expect_started=nil in order to just get true or false without
# informing the user.
Checks the status of PostgreSQL server and informs the user
if it's not an expected one.
Use expect_started=nil in order to just get true or false without
informing the user.
Checks the status of PostgreSQL server and informs the user if it ' s not an expected one . Use expect_started = nil in order to just get true or false without informing the user .
def status_pg_server(expect_started)
    status_cmd = get_pg_server_cmd("status")
    stop_cmd = get_pg_server_cmd("stop")
    start_cmd = get_pg_server_cmd("start")
    if expect_started == nil
      status = "started or stopped"
    elsif expect_started
      status = "started"
    else
      status = "stopped"
    end
    log "Checking PostgreSQL server is " + status
    succeeded = true
    begin
      exec_root_cmd2(status_cmd, false)
    rescue SystemError
      succeeded = false
    end
    if expect_started == nil
      return succeeded
    end
    if expect_started and not succeeded
      log "ERROR: PostgreSQL is stopped when expected to be started or one of"
      log "       the following commands failed. Please ensure both commands"
      log "       can be executed by current account:"
      log "       " + get_root_cmd(start_cmd)
      log "       " + get_root_cmd(status_cmd)
      log ""
      log "       NOTE: the following status command is expected to return"
      log "       a zero return code when PostgreSQL is started:"
      log "       " + get_root_cmd(status_cmd)
      log ""
      print_batch_mode_suggestion
      log ""
      raise SystemError, "PostgreSQL is stopped when expected to be started or status command failed."
    elsif not expect_started and succeeded
      log "ERROR: PostgreSQL is started when expected to be stopped."
      log "       The following command might have failed. Please ensure"
      log "       it can be executed by current account:"
      log "       " + get_root_cmd(stop_cmd)
      log ""
      log "       NOTE: the following status command is expected to return"
      log "       a non zero return code when PostgreSQL is stopped:"
      log "       " + get_root_cmd(status_cmd)
      log ""
      print_batch_mode_suggestion
      log ""
      raise SystemError, "PostgreSQL is started when expected to be stopped."
    end
  end
def status_pg_server ( expect_started ) status_cmd = get_pg_server_cmd ( "status" ) stop_cmd = get_pg_server_cmd ( "stop" ) start_cmd = get_pg_server_cmd ( "start" ) if expect_started == nil status = "started or stopped" elsif expect_started status = "started" else status = "stopped" end log "Checking PostgreSQL server is " + status succeeded = true begin exec_root_cmd2 ( status_cmd , false ) rescue SystemError succeeded = false end if expect_started == nil return succeeded end if expect_started and not succeeded log "ERROR: PostgreSQL is stopped when expected to be started or one of" log "       the following commands failed. Please ensure both commands" log "       can be executed by current account:" log "       " + get_root_cmd ( start_cmd ) log "       " + get_root_cmd ( status_cmd ) log "" log "       NOTE: the following status command is expected to return" log "       a zero return code when PostgreSQL is started:" log "       " + get_root_cmd ( status_cmd ) log "" print_batch_mode_suggestion log "" raise SystemError , "PostgreSQL is stopped when expected to be started or status command failed." elsif not expect_started and succeeded log "ERROR: PostgreSQL is started when expected to be stopped." log "       The following command might have failed. Please ensure" log "       it can be executed by current account:" log "       " + get_root_cmd ( stop_cmd ) log "" log "       NOTE: the following status command is expected to return" log "       a non zero return code when PostgreSQL is stopped:" log "       " + get_root_cmd ( status_cmd ) log "" print_batch_mode_suggestion log "" raise SystemError , "PostgreSQL is started when expected to be stopped." end end
Checks the status of PostgreSQL server and informs the user
if it's not an expected one.
Checks the status of PostgreSQL server and informs the user if it ' s not an expected one .
expect_started