--- InitScriptCheck.py +++ InitScriptCheck.py @@ -29,6 +29,10 @@ use_deflevels = Config.getOption('UseDefaultRunlevels', True) lsb_tags_regex = re.compile('^# ([\w-]+):\s*(.*?)\s*$') lsb_cont_regex = re.compile('^#(?:\t| )(.*?)\s*$') +insserv_regex=re.compile('^\s*sbin/insserv', re.MULTILINE) +stop_on_removal_regex=re.compile('^\s*%stop_on_removal\s+\S+', re.MULTILINE) +restart_on_update_regex=re.compile('^\s*%restart_on_update\s\S+', re.MULTILINE) +insserv_cleanup_regex=re.compile('^\s*%insserv_cleanup', re.MULTILINE) LSB_KEYWORDS = ('Provides', 'Required-Start', 'Required-Stop', 'Should-Start', 'Should-Stop', 'Default-Start', 'Default-Stop', @@ -47,6 +51,13 @@ return initscript_list = [] + + + # check chkconfig call in %post and %preun + postin = pkg[rpm.RPMTAG_POSTIN] or pkg[rpm.RPMTAG_POSTINPROG] + preun = pkg[rpm.RPMTAG_PREUN] or pkg[rpm.RPMTAG_PREUNPROG] + postun = pkg[rpm.RPMTAG_POSTUN] or pkg[rpm.RPMTAG_POSTUNPROG] + for fname, pkgfile in pkg.files().items(): if not fname.startswith('/etc/init.d/') and \ @@ -60,18 +71,19 @@ if dot_in_name_regex.match(basename): printError(pkg, 'init-script-name-with-dot', fname) - # check chkconfig call in %post and %preun - postin = pkg[rpm.RPMTAG_POSTIN] or pkg[rpm.RPMTAG_POSTINPROG] - if not postin: - printError(pkg, 'init-script-without-chkconfig-postin', fname) - elif not chkconfig_regex.search(postin): - printError(pkg, 'postin-without-chkconfig', fname) - preun = pkg[rpm.RPMTAG_PREUN] or pkg[rpm.RPMTAG_PREUNPROG] if not preun: - printError(pkg, 'init-script-without-chkconfig-preun', fname) - elif not chkconfig_regex.search(preun): - printError(pkg, 'preun-without-chkconfig', fname) + printError(pkg, 'init-script-without-%stop_on_removal-preun', fname) + elif not stop_on_removal_regex.search(preun): + printError(pkg, 'preun-without-%stop_on_removal-preun', fname) + + if not postun: + printError(pkg, 'init-script-without-%restart_on_update-postun', fname) + else: + if not restart_on_update_regex.search(postun): + printError(pkg, 'postun-without-%restart_on_update', fname) + if not insserv_cleanup_regex.search(postun): + printError(pkg, 'postun-without-%insserv_cleanup', fname) status_found = False reload_found = False @@ -202,10 +214,18 @@ '''The package contains an init script but doesn't call chkconfig in its %post script.''', -'init-script-without-chkconfig-preun', +'init-script-without-%stop_on_removal-preun', '''The package contains an init script but doesn't contain a %preun with a call to chkconfig.''', +'init-script-without-%insserv_cleanup-postun', +'''The package contains an init script but doesn't contain a %postun +with a call to %insserv_cleanup-postun''', + +'postun-without-%insserv_cleanup', +'''The package contains an init script but doesn't contain a %postun +with a call to %insserv_cleanup-postun''', + 'preun-without-chkconfig', '''The package contains an init script but doesn't call chkconfig in its %preun script.''', @@ -264,6 +284,24 @@ 'init-script-non-executable', '''The init script should have at least the execution bit set for root in order for it to run at boot time.''', + +'init-script-without-%stop_on_removal-preun', +'''The init script should have a %preun script that calls %stop_on_removal.''', + +'preun-without-%stop_on_removal-preun', +'''The init script is not listed in %stop_on_removal in %preun.''', + +'init-script-without-%insserv_cleanup-postun', +'''The package doesn't have a %insserv_cleanup call in %postun''', + +'postun-without-%insserv_cleanup', +'''The package has an init script that is inserted with insserv but +doesn't have a %insserv_cleanup call in %postun''', + +'init-script-without-%restart_on_update-postun', +''' The package has an init script but is missing the %restart_on_update +call in %postun to automatically restart the daemon. This is optional, +but in most cases it is wanted. Please check.''' ) # InitScriptCheck.py ends here