anchor.diff:  handle_cast(_, State) ->
       {noreply, State}.
   
  -handle_info(cert_and_pkey_changed, OldState) ->
  +handle_info(cert_and_pkey_changed, #state{cert_state = OldCertState} = State) ->
       misc:flush(cert_and_pkey_changed),
       {CertPEM, PKeyPEM} = ns_server_cert:cluster_cert_and_pkey_pem(),
       Compat30 = cluster_compat_mode:is_cluster_30(),
       Node = node(),
  -    NewState = build_state(CertPEM, PKeyPEM, Compat30, Node),
  -    case OldState =:= NewState of
  +    NewCertState = build_cert_state(CertPEM, PKeyPEM, Compat30, Node),
  +    case OldCertState =:= NewCertState of
           true ->
  -            {noreply, OldState};
  +            {noreply, State};
           false ->
               ?log_info("Got certificate and pkey change"),
               save_cert_pkey(CertPEM, PKeyPEM, Compat30, Node),
               ?log_info("Wrote new pem file"),
  -            restart_ssl_services(),
  -            ?log_info("Restarted all ssl services"),
  -            {noreply, NewState}
  +            self() ! notify_services,
  +            {noreply, #state{cert_state = NewCertState,
  +                             reload_state = all_services()}}
       end;
  +handle_info(notify_services, #state{reload_state = []} = State) ->
  +    misc:flush(notify_services),
  +    {noreply, State};
  +handle_info(notify_services, #state{reload_state = Reloads} = State) ->
  +    misc:flush(notify_services),
  +    RVs = misc:parallel_map(fun notify_service/1, Reloads, 60000),
  +    ResultPairs = lists:zip(RVs, Reloads),
  +    {Good, Bad} = lists:foldl(fun ({ok, Svc}, {AccGood, AccBad}) ->
  +                                      {[Svc | AccGood], AccBad};
  +                                  (ErrorPair, {AccGood, AccBad}) ->
  +                                      {AccGood, [ErrorPair | AccBad]}
  +                              end, {[], []}, ResultPairs),
  +    case Good of
  +        [] ->
  +            ok;
  +        _ ->
  +            ?log_debug("Succesfully notified services ~p", [Good])
  +    end,
  +    case Bad of
  +        [] ->
  +            ok;
  +        _ ->
  +            ?log_debug("Failed to notify some services. Will retry in 5 sec, ~p", [Bad]),
  +            timer:send_after(5000, notify_services)
  +    end,
  +    {noreply, State#state{reload_state = [Svc || {_, Svc} <- Bad]}};
  +
   handle_info(_Info, State) ->
       {noreply, State}.
   
  
positive.code:     ns_config:sync_announcements(),
      ok = gen_server:call(?MODULE, ping, infinity).
  
  build_state(CertPEM, PKeyPEM, Compat30, Node) ->
      BaseState = #state{cert = CertPEM,
                         pkey = PKeyPEM,
                         compat_30 = Compat30},
      case Compat30 of
          true ->
              BaseState#state{node = Node};
          false ->
              BaseState
      end.
  
negative.code:     Compat30 = cluster_compat_mode:is_cluster_30(),
      Node = node(),
      save_cert_pkey(CertPEM, PKeyPEM, Compat30, Node),
      RetrySvc = all_services() -- [ssl_service],
      Self ! notify_services,
      {ok, #state{cert_state = build_cert_state(CertPEM, PKeyPEM, Compat30, Node),
                  reload_state = RetrySvc}}.
  
  format_status(_Opt, [_PDict, _State]) ->
      {}.
  