Skip to content

Instantly share code, notes, and snippets.

@parente
Created February 15, 2011 01:54
Show Gist options
  • Save parente/826961 to your computer and use it in GitHub Desktop.
Save parente/826961 to your computer and use it in GitHub Desktop.
run a command in virtualenv, useful for supervisord
#!/bin/bash
VENV=$1
if [ -z $VENV ]; then
echo "usage: runinenv [virtualenv_path] CMDS"
exit 1
fi
. ${VENV}/bin/activate
shift 1
echo "Executing $@ in ${VENV}"
exec "$@"
deactivate
; rest of conf omitted for brevity
[program:handlerbag]
command=sh runinenv /opt/envs/handlerbag handlerbag.py --port=5000
directory=/opt/envs/handlerbag
@charles-dyfis-net
Copy link

The deactivate is never executed, since exec doesn't return. Thus, there's no purpose to it.

@charles-dyfis-net
Copy link

Also, using "$@" inside of a string context doesn't make sense -- it won't accurately preserve/present quoting and the like. Either use "$*" to expand a string rather than an array (and accept that you aren't getting accurate quoting), or...

printf -v cmd_str '%q ' "$@"
echo "Executing $cmd_str in $VENV"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment