   end
 
   def terminate(reason, state) do
-    Logger.debug("Terminate CMD #{inspect state.cmd}")
+    Logger.debug("Terminate CMD #{inspect reason} // #{inspect Path.basename(state.cmd)} //  #{inspect Port.info(state.port)}")
     kill(state.port)
     #Port.close(state.port)
     {:ok}

      {:noreply, %{ state | line: line }}
    end
  end
  def handle_info({:EXIT, _port, :normal}, state) do
    {:stop, :normal, state}
  end
  def handle_info({:EXIT, _port, reason}, state) do
    Logger.warn("Command exit, not expected: #{reason}")
    {:stop, reason, state}
  end

  def handle_info(:ratelimit_bucket_add, state) do
    if state.ratelimit_skip > 0 do
      {:noreply, %{ state | ratelimit_skip: state.ratelimit_skip - 1 }}
    else

  def handle_call({:write_line, line}, _from, state) do
    # If fails, makes the cmd exit. And by failing call, quite probably caller too. (Client)
    if state.debug do
      Logger.debug("CMD // #{Path.basename state.cmd} // #{inspect self}> #{line} #{inspect Port.info(state.port)}")
    end
    res = Port.command(state.port, line)

    {:reply, res, state}
  end
  def handle_call({:call, method, params}, from, state) do
    #Logger.debug("Call #{method}")
    RPC.Client.cast( state.client, method, params, fn res ->
      Logger.debug("Response for #{method}: #{inspect res}")
      GenServer.reply(from, res)
    end)
    {:noreply, state }
