docs: def upload_template_and_reload(name):
      """
      Uploads a template only if it has changed, and if so, reload the
      related service.
      """
      template = get_templates()[name]
      local_path = template["local_path"]
      if not os.path.exists(local_path):
          project_root = os.path.dirname(os.path.abspath(__file__))
          local_path = os.path.join(project_root, local_path)
      remote_path = template["remote_path"]
      reload_command = template.get("reload_command")
      owner = template.get("owner")
      mode = template.get("mode")
      remote_data = ""
      if exists(remote_path):
          with hide("stdout"):
              remote_data = sudo("cat %s" % remote_path, show=False)
      with open(local_path, "r") as f:
          local_data = f.read()
          # Escape all non-string-formatting-placeholder occurrences of '%':
          local_data = re.sub(r"%(?!\(\w+\)s)", "%%", local_data)
          if "%(db_pass)s" in local_data:
              env.db_pass = db_pass()
          local_data %= env
      clean = lambda s: s.replace("\n", "").replace("\r", "").strip()
      if clean(remote_data) == clean(local_data):
          return
      upload_template(local_path, remote_path, env, use_sudo=True, backup=False)
      if owner:
          sudo("chown %s %s" % (owner, remote_path))
      if mode:
          sudo("chmod %s %s" % (mode, remote_path))
      if reload_command:
          sudo(reload_command)