code: def service_available(service_name):
      
      try:
          subprocess.check_output(
              ['service', service_name, 'status'],
              stderr=subprocess.STDOUT).decode('UTF-8')
      except subprocess.CalledProcessError as e:
          return b'unrecognized service' not in e.output
      else:
          return True
docs: Determine whether a system service is available