mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
use util.service_is_running for tor also
This commit is contained in:
parent
3f2c9ff2c8
commit
b3da314560
@ -28,7 +28,7 @@ import augeas
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from util import is_running
|
import util
|
||||||
from pagekite_util import SERVICE_PARAMS, convert_to_service, \
|
from pagekite_util import SERVICE_PARAMS, convert_to_service, \
|
||||||
convert_service_to_string, get_augeas_servicefile_path, CONF_PATH
|
convert_service_to_string, get_augeas_servicefile_path, CONF_PATH
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ def _service(action):
|
|||||||
|
|
||||||
def subcommand_is_running(_):
|
def subcommand_is_running(_):
|
||||||
"""Print whether pagekite is enabled (yes or no)"""
|
"""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(_):
|
def subcommand_start_and_enable(_):
|
||||||
|
|||||||
17
actions/tor
17
actions/tor
@ -25,6 +25,8 @@ import argparse
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
import util
|
||||||
|
|
||||||
SERVICE_CONFIG = '/etc/default/tor'
|
SERVICE_CONFIG = '/etc/default/tor'
|
||||||
TOR_CONFIG = '/etc/tor/torrc'
|
TOR_CONFIG = '/etc/tor/torrc'
|
||||||
|
|
||||||
@ -57,20 +59,7 @@ def parse_arguments():
|
|||||||
|
|
||||||
def subcommand_is_running(_):
|
def subcommand_is_running(_):
|
||||||
"""Get whether Tor is running"""
|
"""Get whether Tor is running"""
|
||||||
try:
|
print('yes' if util.service_is_running('tor') else 'no')
|
||||||
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')
|
|
||||||
|
|
||||||
|
|
||||||
def subcommand_start(_):
|
def subcommand_start(_):
|
||||||
|
|||||||
@ -23,7 +23,8 @@ Python action utility functions
|
|||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
def is_running(servicename):
|
|
||||||
|
def service_is_running(servicename):
|
||||||
"""Evaluates whether a service is currently running. Returns boolean"""
|
"""Evaluates whether a service is currently running. Returns boolean"""
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(['service', servicename, 'status'])
|
output = subprocess.check_output(['service', servicename, 'status'])
|
||||||
@ -32,7 +33,7 @@ def is_running(servicename):
|
|||||||
# thus a CalledProcessError
|
# thus a CalledProcessError
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
running = False # default value
|
running = False # default value
|
||||||
for line in output.decode('utf-8').split('\n'):
|
for line in output.decode('utf-8').split('\n'):
|
||||||
if 'Active' in line and 'running' in line:
|
if 'Active' in line and 'running' in line:
|
||||||
running = True
|
running = True
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user