Add new reasons for server restart: PID_FILE_BUT_NO_SERVER, SERVER_VANISHED and SERVER_UNRESPONSIVE, since it looks like these are happening with upsetting frequency in our new grpc world.

PiperOrigin-RevId: 156271743
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index 14f976b..4382534 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -531,8 +531,13 @@
                     ToString(globals->extract_data_time));
   }
   if (globals->restart_reason != NO_RESTART) {
-    const char *reasons[] = {"no_restart", "no_daemon", "new_version",
-                             "new_options"};
+    const char *reasons[] = {"no_restart",
+                             "no_daemon",
+                             "new_version",
+                             "new_options",
+                             "pid_file_but_no_server",
+                             "server_vanished",
+                             "server_unresponsive"};
     args->push_back(string("--restart_reason=") +
                     reasons[globals->restart_reason]);
   }
@@ -700,6 +705,12 @@
   return result;
 }
 
+static void SetRestartReasonIfNotSet(RestartReason restart_reason) {
+  if (globals->restart_reason == NO_RESTART) {
+    globals->restart_reason = restart_reason;
+  }
+}
+
 // Starts up a new server and connects to it. Exits if it didn't work not.
 static void StartServerAndConnect(const WorkspaceLayout *workspace_layout,
                                   BlazeServer *server) {
@@ -721,10 +732,16 @@
   int server_pid = GetServerPid(server_dir);
   if (server_pid > 0) {
     if (VerifyServerProcess(server_pid, globals->options->output_base,
-                            globals->options->install_base) &&
-        KillServerProcess(server_pid)) {
-      fprintf(stderr, "Killed non-responsive server process (pid=%d)\n",
-              server_pid);
+                            globals->options->install_base)) {
+      if (KillServerProcess(server_pid)) {
+        fprintf(stderr, "Killed non-responsive server process (pid=%d)\n",
+                server_pid);
+        SetRestartReasonIfNotSet(SERVER_UNRESPONSIVE);
+      } else {
+        SetRestartReasonIfNotSet(SERVER_VANISHED);
+      }
+    } else {
+      SetRestartReasonIfNotSet(PID_FILE_BUT_NO_SERVER);
     }
   }
 
diff --git a/src/main/cpp/global_variables.h b/src/main/cpp/global_variables.h
index 063cdbb..4774f29 100644
--- a/src/main/cpp/global_variables.h
+++ b/src/main/cpp/global_variables.h
@@ -31,7 +31,15 @@
 
 // The reason for a blaze server restart.
 // Keep in sync with logging.proto.
-enum RestartReason { NO_RESTART = 0, NO_DAEMON, NEW_VERSION, NEW_OPTIONS };
+enum RestartReason {
+  NO_RESTART = 0,
+  NO_DAEMON,
+  NEW_VERSION,
+  NEW_OPTIONS,
+  PID_FILE_BUT_NO_SERVER,
+  SERVER_VANISHED,
+  SERVER_UNRESPONSIVE
+};
 
 struct GlobalVariables {
   GlobalVariables(OptionProcessor *option_processor);