use util.service_is_running for tor also

This commit is contained in:
fonfon committed 2015-05-03 09:44:46 +02:00
1 parent 3f2c9ff2c8
commit b3da314560
3 files changed
+8 -18

No files matched your search

+2 -2
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(_):
+3 -14
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(_):
+3 -2
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