summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2016-03-02 21:25:40 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2016-03-02 21:25:40 +0100
commit247ca9477e628b2e73ff8de7758e4f2998627f9b (patch)
tree592e39bbbe28a2d52d15bd73749c044ea8066c1b
parentf2867a912ce79e30eba591ae0725942dbf525915 (diff)
parent756a365b1045452d952972da8a08ae94433f0147 (diff)
downloadspline-startup-247ca9477e628b2e73ff8de7758e4f2998627f9b.tar.gz
spline-startup-247ca9477e628b2e73ff8de7758e4f2998627f9b.tar.bz2
spline-startup-247ca9477e628b2e73ff8de7758e4f2998627f9b.zip
Merge commit '1.3' into debian
* commit '1.3': Bump version Allow multiple actions Execute the scripts manually No need to wait(), communicate() will already wait Work for users with restricted shell, too
-rwxr-xr-xspline-startup60
1 files changed, 41 insertions, 19 deletions
diff --git a/spline-startup b/spline-startup
index 72c306e..a91faad 100755
--- a/spline-startup
+++ b/spline-startup
@@ -10,7 +10,7 @@ from subprocess import Popen, PIPE, STDOUT
from pipes import quote
-VERSION = '1.2'
+VERSION = '1.3'
def is_root():
@@ -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')
@@ -106,35 +109,54 @@ class SplineStartup(object):
if output != '':
for line in output.split('\n'):
self._pinfo(line)
- return proc.wait()
+ return proc.returncode
else:
return 0
- def _run_scripts(self, user, action, use_su=True):
+ def _get_scripts(self, reverse, directory):
+ args = []
+ if reverse:
+ 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, actions, 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,
- '-c', 'run-parts %s -- %s' %
- (' '.join(args),
- quote(directory))])
- else:
- returnvalue = self._call(['run-parts'] + args + ['--', directory])
+ scripts = self._get_scripts(actions[0] == 'stop', directory)
+
+ self._pinfo('Running scripts: %r' % scripts)
+ error = False
+ for script in scripts:
+ 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
- return returnvalue == 0
+ return error == False
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: