code: def pause_unit(assess_status_func, services=None, ports=None,
                 charm_func=None):
      
      _, messages = manage_payload_services(
          'pause',
          services=services,
          charm_func=charm_func)
      set_unit_paused()
      if assess_status_func:
          message = assess_status_func()
          if message:
              messages.append(message)
      if messages and not is_unit_upgrading_set():
          raise Exception("Couldn't pause: {}".format("; ".join(messages)))
docs: Pause a unit by stopping the services and setting 'unit-paused'
      in the local kv() store.
  
      Also checks that the services have stopped and ports are no longer
      being listened to.
  
      An optional charm_func() can be called that can either raise an
      Exception or return non None, None to indicate that the unit
      didn't pause cleanly.
  
      The signature for charm_func is:
      charm_func() -> message: string
  
      charm_func() is executed after any services are stopped, if supplied.
  
      The services object can either be:
        - None : no services were passed (an empty dict is returned)
        - a list of strings
        - A dictionary (optionally OrderedDict) {service_name: {'service': ..}}
        - An array of [{'service': service_name, ...}, ...]
  
      @param assess_status_func: (f() -> message: string | None) or None
      @param services: OPTIONAL see above
      @param ports: OPTIONAL list of port
      @param charm_func: function to run for custom charm pausing.
      @returns None
      @raises Exception(message) on an error for action_fail().