Running foreman from a rake task
If you must make it work via rake, try changing the shell-out via backtick to use a hard-coded path to the system-wide foreman binary
`/global/path/to/foreman start -f Procfile.dev`
You just need to use 'which' or 'locate' or a similar tool to determine the path that works outside your bundler context. If you are using rbenv, then this might be sufficient :
$ rbenv which rake/home/name/.rbenv/versions/1.9.3-p448/bin/rake
I hope that helps you move forward.
Not sure if this will work, but you could export the environment variables associated with your shell explicitly and then make a call to foreman
. FWIW, I don't think this is recommended, and would suggest using a bash script as @dax proposes.
Steps
Get the
$PATH
and other environment variables from your shellprintenv >> shell.env
Get the environment variables from the rails environment
namespace :foreman_test do task :dev do `printenv >> rails.env` endend
Compare the two and find out the changed environment variables, and set them up in your rake task in the
system
callnamespace :foreman do task :dev do `export PATH=/original/path:/value && GEM_DIR=/some/folder && foreman start -f Procfile.dev` endend
if it has to be a rake task, try this (from this answer):
namespace :foreman do task :dev do sh "foreman start -f Procfile.dev" endend
if it doesn't have to be a rake task, I have a simple bash script to start for a specific project that works well:
#!/bin/bashexport PROJECT_DIR=`pwd`export PORT=$1source "$HOME/.rvm/scripts/rvm"unset BUNDLE_GEMFILEunset BUNDLE_BIN_PATHunset RUBYOPTunset GEM_HOMEunset GEM_PATH(cd <project full path> && exec foreman start -p $PORT)