diff options
-rwxr-xr-x | spline-startup | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/spline-startup b/spline-startup index d3e1ef3..9a52612 100755 --- a/spline-startup +++ b/spline-startup @@ -51,10 +51,13 @@ class SplineStartup(object): def _parse_args(self): parser = argparse.ArgumentParser(description='Startup for users.') - parser.add_argument('action', metavar='ACTION', nargs='?', - default='start', + parser.add_argument('actions', metavar='ACTION', nargs='*', + default=['start'], help='argument supplied to each called ' - 'script (default: %(default)s)') + 'script, if multiple arguments are given ' + 'each script is called with each argument ' + 'until the first one exits with return code ' + '0 (default: %(default)s)') parser.add_argument('-q', '--quiet', action='store_true', help='only log error messages') @@ -110,9 +113,9 @@ class SplineStartup(object): else: return 0 - def _get_scripts(self, action, directory): + def _get_scripts(self, reverse, directory): args = [] - if action == 'stop': + if reverse: args.append('--reverse') cmd = ['run-parts', '--list'] + args + ['--', directory] @@ -121,25 +124,29 @@ class SplineStartup(object): output, _ = proc.communicate() return output.strip().splitlines() - def _run_scripts(self, user, action, use_su=True): + def _run_scripts(self, user, actions, use_su=True): self._pdebug("Running scripts for user '%s'" % user.pw_name) directory = os.path.join(user.pw_dir, 'etc', 'rc.d') if not os.path.isdir(directory): return True - scripts = self._get_scripts(action, directory) + scripts = self._get_scripts(actions[0] == 'stop', directory) self._pinfo('Running scripts: %r' % scripts) error = False for script in scripts: - if use_su: - exitcode = self._call(['su', '-', user.pw_name, - '-s', '/bin/sh', - '-c', '%s %s' % (quote(script), - quote(action))]) - else: - exitcode = self._call([script, action]) + for action in actions: + if use_su: + exitcode = self._call(['su', '-', user.pw_name, + '-s', '/bin/sh', + '-c', '%s %s' % (quote(script), + quote(action))]) + else: + exitcode = self._call([script, action]) + + if exitcode == 0: + break if exitcode != 0: error = True @@ -149,7 +156,7 @@ class SplineStartup(object): def run(self): if not is_root(): user = pwd.getpwuid(os.getuid()) - self._run_scripts(user, self.options.action, False) + self._run_scripts(user, self.options.actions, False) return if self.options.user is not None: |