@staticmethod
def _query_state_value(command):
"""Execute state command for return value."""
_LOGGER.info("Running state command: %s", command)
try:
return_value = subprocess.check_output(command, shell=True)
return return_value.strip().decode('utf-8')
except subprocess.CalledProcessError:
_LOGGER.error("Command failed: %s", command)
这里执行命令时,加了一个try,看了一下man systemctl我才想明白:
is-active PATTERN...
Check whether any of the specified units are active (i.e. running). Returns an exit
code 0 if at least one is active, or non-zero otherwise. Unless --quiet is specified,
this will also print the current unit state to standard output.