diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2016-03-02 21:00:53 +0100 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2016-03-02 21:12:57 +0100 |
commit | 4720a0e94bc77cc42b7ffdbc62aec9feb1386cc8 (patch) | |
tree | f705f45dd1eb2d783db7b67553e228036e880ae1 | |
parent | 49c6672188f5048941b84d86b07af5d9efed522d (diff) | |
download | spline-startup-4720a0e94bc77cc42b7ffdbc62aec9feb1386cc8.tar.gz spline-startup-4720a0e94bc77cc42b7ffdbc62aec9feb1386cc8.tar.bz2 spline-startup-4720a0e94bc77cc42b7ffdbc62aec9feb1386cc8.zip |
Execute the scripts manually
Only use run-parts to get the script names and execute the scripts one by one.
-rwxr-xr-x | spline-startup | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/spline-startup b/spline-startup index 746e149..d3e1ef3 100755 --- a/spline-startup +++ b/spline-startup @@ -110,27 +110,41 @@ class SplineStartup(object): else: return 0 + def _get_scripts(self, action, directory): + args = [] + if action == 'stop': + args.append('--reverse') + cmd = ['run-parts', '--list'] + args + ['--', directory] + + self._pinfo('Getting scripts: %s' % ' '.join(cmd)) + proc = Popen(cmd, stdout=PIPE, stderr=STDOUT) + output, _ = proc.communicate() + return output.strip().splitlines() + def _run_scripts(self, user, action, use_su=True): self._pdebug("Running scripts for user '%s'" % user.pw_name) directory = os.path.join(user.pw_dir, 'etc', 'rc.d') - args = ['--arg=%s' % quote(action)] - if action == 'stop': - args.append('--reverse') - if not os.path.isdir(directory): return True - if use_su: - returnvalue = self._call(['su', '-', user.pw_name, - '-s', '/bin/sh', - '-c', 'run-parts %s -- %s' % - (' '.join(args), - quote(directory))]) - else: - returnvalue = self._call(['run-parts'] + args + ['--', directory]) + scripts = self._get_scripts(action, 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]) + + if exitcode != 0: + error = True - return returnvalue == 0 + return error == False def run(self): if not is_root(): |