#NEWLINE# def parse_service( pathname ) : #NEWLINE# #INDENT# '\n    Parse a potential service init script or config file into the\n    manager and service name or raise `ValueError`.  Use the Upstart\n    "start on" stanzas and SysV init\'s LSB headers to restrict services to\n    only those that start at boot and run all the time.\n    ' #NEWLINE# ( dirname , basename ) = os . path . split ( pathname ) #NEWLINE# if ( '/etc/init' == dirname ) : #NEWLINE# #INDENT# ( service , ext ) = os . path . splitext ( basename ) #NEWLINE# if ( '.conf' != ext ) : #NEWLINE# #INDENT# raise ValueError ( 'not an Upstart config' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# content = open ( pathname ) . read ( ) #NEWLINE# #UNINDENT# except IOError : #NEWLINE# #INDENT# raise ValueError ( 'not a readable Upstart config' ) #NEWLINE# #UNINDENT# if ( not ( pattern_upstart_1 . search ( content ) or pattern_upstart_2 . search ( content ) ) ) : #NEWLINE# #INDENT# raise ValueError ( 'not a running service' ) #NEWLINE# #UNINDENT# return ( 'upstart' , pathname ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( '/etc/init.d' == dirname ) or ( '/etc/rc.d/init.d' == dirname ) ) : #NEWLINE# #INDENT# if ( os . path . islink ( pathname ) and ( '/lib/init/upstart-job' == os . readlink ( pathname ) ) ) : #NEWLINE# #INDENT# raise ValueError ( 'proxy for an Upstart config' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# content = open ( pathname ) . read ( ) #NEWLINE# #UNINDENT# except IOError : #NEWLINE# #INDENT# raise ValueError ( 'not a readable SysV init script' ) #NEWLINE# #UNINDENT# if ( not re . search ( '(?:Default-Start|chkconfig):\\s*[2345]' , content ) ) : #NEWLINE# #INDENT# raise ValueError ( 'not a running service' ) #NEWLINE# #UNINDENT# return ( 'sysvinit' , basename ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( 'not a service' )