code: @CLIMethod(name="safe-shutdown")
      @RequirePOST
      public HttpResponse doSafeExit(StaplerRequest req) throws IOException {
          checkPermission(ADMINISTER);
          isQuietingDown = true;
          final String exitUser = getAuthentication().getName();
          final String exitAddr = req!=null ? req.getRemoteAddr() : "unknown";
          new Thread("safe-exit thread") {
              @Override
              public void run() {
                  try {
                      ACL.impersonate(ACL.SYSTEM);
                      LOGGER.info(String.format("Shutting down VM as requested by %s from %s",
                                                  exitUser, exitAddr));
                      // Wait 'til we have no active executors.
                      doQuietDown(true, 0);
                      // Make sure isQuietingDown is still true.
                      if (isQuietingDown) {
                          cleanUp();
                          System.exit(0);
                      }
                  } catch (Exception e) {
                      LOGGER.log(Level.WARNING, "Failed to shut down Jenkins", e);
                  }
              }
          }.start();
  
          return HttpResponses.plainText("Shutting down as soon as all jobs are complete");
      }
docs: Shutdown the system safely.
  @since 1.332