def parse_service(pathname):
    dirname, basename = os.path.split(pathname)
    if '/etc/init' == dirname:
        service, ext = os.path.splitext(basename)

        # Ignore extraneous files in /etc/init.
        if '.conf' != ext:
            raise ValueError('not an Upstart config')

        # Ignore services that don't operate on the (faked) main runlevels.
        try:
            content = open(pathname).read()
        except IOError:
            raise ValueError('not a readable Upstart config')
        if not (pattern_upstart_1.search(content) \
                or pattern_upstart_2.search(content)):
            raise ValueError('not a running service')

        return ('upstart', service)
    elif '/etc/init.d' == dirname or '/etc/rc.d/init.d' == dirname:

        # Let Upstart handle its services.
        if os.path.islink(pathname) \
            and '/lib/init/upstart-job' == os.readlink(pathname):
            raise ValueError('proxy for an Upstart config')

        # Ignore services that don't operate on the main runlevels.
        try:
            content = open(pathname).read()
        except IOError:
            raise ValueError('not a readable SysV init script')
        if not re.search(r'(?:Default-Start|chkconfig):\s*[2345]', content):
            raise ValueError('not a running service')

        return ('sysvinit', basename)
    else:
        raise ValueError('not a service')
Parse a potential service init script or config file into the
dataset/ETHPy150Open devstructure/blueprint/blueprint/util.py/parse_service