InitScript - files /etc/rc.d/init.d/*

InitScript is a parser for the initscripts in /etc/rc.d/init.d.

Because this parser read multiple files, the initscripts are stored as a list within the parser and need to be iterated through in order to find specific initscripts.

Examples

>>> for initscript in shared[InitScript]: # Parser contains list of all initscripts
...     print "Name:", initscript.file_name
...
Name: netconsole
Name: rhnsd
exception insights.parsers.initscript.EmptyFileException[source]

Bases: ParseException

class insights.parsers.initscript.InitScript(context)[source]

Bases: Parser

Parse initscript files. Each item is a dictionary with following fields:

file_name

initscript name

Type

str

file_path

initscript path without leading ‘/’

Type

str

file_content

initscript content, line by line

Type

list

Because some files may not be real initscripts, to determine whether a file in etc/rc.d/init.d/ is an initscript, the parser checks for # chkconfig: <values> or # Provides: <names> strings in the script. If that matches, then it assumes it is an initscript.

Otherwise, it tries to find out if it is by searching for

  • shebang (e.g. #!/bin/bash) on first line

  • start/stop/status tokens in non-commented out lines

If 3 or more items are found (half the items searched for + 1), called confidence in the code (e.g. shebang + start + stop), then we assume it is an initscript.

Otherwise the parser raises a ParseException.

parse_content(content)[source]
Raises
exception insights.parsers.initscript.NotInitscriptException[source]

Bases: ParseException