-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
integration: add background runner script #1594
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/python3 | ||
|
||
# Use screen to run a terminal program in the background until it exists. | ||
# This process stays around in the forground. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/forground/foreground/ |
||
# Exit code from the program being run is returned here. | ||
|
||
import argparse | ||
import subprocess | ||
import sys | ||
import tempfile | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-l', '--logfile', default=None, | ||
help='append output to logfile') | ||
args, program = parser.parse_known_args() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sadly, there seems to be no way to tell argparse to parse options only at the beginning of the CLI. This means that doing:
will interpret I suggest to disable prefix matching (i.e., setting Another alternative is to insert
but with parser.parse_known_args(["-l", "/tmp/log", "--", "ls", "/root"])
(Namespace(logfile='/tmp/log'), ['--', 'ls', '/root']) |
||
|
||
cmd = [ | ||
'screen', | ||
'-c', '/dev/null', # ignore any user configuration | ||
'-D', '-m', # run detached from a terminal perspective, | ||
# but the screen process doesn't background | ||
] | ||
if args.logfile: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is not None? |
||
cmd.extend(('-L', '-Logfile', args.logfile)) | ||
|
||
with tempfile.NamedTemporaryFile() as exitfile: | ||
cmd.extend(('./scripts/capture-exit-code', exitfile.name, *program)) | ||
subprocess.run(cmd, check=True) | ||
sys.exit(int(exitfile.read())) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh -u | ||
|
||
# Take a filename argument. The rest of the arguments are a program to run. | ||
# Save the exit code of that program to the filename arg. | ||
|
||
exitfile="$1" | ||
shift | ||
"$@" | ||
ec=$? | ||
echo $ec > "$exitfile" | ||
exit $ec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/exists/exits/