Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

wrap command in a runner that sources .profile.d scripts

  • Loading branch information...
commit 584f251e4a1ef7dda4f5b20e06b7152c367a5970 1 parent 7d9c2b2
@ddollar authored
View
18 bin/foreman-runner
@@ -1,6 +1,6 @@
-#!/bin/sh
+#!/bin/bash

Not everyone has /bin/bash :disappointed:
/usr/bin/env bash plz.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
#
-#/ Usage: foreman-runner [-d <dir>] <command> [<args>...]
+#/ Usage: foreman-runner [-d <dir>] [-p] <command> [<args>...]
#/
#/ Run a command with exec, optionally changing directory first
@@ -16,9 +16,12 @@ usage() {
exit
}
-while getopts ":hd:" OPT; do
+read_profiled=""
+
+while getopts ":hd:p" OPT; do
case $OPT in
d) cd "$OPTARG" ;;
+ p) read_profiled="1" ;;
h) usage ;;
\?) error "invalid option: -$OPTARG" ;;
:) error "option -$OPTARG requires an argument" ;;
@@ -29,4 +32,13 @@ shift $((OPTIND-1))
[ -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 "$@"
View
2  data/example/.profile.d/foo.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+export FOO=bar
View
27 lib/foreman/process.rb
@@ -43,23 +43,20 @@ def run(options={})
Process.spawn env, expanded_command, :out => output, :err => output
end
elsif Foreman.jruby?
- Dir.chdir(cwd) do
- require "posix/spawn"
- POSIX::Spawn.spawn env, command, :out => output, :err => output
- end
+ require "posix/spawn"
+ wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}"
+ POSIX::Spawn.spawn env, wrapped_command, :out => output, :err => output
elsif Foreman.ruby_18?
- Dir.chdir(cwd) do
- fork do
- $stdout.reopen output
- $stderr.reopen output
- env.each { |k,v| ENV[k] = v }
- exec command
- end
+ fork do
+ $stdout.reopen output
+ $stderr.reopen output
+ env.each { |k,v| ENV[k] = v }
+ wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}"
+ exec wrapped_command
end
else
- Dir.chdir(cwd) do
- Process.spawn env, command, :out => output, :err => output
- end
+ wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}"
+ Process.spawn env, wrapped_command, :out => output, :err => output
end
end
@@ -96,7 +93,7 @@ def dead?
private
def cwd
- @options[:cwd] || "."
+ File.expand_path(@options[:cwd] || ".")
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.