use util.service_is_running for tor also

This commit is contained in:
fonfon 2015-01-22 15:56:24 +00:00
parent 3f2c9ff2c8
commit b3da314560
3 changed files with 8 additions and 18 deletions

View File

@ -28,7 +28,7 @@ import augeas
import os
import subprocess
from util import is_running
import util
from pagekite_util import SERVICE_PARAMS, convert_to_service, \
convert_service_to_string, get_augeas_servicefile_path, CONF_PATH
@ -92,7 +92,7 @@ def _service(action):
def subcommand_is_running(_):
"""Print whether pagekite is enabled (yes or no)"""
print 'yes' if is_running('pagekite') else 'no'
print 'yes' if util.service_is_running('pagekite') else 'no'
def subcommand_start_and_enable(_):

View File

@ -25,6 +25,8 @@ import argparse
import os
import subprocess
import util
SERVICE_CONFIG = '/etc/default/tor'
TOR_CONFIG = '/etc/tor/torrc'
@ -57,20 +59,7 @@ def parse_arguments():
def subcommand_is_running(_):
"""Get whether Tor is running"""
try:
output = subprocess.check_output(['service', 'tor', 'status'])
except subprocess.CalledProcessError:
# If Tor is not running we get a status code != 0 and a
# CalledProcessError
print('no')
else:
running = False
for line in output.decode().split('\n'):
if 'Active' in line and 'running' in line:
running = True
break
print('yes' if running else 'no')
print('yes' if util.service_is_running('tor') else 'no')
def subcommand_start(_):

View File

@ -23,7 +23,8 @@ Python action utility functions
import subprocess
def is_running(servicename):
def service_is_running(servicename):
"""Evaluates whether a service is currently running. Returns boolean"""
try:
output = subprocess.check_output(['service', servicename, 'status'])
@ -32,7 +33,7 @@ def is_running(servicename):
# thus a CalledProcessError
return False
else:
running = False # default value
running = False # default value
for line in output.decode('utf-8').split('\n'):
if 'Active' in line and 'running' in line:
running = True