def run(self):
with open(os.devnull, 'w') as devnull:
try:
# If the service is disabled in Preferences
# the query returns a non-zero error
# should use this query better in future
if subprocess.check_call(['launchctl', 'print', 'system/com.openssh.sshd'], stdout=devnull, stderr=devnull):
return (True, "disabled")
else:
return (False, "enabled in Sharing Prefs: Remote Login")
except subprocess.CalledProcessError as e:
# this only gets run if sshd isn't enabled by
# launchd as checked above
pids = []
for p in psutil.process_iter():
try:
if p.name() == 'sshd':
pids.append(p.pid)
except psutil.NoSuchProcess:
pass
if len(pids):
return (False, "enabled manually - see pids: {} ".format(', '.join([str(p) for p in pids])))
else:
return (True, "disabled")
评论列表
文章目录