<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import logging <EOL> import os <EOL> import os . path <EOL> import re <EOL> import salt . utils <EOL> from salt . exceptions import CommandExecutionError <EOL> __func_alias__ = { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> log = logging . getLogger ( __name__ ) <EOL> VALID_SERVICE_DIRS = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> SERVICE_DIR = None <EOL> for service_dir in VALID_SERVICE_DIRS : <EOL> if os . path . exists ( service_dir ) : <EOL> SERVICE_DIR = service_dir <EOL> break <EOL> def __virtual__ ( ) : <EOL> BINS = frozenset ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> return all ( salt . utils . which ( b ) for b in BINS ) <EOL> def _service_path ( name ) : <EOL> '''<STR_LIT>''' <EOL> if not SERVICE_DIR : <EOL> raise CommandExecutionError ( "<STR_LIT>" ) <EOL> return '<STR_LIT>' . format ( SERVICE_DIR , name ) <EOL> def start ( name ) : <EOL> '''<STR_LIT>''' <EOL> __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' . format ( _service_path ( name ) ) ) <EOL> cmd = '<STR_LIT>' . format ( _service_path ( name ) ) <EOL> return not __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) <EOL> def stop ( name ) : <EOL> '''<STR_LIT>''' <EOL> __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' . format ( _service_path ( name ) ) ) <EOL> cmd = '<STR_LIT>' . format ( _service_path ( name ) ) <EOL> return not __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) <EOL> def term ( name ) : <EOL> '''<STR_LIT>''' <EOL> cmd = '<STR_LIT>' . format ( _service_path ( name ) ) <EOL> return not __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) <EOL> def reload_ ( name ) : <EOL> '''<STR_LIT>''' <EOL> term ( name ) <EOL> def restart ( name ) : <EOL> '''<STR_LIT>''' <EOL> ret = '<STR_LIT>' <EOL> if stop ( name ) and start ( name ) : <EOL> ret = '<STR_LIT>' <EOL> return ret <EOL> def full_restart ( name ) : <EOL> '''<STR_LIT>''' <EOL> restart ( name ) <EOL> def status ( name , sig = None ) : <EOL> '''<STR_LIT>''' <EOL> cmd = '<STR_LIT>' . format ( _service_path ( name ) ) <EOL> out = __salt__ [ '<STR_LIT>' ] ( cmd , python_shell = False ) <EOL> try : <EOL> pid = re . search ( r'<STR_LIT>' , out ) . group ( <NUM_LIT:1> ) <EOL> except AttributeError : <EOL> pid = '<STR_LIT>' <EOL> return pid <EOL> def available ( name ) : <EOL> '''<STR_LIT>''' <EOL> return name in get_all ( ) <EOL> def missing ( name ) : <EOL> '''<STR_LIT>''' <EOL> return name not in get_all ( ) <EOL> def get_all ( ) : <EOL> '''<STR_LIT>''' <EOL> if not SERVICE_DIR : <EOL> raise CommandExecutionError ( "<STR_LIT>" ) <EOL> return sorted ( os . listdir ( SERVICE_DIR ) ) <EOL> def enabled ( name , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> if not available ( name ) : <EOL> log . error ( '<STR_LIT>' . format ( name ) ) <EOL> return False <EOL> run_file = os . path . join ( SERVICE_DIR , name , '<STR_LIT>' ) <EOL> down_file = os . path . join ( SERVICE_DIR , name , '<STR_LIT>' ) <EOL> return ( <EOL> os . path . isfile ( run_file ) and <EOL> os . access ( run_file , os . X_OK ) and not <EOL> os . path . isfile ( down_file ) <EOL> ) <EOL> def disabled ( name ) : <EOL> '''<STR_LIT>''' <EOL> return not enabled ( name ) </s>
