wrap command in a runner that sources .profile.d scripts
This commit is contained in:
1 parent
7d9c2b2ac4
commit
584f251e4a
3 files changed
+29
-18
No files matched your search
+15
-3
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
#
|
#
|
||||||
#/ Usage: foreman-runner [-d <dir>] <command> [<args>...]
|
#/ Usage: foreman-runner [-d <dir>] [-p] <command> [<args>...]
|
||||||
#/
|
#/
|
||||||
#/ Run a command with exec, optionally changing directory first
|
#/ Run a command with exec, optionally changing directory first
|
||||||
|
|
||||||
@@ -16,9 +16,12 @@ usage() {
|
|||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts ":hd:" OPT; do
|
read_profiled=""
|
||||||
|
|
||||||
|
while getopts ":hd:p" OPT; do
|
||||||
case $OPT in
|
case $OPT in
|
||||||
d) cd "$OPTARG" ;;
|
d) cd "$OPTARG" ;;
|
||||||
|
p) read_profiled="1" ;;
|
||||||
h) usage ;;
|
h) usage ;;
|
||||||
\?) error "invalid option: -$OPTARG" ;;
|
\?) error "invalid option: -$OPTARG" ;;
|
||||||
:) error "option -$OPTARG requires an argument" ;;
|
:) error "option -$OPTARG requires an argument" ;;
|
||||||
@@ -29,4 +32,13 @@ shift $((OPTIND-1))
|
|||||||
|
|
||||||
[ -z "$1" ] && usage
|
[ -z "$1" ] && usage
|
||||||
|
|
||||||
|
if [ "$read_profiled" == "1" ]; then
|
||||||
|
shopt -s nullglob
|
||||||
|
for script in .profile.d/*; do
|
||||||
|
echo "sourcing $script"
|
||||||
|
source $script
|
||||||
|
done
|
||||||
|
shopt -u nullglob
|
||||||
|
fi
|
||||||
|
|
||||||
exec "$@"
|
exec "$@"
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
export FOO=bar
|
||||||
+12
-15
@@ -43,23 +43,20 @@ class Foreman::Process
|
|||||||
Process.spawn env, expanded_command, :out => output, :err => output
|
Process.spawn env, expanded_command, :out => output, :err => output
|
||||||
end
|
end
|
||||||
elsif Foreman.jruby?
|
elsif Foreman.jruby?
|
||||||
Dir.chdir(cwd) do
|
require "posix/spawn"
|
||||||
require "posix/spawn"
|
wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}"
|
||||||
POSIX::Spawn.spawn env, command, :out => output, :err => output
|
POSIX::Spawn.spawn env, wrapped_command, :out => output, :err => output
|
||||||
end
|
|
||||||
elsif Foreman.ruby_18?
|
elsif Foreman.ruby_18?
|
||||||
Dir.chdir(cwd) do
|
fork do
|
||||||
fork do
|
$stdout.reopen output
|
||||||
$stdout.reopen output
|
$stderr.reopen output
|
||||||
$stderr.reopen output
|
env.each { |k,v| ENV[k] = v }
|
||||||
env.each { |k,v| ENV[k] = v }
|
wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}"
|
||||||
exec command
|
exec wrapped_command
|
||||||
end
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Dir.chdir(cwd) do
|
wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}"
|
||||||
Process.spawn env, command, :out => output, :err => output
|
Process.spawn env, wrapped_command, :out => output, :err => output
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -96,7 +93,7 @@ class Foreman::Process
|
|||||||
private
|
private
|
||||||
|
|
||||||
def cwd
|
def cwd
|
||||||
@options[:cwd] || "."
|
File.expand_path(@options[:cwd] || ".")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user