code: def start_rest_server(
      port,
      platform,
      mode,
      experiment_id,
      foreground=False,
      log_dir=None,
      log_level=None,
      url_prefix=None,
  ):
      """Run nni manager process"""
      if detect_port(port):
          print_error(
              "Port %s is used by another process, please reset the port!\n"
              "You could use 'nnictl create --help' to get help information"
              % port
          )
          exit(1)
  
      if (platform not in ["local", "aml"]) and detect_port(
          int(port) + 1
      ):
          print_error(
              "%s mode need an additional adjacent port %d, and the port %d is used by another process!\n"
              "You could set another port to start experiment!\n"
              "You could use 'nnictl create --help' to get help information"
              % (platform, (int(port) + 1), (int(port) + 1))
          )
          exit(1)
  
      print_normal("Starting restful server...")
  
      import nni_node
  
      entry_dir = nni_node.__path__[0]
      if (not entry_dir) or (not os.path.exists(entry_dir)):
          print_error("Fail to find nni under python library")
          exit(1)
      entry_file = os.path.join(entry_dir, "main.js")
  
      if sys.platform == "win32":
          node_command = os.path.join(entry_dir, "node.exe")
      else:
          node_command = os.path.join(entry_dir, "node")
      cmds = [
          node_command,
          "--max-old-space-size=4096",
          entry_file,
          "--port",
          str(port),
          "--mode",
          platform,
          "--experiment-id",
          experiment_id,
      ]
      cmds += ["--action", mode]
      if log_dir is not None:
          cmds += ["--experiments-directory", log_dir]
      if log_level is not None:
          cmds += ["--log-level", log_level]
      if foreground:
          cmds += ["--foreground", "true"]
      if url_prefix:
          _validate_prefix_path(url_prefix)
          set_prefix_url(url_prefix)
          cmds += ["--url-prefix", url_prefix.strip("/")]
  
      stdout_full_path, stderr_full_path = get_log_path(experiment_id)
      with open(stdout_full_path, "a+") as stdout_file, open(
          stderr_full_path, "a+"
      ) as stderr_file:
          start_time = time.time()
          time_now = time.strftime(
              "%Y-%m-%d %H:%M:%S", time.localtime(start_time)
          )
          # add time information in the header of log files
          log_header = LOG_HEADER % str(time_now)
          stdout_file.write(log_header)
          stderr_file.write(log_header)
          if sys.platform == "win32":
              from subprocess import CREATE_NEW_PROCESS_GROUP
  
              if foreground:
                  process = Popen(
                      cmds,
                      cwd=entry_dir,
                      stdout=PIPE,
                      stderr=STDOUT,
                      creationflags=CREATE_NEW_PROCESS_GROUP,
                  )
              else:
                  process = Popen(
                      cmds,
                      cwd=entry_dir,
                      stdout=stdout_file,
                      stderr=stderr_file,
                      creationflags=CREATE_NEW_PROCESS_GROUP,
                  )
          else:
              if foreground:
                  process = Popen(
                      cmds, cwd=entry_dir, stdout=PIPE, stderr=PIPE
                  )
              else:
                  process = Popen(
                      cmds,
                      cwd=entry_dir,
                      stdout=stdout_file,
                      stderr=stderr_file,
                  )
      return process, int(start_time * 1000)
  
imports: import json
  import os
  from pathlib import Path
  import sys
  import string
  import random
  import time
  import re
  from subprocess import Popen, check_call, CalledProcessError, PIPE, STDOUT
  from nni.experiment.config import ExperimentConfig, convert
  from nni.tools.package_utils.tuner_factory import get_builtin_module_class_name
  from .launcher_utils import validate_all_content
  from .rest_utils import rest_put, rest_post, check_rest_server, check_response
  from .url_utils import cluster_metadata_url, experiment_url, get_local_urls, set_prefix_url
  from .config_utils import Config, Experiments
  from .common_utils import get_yml_content, get_json_content, print_error, print_normal, detect_port
  from .constants import NNI_HOME_DIR, ERROR_INFO, REST_TIME_OUT, EXPERIMENT_SUCCESS_INFO, LOG_HEADER
  from .command_utils import check_output_command, kill_command
  from .nnictl_utils import update_experiment
label_desc: Use image node_id 3 for calling a global function with example usage: start_rest_server(port, platform, mode, experiment_id, foreground, log_dir, log_level, url_prefix) and returns: process,  int